List of usage examples for org.hibernate.criterion Restrictions disjunction
public static Disjunction disjunction()
From source file:com.lyh.licenseworkflow.dao.EnhancedHibernateDaoSupport.java
/** * ?SQLor?? from DeviceResource where (type = 'ROUTER' or type = 'L3_SWITCH'); * <p/>//from ww w .j av a2 s . c o m * <p/> * Notes: or<br> * <br> * Create Author : allen.wang <br> * Create Date : 2009-3-18 * * @param start * @param pageSize * @param propertyName * @param values * @return */ @SuppressWarnings("unchecked") public List<T> getPagingEntitiesByOrCondition(final int start, final int pageSize, final String propertyName, final Object... values) { return (List<T>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(getEntityName()); Disjunction d = Restrictions.disjunction(); criteria = criteria.add(d); for (int i = 0; i < values.length; i++) d.add(Restrictions.eq(propertyName, values[i])); criteria.setFirstResult(start); criteria.setMaxResults(pageSize); return criteria.list(); } }); }
From source file:com.lyh.licenseworkflow.dao.EnhancedHibernateDaoSupport.java
/** * ??? from DeviceResource where (type = 'ROUTER' or type = 'L3_SWITCH');<br> * <br>// ww w. j a v a 2s . c om * Create Author : allen.wang <br> * Create Date : 2009-3-18 * * @param propertyName * @param values * @return */ public int countEntitiesByOrCondition(final String propertyName, final Object... values) { return (Integer) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(getEntityName()); Disjunction d = Restrictions.disjunction(); criteria = criteria.add(d); for (int i = 0; i < values.length; i++) d.add(Restrictions.eq(propertyName, values[i])); int num = ((Integer) criteria.setProjection(Projections.rowCount()).uniqueResult()).intValue();// ??? return new Integer(num); } }); }
From source file:com.lyh.licenseworkflow.dao.EnhancedHibernateDaoSupport.java
/** * ?SQLor?? from DeviceResource where (type = 'ROUTER' or type = 'L3_SWITCH'); * <p/>//from w ww .j a v a 2 s .c om * <p/> * Notes: or * * @param propertyName ?? * @param values ? * @return ?? */ @SuppressWarnings("unchecked") public List<T> getEntitiesByOrCondition(final String propertyName, final Object... values) { return (List<T>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria c = session.createCriteria(getEntityName()); Disjunction d = Restrictions.disjunction(); c = c.add(d); for (int i = 0; i < values.length; i++) d.add(Restrictions.eq(propertyName, values[i])); return c.list(); } }); }
From source file:com.maydesk.base.dao.DaoRole.java
License:Mozilla Public License
public static List<MUserRole> getRoles(MUser user, MBase context, Session... session2) { Session session = null;/* w ww . java 2 s . c o m*/ if (session2 != null && session2.length > 0) { session = session2[0]; } else { session = PDHibernateFactory.getSession(); } Criteria criteria = session.createCriteria(MUserRole.class); criteria.add(eq("userRef", user)); if (context == null) { criteria.add(Restrictions.isNull("contextClass")); } else { Disjunction orCondition = Restrictions.disjunction(); criteria.add(orCondition); Conjunction andCondition = Restrictions.conjunction(); orCondition.add(andCondition); andCondition.add(eq("contextId", context.getId())); andCondition.add(eq("contextClass", context.getClass().getCanonicalName())); orCondition.add(Restrictions.isNull("contextClass")); } return criteria.list(); }
From source file:com.myapp.dao.EmployeeDao.java
public List getAllEmployees(String empname) { SessionFactory factory = NewHibernateUtil.getSessionFactory(); Session session = factory.openSession(); Criteria crit = session.createCriteria(Employees.class); Disjunction or = Restrictions.disjunction(); or.add(Restrictions.like("firstName", empname + "%")); or.add(Restrictions.like("lastName", empname + "%")); crit.add(or);/*from w w w .j a va 2 s . co m*/ List<Employees> employees = crit.list(); List emplist = new LinkedList(); for (Employees obj : employees) { String fullname = obj.getFirstName() + " " + obj.getLastName(); emplist.add(fullname); } return emplist; }
From source file:com.mycompany.CRMFly.hibernateAccess.CallsDAOImpl.java
public List<Calls> getFromProxy(List<Calls> proxy) { Disjunction or = Restrictions.disjunction(); for (Calls pr : proxy) { or.add(Restrictions.eq("id", pr.getId())); }/*from ww w .j av a 2 s . co m*/ return sessionFactory.getCurrentSession().createCriteria(Calls.class).add(or).list(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ClientsDAOImpl.java
public List<Clients> getFromProxy(List<Clients> proxy) { Disjunction or = Restrictions.disjunction(); for (Clients pr : proxy) { or.add(Restrictions.eq("id", pr.getId())); }/*from ww w. j a v a 2 s .c o m*/ return sessionFactory.getCurrentSession().createCriteria(Clients.class).add(or).list(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContactsDAOImpl.java
public List<Contacts> getFromProxy(List<Contacts> proxy) { Disjunction or = Restrictions.disjunction(); for (Contacts pr : proxy) { or.add(Restrictions.eq("id", pr.getId())); }/*from w w w .ja v a2 s.c o m*/ return sessionFactory.getCurrentSession().createCriteria(Contacts.class).add(or).list(); }
From source file:com.mycompany.CRMFly.hibernateAccess.ContractsDAOImpl.java
public List<Contracts> getFromProxy(List<Contracts> proxy) { Disjunction or = Restrictions.disjunction(); for (Contracts pr : proxy) { or.add(Restrictions.eq("id", pr.getId())); }//from w w w . ja va 2 s .com return sessionFactory.getCurrentSession().createCriteria(Contracts.class).add(or).list(); }
From source file:com.mycompany.CRMFly.hibernateAccess.CustomersDAOImpl.java
public List<Customers> getFromProxy(List<Customers> proxy) { Disjunction or = Restrictions.disjunction(); for (Customers pr : proxy) { or.add(Restrictions.eq("id", pr.getId())); }// www . j av a2s. c o m return sessionFactory.getCurrentSession().createCriteria(Customers.class).add(or).list(); }