List of usage examples for org.hibernate.criterion Restrictions and
public static LogicalExpression and(Criterion lhs, Criterion rhs)
From source file:chat.service.DoChat.java
License:LGPL
/** * read chats according to SO' {@link Chat#out} and {@link Chat#in} from * {@link Chat#datime}(excluded, or oldest if null), order by {@link Chat#datime} asc *//*from ww w .ja va2 s . co m*/ @Service @Transac.Readonly public List<Chat> read(Chat c) throws Exception { Criteria<Chat> t = data.criteria(Chat.class); User me = new User().id(sess.me); Criterion out = Restrictions.eq("out", me); if (c.in != null) out = Restrictions.and(out, // chats from me Restrictions.eq("in", c.in)); Criterion in = Restrictions.eq("in", me); if (c.out != null) in = Restrictions.and(in, // chats to me Restrictions.eq("out", c.out)); t.add(Restrictions.or(out, in)); if (c.datime != null) t.add(Restrictions.gt("datime", c.datime)); return t.addOrder(Order.asc("datime")).list(); }
From source file:cloudoutput.dao.NetworkMapEntryDAO.java
License:Open Source License
/** * Gets an existing network entry based on a source and a destination. * * @param source the name of a source entity. * @param destination the name of a destination entity. * @return the network entry, if it exists; * <code>null</code> otherwise. * @see NetworkMapEntry * @since 1.0/* w w w . ja v a 2 s .c o m*/ */ public NetworkMapEntry getNetworkMapEntry(String source, String destination) { Session session = HibernateUtil.getSession(); NetworkMapEntry entry = null; try { entry = (NetworkMapEntry) session.createCriteria(NetworkMapEntry.class).add(Restrictions .and(Restrictions.eq("source", source), Restrictions.eq("destination", destination))) .uniqueResult(); } catch (HibernateException ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); } finally { HibernateUtil.closeSession(session); } return entry; }
From source file:cn.newtouch.hibernate.dao.StudentDAO.java
License:Open Source License
public static void main(String[] args) { try {//from w w w . ja v a 2 s . c o m Session session = HibernateUtil.getSession(); String hql = " from Student"; List<Student> userList = session.createQuery(hql).list(); System.out.println("=====1=======" + userList.size()); Criteria criteria = session.createCriteria(Student.class); // criteria.add(Restrictions.eq("name", "HZZ")); // map criteria.add(Restrictions.allEq(new HashMap<String, String>())); // criteria.add(Restrictions.gt("id", new Long(1))); // criteria.add(Restrictions.ge("id", new Long(1))); // ? criteria.add(Restrictions.lt("id", new Long(1))); // ? criteria.add(Restrictions.le("id", new Long(1))); // xxxyyy criteria.add(Restrictions.between("id", new Long(1), new Long(2))); // ? criteria.add(Restrictions.like("name", "H")); // and? criteria.add(Restrictions.and(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1)))); // or? criteria.add(Restrictions.or(Restrictions.ge("id", new Long(1)), Restrictions.ge("id", new Long(1)))); userList = criteria.list(); System.out.println("=====2=======" + userList.size()); Student student = new Student(); student.setId(123456L); student.setName("hzz"); student.setAge(14); save(student); System.out.println("OK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); } catch (Exception e) { e.printStackTrace(); } }
From source file:cn.trymore.core.hibernate.HibernateUtils.java
License:Open Source License
/** * QBCAND/*from w w w . j a v a2 s . c om*/ * @param crit1 * @param crit2 * @return */ public static Criterion QBC_AND(Criterion crit1, Criterion crit2) { if (crit1 == null) { return crit2; } if (crit2 == null) { return crit1; } return Restrictions.and(crit1, crit2); }
From source file:com.abiquo.server.core.appslibrary.VirtualImageConversionDAO.java
License:Open Source License
/** * Get all the provided hypervisor compatible {@link VirtualImageConversion} for a given * {@link HypervisorType}//from w w w . j av a 2 s .co m * <p> * Before calling this method assure the virtualImage format IS NOT the hypervisorType base * format or compatible (conversion not needed). @see * {@link VirtualMachineServicePremium#shouldFindConversion} * * @return the list of all compatible {@link VirtualImageConversion} in <b>ANY state</b>. * {@link VirtualMachineServicePremium#selectConversion} will check the state and pick * the most suitable format. */ @SuppressWarnings("unchecked") public List<VirtualImageConversion> compatilbeConversions(final VirtualMachineTemplate virtualImage, final HypervisorType hypervisorType) { final Criterion compat = Restrictions.and(sameImage(virtualImage), targetFormatIn(hypervisorType.compatibleFormats)); return createCriteria(compat).list(); }
From source file:com.abiquo.server.core.appslibrary.VirtualImageConversionDAO.java
License:Open Source License
public boolean isConverted(final VirtualMachineTemplate image, final DiskFormatType targetType) { final Criterion compat = Restrictions.and(sameImage(image), targetFormatIn(targetType)); return !createCriteria(compat).list().isEmpty(); }
From source file:com.abiquo.server.core.appslibrary.VirtualImageConversionDAO.java
License:Open Source License
public boolean existDuplicatedConversion(final VirtualImageConversion conversion) { Criterion cri = Restrictions.and(sameImage(conversion), sameSourceFormat(conversion)); cri = Restrictions.and(cri, sameTargetFormat(conversion)); return existsAnyByCriterions(cri); }
From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java
License:Open Source License
private Criterion importedVirtualMachineTemplate(final Enterprise enterprise) { return Restrictions.and(sameEnterprise(enterprise), repositoryNull()); }
From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java
License:Open Source License
/** * If (finished) conversions check some compatible. Left join to {@link VirtualImageConversion} *//*from ww w.ja va 2 s .c om*/ private Criterion compatibleConversions(final Collection<DiskFormatType> types, final Criteria criteria) { criteria.createAlias(VirtualMachineTemplate.CONVERSIONS_PROPERTY, "conversions", JoinFragment.LEFT_OUTER_JOIN); Criterion finished = Restrictions.eq("conversions." + VirtualImageConversion.STATE_PROPERTY, ConversionState.FINISHED); Criterion compatible = Restrictions.in("conversions." + VirtualImageConversion.TARGET_TYPE_PROPERTY, types); return Restrictions.and(finished, compatible); }
From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java
License:Open Source License
private static Criterion statefulVirtualMachineTemplate(final StatefulInclusion stateful, final Criteria criteria) { Criterion cri = Restrictions.eq(VirtualMachineTemplate.STATEFUL_PROPERTY, true); switch (stateful) { case ALL:/* w w w . ja va2 s. c o m*/ Restrictions.and(cri, Restrictions.isNotNull(VirtualMachineTemplate.VOLUME_PROPERTY)); break; case USED: // use function criteriaWithStatefulNavigation before return Restrictions.and(cri, Restrictions.eq("vl." + VolumeManagement.STATE_PROPERTY, VolumeState.ATTACHED)); case NOTUSED: // use function criteriaWithStatefulNavigation before return Restrictions.and(cri, Restrictions.eq("vl." + VolumeManagement.STATE_PROPERTY, VolumeState.DETACHED)); } return cri; }