Pursue DAO Pattern:
The motivation is when you have a cascade of database operations that are common between the components, the implement a Bag to cover the search space with allcommon, and by the end you define delegation Object to execute specific operations.
Or also, the case of who smokes is the cigarrete.
package org.nanotek.dao;
|
|
import java.io.Serializable;
|
import java.util.List;
|
import org.nanotek.util.Base;
|
|
public interface DAO <T extends Base<?>>{
}
package org.nanotek.dao;
|
|
import java.util.List;
|
|
import org.hibernate.Session;
|
import org.hibernate.SessionFactory;
|
import org.nanotek.util.Base;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Transactional;
|
|
public abstract class BaseDAO {
|
|
protected Class<Base<?>> clazz;
//get set methods for the base class and the class is not bound to a specific container //yet. but its methods shall be declared in an interface.
} //which is the interface above. |
|
There after you implement the bag using the BaseDAO/DAO as follows.
public class TenantDAO<D extends DAO<Base<?>>, E extends Base<?>> extends BaseDAO implements DAOBag<DAO<Base<?>>, Base<?>> {
|
|
|
/** |
Deixa ae que agora que foi criado, soh eh removido quando morre. |
**/
|
protected DAO<E> dAOInstance;
}
package org.nanotek.dao;
|
|
import org.nanotek.util.Base;
|
|
public interface SpecializedBaseDAOInterface <T extends Base<?>>{
|
|
public boolean doSomethingNice(T instance);//return true or false to confirm if the operation
|
//was completed sucessfully (wich means something nice happen
|
//can also return a type T that was "enriched' by interceptors pre and pos.
|
|
} |
package org.nanotek.dao;
|
|
import org.nanotek.util.Base;
|
|
public class DelegateDAO extends TenantDAO<DAO<Base<?>>, Base<?>> implements SpecializedBaseDAOInterface<Base<?>> {
|
|
public DelegateDAO() {
|
}
|
|
@Override
|
public boolean doSomethingNice(Base<?> instance) {
|
return false;
|
}
|
|
} |
|