Created
May 11, 2013 17:19
-
-
Save rvazquezglez/5560683 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package javagurus.curso.frameworks.dao; | |
import java.util.List; | |
import javagurus.curso.frameworks.model.Cliente; | |
import javagurus.curso.frameworks.util.HibernateUtil; | |
import org.hibernate.Criteria; | |
import org.hibernate.Query; | |
import org.hibernate.Session; | |
import org.hibernate.criterion.Projections; | |
public class ClienteDao { | |
public List<Cliente> buscarClientesPorNombre(String nombre){ | |
Session session = HibernateUtil.getSessionFactory() | |
.openSession(); | |
Query query = session.createQuery( | |
"from Cliente where nombre like :param"); | |
query.setString("param", "%"+nombre+"%"); | |
return (List<Cliente>) query.list(); | |
} | |
public Integer contarClientes(){ | |
Session session = HibernateUtil.getSessionFactory() | |
.openSession(); | |
Query query = session.createQuery( | |
"select count(*) from Cliente"); | |
return ((Long) query.list().get(0)).intValue(); | |
// Criteria criter = session.createCriteria(Cliente.class) | |
// .setProjection(Projections.rowCount()); | |
// | |
// return criter.uniqueResult(); | |
} | |
public List<Cliente> listarClientesPaginado(int from, int rows){ | |
Session session = HibernateUtil.getSessionFactory() | |
.openSession(); | |
Query query = session.createQuery( | |
"from Cliente"); | |
query.setFirstResult(from); | |
query.setMaxResults(rows); | |
return (List<Cliente>) query.list(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment