Created
April 17, 2015 17:05
-
-
Save nunenuh/1810589edf9c4b69d4ef to your computer and use it in GitHub Desktop.
SampleDAO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import epserv.orm.utils.HibernateUtil; | |
import java.util.List; | |
import org.hibernate.Criteria; | |
import org.hibernate.Session; | |
import org.hibernate.Transaction; | |
import org.hibernate.criterion.Restrictions; | |
import orm.entity.Subdomain; | |
/** | |
* | |
* @author gen5x4 | |
*/ | |
public class SubdomainDao { | |
public SubdomainDao() { | |
} | |
private Session begin() { | |
Session session = HibernateUtil.getSessionFactory().openSession(); | |
session.beginTransaction(); | |
return session; | |
} | |
public void save(Subdomain sbd) { | |
begin().save(sbd); | |
begin().getTransaction().commit(); | |
} | |
public void update(Subdomain sbd) { | |
Session session = HibernateUtil.getSessionFactory().openSession(); | |
session.beginTransaction(); | |
session.update(sbd); | |
session.getTransaction().commit(); | |
} | |
public void delete(Subdomain sbd) { | |
Session session = HibernateUtil.getSessionFactory().openSession(); | |
session.beginTransaction(); | |
session.delete(sbd); | |
session.getTransaction().commit(); | |
} | |
public Subdomain getById(int id) { | |
Session session = HibernateUtil.getSessionFactory().openSession(); | |
session.beginTransaction(); | |
Subdomain sbd = (Subdomain) session.load(Subdomain.class, id); | |
session.getTransaction().commit(); | |
return sbd; | |
} | |
public List getAll() { | |
Session session = HibernateUtil.getSessionFactory().openSession(); | |
session.beginTransaction(); | |
List<Subdomain> list = session.createCriteria(Subdomain.class).list(); | |
session.getTransaction().commit(); | |
return list; | |
} | |
public List getByIdAccount(int id) { | |
Session session = HibernateUtil.getSessionFactory().openSession(); | |
session.beginTransaction(); | |
Criteria cr = session.createCriteria(Subdomain.class); | |
cr.createCriteria("account").add(Restrictions.eq("id", id)); | |
List<Subdomain> list = cr.list(); | |
session.getTransaction().commit(); | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment