br.com.arsmachina.controller.impl
Class ControllerImpl<T,K extends Serializable>

java.lang.Object
  extended by br.com.arsmachina.controller.impl.ControllerImpl<T,K>
Type Parameters:
T - the entity class related to this controller.
K - the type of the field that represents the entity class' primary key.
All Implemented Interfaces:
Controller<T,K>, ReadableController<T,K>, WriteableController<T,K>

public abstract class ControllerImpl<T,K extends Serializable>
extends Object
implements Controller<T,K>

Abstract class that implements the Controller interface by delegating all method calls to a DAO passed through its constructor.

Author:
Thiago H. de Paula Figueiredo

Constructor Summary
ControllerImpl(br.com.arsmachina.dao.DAO<T,K> dao)
          Single constructor of this class.
 
Method Summary
 int countAll()
          Invokes dao.countAll().
 void delete(K id)
          Invokes dao.delete().
 void delete(T object)
          Invokes dao.delete().
 void evict(T object)
          Invokes dao.evict().
 List<T> findAll()
          Invokes dao.findAll().
 List<T> findAll(int firstResult, int maxResults, br.com.arsmachina.dao.SortCriterion... sortCriteria)
          Invokes dao.findAll().
 List<T> findByExample(T example)
          Invokes dao.findByExample().
 T findById(K id)
          Invokes dao.findById().
 List<T> findByIds(K... ids)
          Invokes dao.findByIds().
 boolean isPersistent(T object)
          Invokes dao.isPersistent().
 T reattach(T object)
          Invokes dao.reattach().
 void refresh(T object)
          Invokes dao.refresh().
 void save(T object)
          Invokes dao.save().
 T saveOrUpdate(T object)
          Invokes save(Object) if the object is persistent and update(Object) otherwise.
 T update(T object)
          Invokes dao.update().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ControllerImpl

public ControllerImpl(br.com.arsmachina.dao.DAO<T,K> dao)
Single constructor of this class.

Parameters:
dao - a DAO. It cannot be null.
Method Detail

countAll

public int countAll()
Invokes dao.countAll().

Specified by:
countAll in interface ReadableController<T,K extends Serializable>
Returns:
See Also:
ReadableControllerImpl.countAll()

findAll

public List<T> findAll()
Invokes dao.findAll().

Specified by:
findAll in interface ReadableController<T,K extends Serializable>
Returns:
See Also:
ReadableControllerImpl.findAll()

findAll

public List<T> findAll(int firstResult,
                       int maxResults,
                       br.com.arsmachina.dao.SortCriterion... sortCriteria)
Invokes dao.findAll().

Specified by:
findAll in interface ReadableController<T,K extends Serializable>
Parameters:
firstResult -
maxResults -
sortCriteria -
Returns:
See Also:
ReadableControllerImpl.findAll(int, int, br.com.arsmachina.dao.SortCriterion[])

findByExample

public List<T> findByExample(T example)
Invokes dao.findByExample().

Specified by:
findByExample in interface ReadableController<T,K extends Serializable>
Parameters:
example -
Returns:
See Also:
ReadableControllerImpl.findByExample(java.lang.Object)

findById

public T findById(K id)
Invokes dao.findById().

Specified by:
findById in interface ReadableController<T,K extends Serializable>
Parameters:
id -
Returns:
See Also:
ReadableControllerImpl.findById(java.io.Serializable)

findByIds

public List<T> findByIds(K... ids)
Invokes dao.findByIds().

Specified by:
findByIds in interface ReadableController<T,K extends Serializable>
Parameters:
ids -
Returns:
See Also:
br.com.arsmachina.controller.impl.ReadableControllerImpl#findByIds(K[])

refresh

public void refresh(T object)
Invokes dao.refresh().

Parameters:
object -
See Also:
ReadableControllerImpl.refresh(java.lang.Object)

delete

public void delete(K id)
Invokes dao.delete().

Specified by:
delete in interface WriteableController<T,K extends Serializable>
Parameters:
id -
See Also:
WriteableControllerImpl.delete(java.io.Serializable)

delete

public void delete(T object)
Invokes dao.delete().

Specified by:
delete in interface WriteableController<T,K extends Serializable>
Parameters:
object -
See Also:
WriteableControllerImpl.delete(java.lang.Object)

evict

public void evict(T object)
Invokes dao.evict().

Specified by:
evict in interface WriteableController<T,K extends Serializable>
Parameters:
object -
See Also:
WriteableControllerImpl.evict(java.lang.Object)

isPersistent

public boolean isPersistent(T object)
Invokes dao.isPersistent().

Specified by:
isPersistent in interface WriteableController<T,K extends Serializable>
Parameters:
object -
Returns:
See Also:
WriteableControllerImpl.isPersistent(java.lang.Object)

save

public void save(T object)
Invokes dao.save().

Specified by:
save in interface WriteableController<T,K extends Serializable>
Parameters:
object -
See Also:
WriteableControllerImpl.save(java.lang.Object)

saveOrUpdate

public T saveOrUpdate(T object)
Invokes save(Object) if the object is persistent and update(Object) otherwise. The object is considered persistent if isPersistent(Object) returns true.

Specified by:
saveOrUpdate in interface WriteableController<T,K extends Serializable>
Parameters:
object - a T.
Returns:
a T.

update

public T update(T object)
Invokes dao.update().

Specified by:
update in interface WriteableController<T,K extends Serializable>
Parameters:
object -
Returns:
a T.
See Also:
WriteableControllerImpl.update(java.lang.Object)

reattach

public T reattach(T object)
Invokes dao.reattach().

Specified by:
reattach in interface ReadableController<T,K extends Serializable>
Parameters:
object -
Returns:
See Also:
ReadableController.reattach(java.lang.Object)


Copyright © 2008-2009 Thiago H. de Paula Figueiredo. All Rights Reserved.