Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yogonza524/74025bf50b250be78489 to your computer and use it in GitHub Desktop.
Save yogonza524/74025bf50b250be78489 to your computer and use it in GitHub Desktop.
/*
* @Owner Gonzalo H. Mendoza
* @Version 1.0.0
*/
import java.util.List;
import org.blh.habilitacion.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
/**
*
* @author Gonza
*/
public abstract class AbstractController<T> {
protected static SessionFactory sf;
protected boolean composite = false;
public List<T> all(){
sf = HibernateUtil.getSessionFactory();
Session s = sf.openSession();
List<T> l = s.createCriteria(className()).list();
beforeAll();
if(composite){
for(T o : l){
initialize(o);
}
}
s.close();
afterAll();
return l;
}
public abstract Class<T> className();
public abstract void initialize(T entity);
public void beforeAll(){}
public void afterAll(){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment