org.perfectjpattern.jee.api.integration.dao
Interface ISession


public interface ISession

Abstract definition of Session available for the DAO implementation. The DAO API exposes this interface but it will be automatically adapted from the underlying JPA-specific implementation (see IAdapter).

JPA and specific implementations define similar abstractions e.g. Session vs EntityManager but despite their similarities, their types actually mismatch making it difficult to provide a generic unified DAO solution.

Note that this is a subset of the functionality that the underlying implementation offers. This is the subset required to make the DAO portable. If required, it is possible to get the underlying implementation using getDelegate()

Version:
$Revision: 1.0 $Date: Feb 10, 2009 5:47:08 PM $
Author:
Giovanni Azua
 

Method Summary
 void clear()
          Clears the Session, removing all cached changes without applying them.
 void close()
          Closes the Session.
 boolean contains(Object anEntity)
          Returns true if the instance belongs to the current persistence context, false otherwise
 IQuery createNativeQuery(String aSqlString, Class<?> aPersistentClass)
          Returns instance of JPA implementation-specific Query for executing native SQL queries.
 IQuery createQuery(String aSqlString)
          Returns instance of JPA implementation-specific Query for executing JPA-specific Queries e.g.
<E> E
find(Class<E> aPersistentClass, Object anId)
          Returns the Entity instance if found, null if the entity does not exist
 void flush()
          Flushes the Session by applying all cached changes to the persistent store.
<S> S
getDelegate()
          Returns the implementation-specific Session
 ITransaction getTransaction()
          Returns the ITransaction adapted from the implementation-specific
<Id> Id
persist(Object anObject)
          Returns the Id of the newly persisted Object.
 void refresh(Object anObject)
          Refresh the state of the instance from the database, overwriting changes made to the entity, if any
 void remove(Object anObject)
          Removes Object from the persistent store
 void update(Object anObject)
          Updates the Object in the persistent store
 

Method Detail

clear

void clear()
           throws DaoException
Clears the Session, removing all cached changes without applying them. The underlying implementation is JPA implementation- specific.

Throws:
DaoException

close

void close()
           throws DaoException
Closes the Session. The underlying implementation is JPA implementation-specific.

Throws:
DaoException

flush

void flush()
           throws DaoException
Flushes the Session by applying all cached changes to the persistent store. The underlying implementation is JPA implementation- specific.

Throws:
DaoException

contains

boolean contains(Object anEntity)
Returns true if the instance belongs to the current persistence context, false otherwise

Parameters:
anEntity - The entity to check
Returns:
true if the instance belongs to the current persistence context, false otherwise

find

<E> E find(Class<E> aPersistentClass,
           Object anId)
Returns the Entity instance if found, null if the entity does not exist

Type Parameters:
E -
Parameters:
aPersistentClass - Persistent class
anId - The Id to look for
Returns:
Entity instance if found, null if the entity does not exist

getTransaction

ITransaction getTransaction()
Returns the ITransaction adapted from the implementation-specific

Returns:
ITransaction adapted from the implementation-specific
See Also:
IAdapter

remove

void remove(Object anObject)
Removes Object from the persistent store

Parameters:
anObject - The Object to remove

persist

<Id> Id persist(Object anObject)
Returns the Id of the newly persisted Object. Creates the Object in the persistent store. Note that not all adapted implementations will return an Id e.g. adapted Hibernate does but using pure JPA will not.

Parameters:
anObject - The Object to persist
Returns:
Id of the newly persisted Object

update

void update(Object anObject)
Updates the Object in the persistent store

Parameters:
anObject - The Object to update

refresh

void refresh(Object anObject)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any

Parameters:
anObject - The Object to refresh

createQuery

IQuery createQuery(String aSqlString)
Returns instance of JPA implementation-specific Query for executing JPA-specific Queries e.g. HQL queries.

Parameters:
aSqlString - SQL query input
Returns:
instance of JPA implementation-specific Query

createNativeQuery

IQuery createNativeQuery(String aSqlString,
                         Class<?> aPersistentClass)
Returns instance of JPA implementation-specific Query for executing native SQL queries.

Parameters:
aSql - SQL query input
Returns:
instance of JPA implementation-specific Query

getDelegate

<S> S getDelegate()
Returns the implementation-specific Session

Returns:
implementation-specific Session


Copyright © 2007-2009. All Rights Reserved.