com.banda.serverbase.persistence
Interface GenericDAO<T,PK extends Serializable>

Type Parameters:
T - Type of handled object
PK - The primary key of the object
All Known Implementing Classes:
GenericHibernate3DAO, GenericHibernate4DAO

public interface GenericDAO<T,PK extends Serializable>

Title: GenericDAO

Description: Generic DAO (Data Access Object) containing common methods for object persistence.

Since:
2008
Author:
© Peter Banda

Method Summary
 void clear()
          Clears session.
 void evict(T object)
          Evicts given object from session.
 boolean exists(PK id)
          Checks for existence of an object with given key.
 void flush()
          Flushes session.
 Collection<T> get(Collection<PK> ids)
          Generic method to get objects based on class and identifiers.
 T get(PK id)
          Generic method to get an object based on class and identifier.
 List<T> getAll()
          Generic method used to get all objects of a particular type.
 List<T> getByExample(T object)
          Gets objects from the database that match given example.
 T getByUniqueExample(T object)
          Gets object from the database that match given example.
 PK getKey(T object)
          Generic method to get the identifier of a given object.
 T getLast()
          Generic method to get the last object.
 void remove(Collection<T> objects)
          Generic method to delete a given object
 void remove(PK id)
          Generic method to delete an object with given id
 void remove(T object)
          Generic method to delete a given object
<C extends Collection<T>>
C
save(C objects)
          Generic method to save collection of objects - handles insert, update and remove.
 T save(T object)
          Generic method to save an object - handles insert, update and remove.
 void setKey(T object, PK key)
          Generic method to set the identifier for a given object.
 

Method Detail

getAll

List<T> getAll()
Generic method used to get all objects of a particular type.

Returns:
List of populated objects
Throws:
Exception - When database problems occur

get

T get(PK id)
Generic method to get an object based on class and identifier.

Parameters:
id - The identifier (primary key) of the object to get
Returns:
The populated object with given key
Throws:
Exception - When database problems occur

get

Collection<T> get(Collection<PK> ids)
Generic method to get objects based on class and identifiers.

Parameters:
ids - The identifiers (primary keys) of the objects to get
Returns:
The populated objects with given keys
Throws:
Exception - When database problems occur

getLast

T getLast()
Generic method to get the last object.

Returns:
The last inserted object

getByExample

List<T> getByExample(T object)
Gets objects from the database that match given example.

Parameters:
object - The template object to match (not null columns)
Returns:
The loaded objects matching given template from the database
Throws:
Exception - When database problems occur

getByUniqueExample

T getByUniqueExample(T object)
Gets object from the database that match given example. There is maximum single object matching given (unique) criteria.

Parameters:
object - The template object to match (not null columns)
Returns:
The loaded object matching given template from the database (if any)
Throws:
Exception - When database problems occur

exists

boolean exists(PK id)
Checks for existence of an object with given key.

Parameters:
id - The id of the entity
Returns:
The result of the test
Throws:
Exception - When database problems occur

save

T save(T object)
Generic method to save an object - handles insert, update and remove.

Parameters:
object - The object to save
Returns:
The persisted object (if not removed)
Throws:
Exception - When database problems occur

save

<C extends Collection<T>> C save(C objects)
Generic method to save collection of objects - handles insert, update and remove.

Type Parameters:
C - Type of collection
Parameters:
objects - The objects to save
Throws:
Exception - When database problems occur

remove

void remove(T object)
Generic method to delete a given object

Parameters:
object - The object to remove
Throws:
Exception - When database problems occur

remove

void remove(Collection<T> objects)
Generic method to delete a given object

Parameters:
object - The object to remove
Throws:
Exception - When database problems occur

remove

void remove(PK id)
Generic method to delete an object with given id

Parameters:
id - The identifier (primary key) of the object to remove
Throws:
Exception - When database problems occur

flush

void flush()
Flushes session.


clear

void clear()
Clears session.


evict

void evict(T object)
Evicts given object from session.

Parameters:
object -

getKey

PK getKey(T object)
Generic method to get the identifier of a given object.

Parameters:
object - The object to get PK for
Returns:
The identifier (primary key) of a given object

setKey

void setKey(T object,
            PK key)
Generic method to set the identifier for a given object.

Parameters:
object - The object to get PK for
key - The identifier (primary key) of a given object


Copyright © 2013. All Rights Reserved.