net.sf.derquinsej.hib3
Class AbstractDAOImpl

java.lang.Object
  extended by net.sf.derquinsej.hib3.AbstractDAOImpl
All Implemented Interfaces:
DAO
Direct Known Subclasses:
GeneralDAOImpl, GenericDAOImpl

public abstract class AbstractDAOImpl
extends Object
implements DAO

Abstract implementation for general and generic DAO.

Author:
Andres Rodriguez

Constructor Summary
AbstractDAOImpl()
          Constructs the DAO
AbstractDAOImpl(SessionFactory sessionFactory)
          Constructs the DAO
 
Method Summary
 void clear()
          Clears the session cache.
protected  void evict(Object object)
          Remove the provided instance from the session cache.
protected
<T> T
first(Class<T> type, Query query)
          Returns the first result of a query returning instances of a specified class.
 void flush()
          Flushes the session.
protected  Query getNamedQuery(String queryName)
          Returns a externally defined named query.
protected  Session getSession()
          Returns the current session.
protected
<T> List<T>
list(Class<T> type, Query query)
          Returns the results of a query as a list of a specified class.
protected
<T> List<T>
list(Class<T> type, String queryName, Object value)
          Returns the results of a named query with a single parameter as a list of a specified class.
 void setSessionFactory(SessionFactory sessionFactory)
          Sets the session factory to use.
 void sync()
          Flushes the session and clears the session cache.
protected
<T> T
unique(Class<T> type, Query query)
          Returns the unique result of a query returning instances of a specified class.
protected
<T> T
unique(Class<T> type, String queryName, Object value)
          Returns the unique result of a named query with a single parameter returning instances of a specified class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDAOImpl

public AbstractDAOImpl(SessionFactory sessionFactory)
Constructs the DAO

Parameters:
sessionFactory - Hibernate Session factory.

AbstractDAOImpl

public AbstractDAOImpl()
Constructs the DAO

Method Detail

setSessionFactory

public void setSessionFactory(SessionFactory sessionFactory)
Sets the session factory to use.

Parameters:
sessionFactory - Hibernate session factory.

getSession

protected final Session getSession()
Returns the current session.

Returns:
The current session.

clear

public void clear()
Description copied from interface: DAO
Clears the session cache.

Specified by:
clear in interface DAO

flush

public void flush()
Description copied from interface: DAO
Flushes the session.

Specified by:
flush in interface DAO

sync

public void sync()
Description copied from interface: DAO
Flushes the session and clears the session cache.

Specified by:
sync in interface DAO

evict

protected void evict(Object object)
Remove the provided instance from the session cache.

Parameters:
object - The persistent instance to remove.

getNamedQuery

protected Query getNamedQuery(String queryName)
Returns a externally defined named query.

Parameters:
queryName - Query name.
Returns:
The requested query.

list

protected <T> List<T> list(Class<T> type,
                           Query query)
Returns the results of a query as a list of a specified class.

Parameters:
type - Entity type.
query - Query to execute.
Returns:
The results.

first

protected <T> T first(Class<T> type,
                      Query query)
Returns the first result of a query returning instances of a specified class.

Parameters:
type - Entity type.
query - Query to execute.
Returns:
The first result or null if there are no results.

unique

protected <T> T unique(Class<T> type,
                       Query query)
Returns the unique result of a query returning instances of a specified class.

Parameters:
type - Entity type.
query - Query to execute.
Returns:
The unique result or null if there are no results.
Throws:
NonUniqueResultException - if there are more than one result.

list

protected <T> List<T> list(Class<T> type,
                           String queryName,
                           Object value)
Returns the results of a named query with a single parameter as a list of a specified class.

Parameters:
type - Entity type.
queryName - Query name.
value - Non-null parameter value.
Returns:
The results.

unique

protected <T> T unique(Class<T> type,
                       String queryName,
                       Object value)
Returns the unique result of a named query with a single parameter returning instances of a specified class.

Parameters:
type - Entity type.
queryName - Query name.
value - Non-null parameter value.
Returns:
The unique result or null if there are no results.
Throws:
NonUniqueResultException - if there are more than one result.


Copyright © 2012. All Rights Reserved.