Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package co.webmonkey.models.management; import co.webmonkey.config.HibernateUtil; import co.webmonkey.models.entities.Infoswebsite; import co.webmonkey.models.entities.Users; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.criterion.Criterion; import org.hibernate.criterion.Projections; /** * * @author Hamza */ public class WebsiteManagement { Session session; public WebsiteManagement() { session = HibernateUtil.getSessionFactory().openSession(); } public boolean isInstalled() { session.getTransaction().begin(); Criteria cr = session.createCriteria(Users.class); cr.setProjection(Projections.rowCount()); int nb = ((Long) cr.uniqueResult()).intValue(); session.getTransaction().commit(); return nb > 0; } public Infoswebsite getWebsite() { session.getTransaction().begin(); Criteria cr = session.createCriteria(Infoswebsite.class); Infoswebsite website = (Infoswebsite) cr.list().get(0); session.getTransaction().commit(); return website; } public void updateWebsite(Infoswebsite iw) { session.getTransaction().begin(); session.saveOrUpdate(iw); session.getTransaction().commit(); } }