fri.util.database.jpa.commons
Interface DbSession

All Known Implementing Classes:
DbSessionHibernateImpl, DbSessionJpaImpl

public interface DbSession

Responsibilities of an JPA database session in interaction with NestedSetsTreeDAO. Should be implementable using a Hibernate Session or an JPA EntityManager.

Author:
Fritz Ritzberger, 08.10.2011

Method Summary
 void delete(java.lang.Object node)
          Deletes passed object from persistence.
 void executeUpdate(java.lang.String statement, java.lang.Object[] parameters)
          Executes an update or delete statement.
 void flush()
          Flushes all changes to database.
 java.lang.Object get(java.lang.Class<?> entityClass, java.io.Serializable id)
          Fast cached read of an object by identity (primary key).
 int queryCount(java.lang.String queryText, java.lang.Object[] parameters)
          Executes given query and returns the resulting count of found records.
 java.util.List<?> queryList(java.lang.String queryText, java.lang.Object[] parameters)
          Executes a query and returns its result list.
 void refresh(java.lang.Object node)
          Re-reads passed object from persistence.
 java.lang.Object save(java.lang.Object node)
          Save the passed object to persistence.
 

Method Detail

get

java.lang.Object get(java.lang.Class<?> entityClass,
                     java.io.Serializable id)
Fast cached read of an object by identity (primary key).

Parameters:
entityClass - the persistence class of the entity (POJO).
id - the primary key of the entity.
Returns:
the entity object with given primary key.

queryList

java.util.List<?> queryList(java.lang.String queryText,
                            java.lang.Object[] parameters)
Executes a query and returns its result list.

Parameters:
queryText - the JPQL text for the query.
parameters - the positional parameters for "?" place-holders in query text.
Returns:
the result list of the query.

queryCount

int queryCount(java.lang.String queryText,
               java.lang.Object[] parameters)
Executes given query and returns the resulting count of found records. The query must be a select count(x) ... query.

Parameters:
queryText - the JPQL text for the query.
parameters - the positional parameters for "?" place-holders in query text.
Returns:
the number of records found by the query.

save

java.lang.Object save(java.lang.Object node)
Save the passed object to persistence.

Parameters:
node - the object to save.

refresh

void refresh(java.lang.Object node)
Re-reads passed object from persistence. This is needed as some changes are not done via JPA objects but directly via JPQL.

Parameters:
node - the object to refresh.

delete

void delete(java.lang.Object node)
Deletes passed object from persistence.

Parameters:
node - the object to delete.

executeUpdate

void executeUpdate(java.lang.String statement,
                   java.lang.Object[] parameters)
Executes an update or delete statement.

Parameters:
statement - the text of the JPQL statement.
parameters - the positional parameters for place-holders in command text.

flush

void flush()
Flushes all changes to database. This is needed as some changes are not done via JPA objects but directly via JPQL.