List of usage examples for org.hibernate.criterion Restrictions isNull
public static Criterion isNull(String propertyName)
From source file:monasca.thresh.infrastructure.persistence.hibernate.AlarmSqlImpl.java
License:Apache License
@SuppressWarnings("unchecked") private List<Alarm> findAlarms(@Nonnull final LookupHelper lookupHelper) { StatelessSession session = null;//from ww w . j a v a 2 s.c om try { session = sessionFactory.openStatelessSession(); final Criteria criteria = lookupHelper.apply(session.createCriteria(AlarmDb.class, "a") .createAlias("a.subAlarms", "sa").createAlias("a.alarmDefinition", "ad") .add(Restrictions.isNull("ad.deletedAt")).addOrder(Order.asc("a.id")) .setProjection(Projections.projectionList().add(Projections.property("a.id")) .add(Projections.property("a.alarmDefinition.id")).add(Projections.property("a.state")) .add(Projections.alias(Projections.property("sa.id"), "sub_alarm_id")) .add(Projections.property("sa.expression")) .add(Projections.property("sa.subExpression.id")) .add(Projections.property("ad.tenantId"))) .setReadOnly(true)); assert criteria != null; return this.createAlarms(session, (List<Object[]>) criteria.list(), lookupHelper); } finally { if (session != null) { session.close(); } } }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method finds all the deployments of a <code>Device</code> that fall * within a certain time window. This is usually done when searching for * data from that device./*from ww w . j a va 2 s . c o m*/ * * @param device * @param startDate * @param endDate * @param orderByPropertyName * @param ascendingOrDescending * @param returnFullObjectGraph * @return * @throws MetadataAccessException */ public Collection findByDeviceAndTimeWindow(Device device, Date startDate, Date endDate, String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException { // The collection to return Collection dataProducersToReturn = new ArrayList(); // First make sure the device exists DeviceDAO deviceDAO = new DeviceDAO(getSession()); Device persistentDevice = null; persistentDevice = (Device) deviceDAO.findEquivalentPersistentObject(device, false); if (persistentDevice == null) return dataProducersToReturn; // Create the criteria try { Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("device", persistentDevice)); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); // Add the time criteria if (startDate != null) { criteria.add( Restrictions.or(Restrictions.gt("endDate", startDate), Restrictions.isNull("endDate"))); } if (endDate != null) { criteria.add( Restrictions.or(Restrictions.lt("startDate", endDate), Restrictions.isNull("startDate"))); } addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); } catch (HibernateException e) { throw new MetadataAccessException(e.getMessage()); } // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); return dataProducersToReturn; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method returns all the <code>DataProducer</code> that have no end * date, no parent, and are of type Deployment. */// www .j a v a 2 s .co m public Collection findCurrentParentlessDeployments(String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException { // The collection to return Collection dataProducersToReturn = new ArrayList(); // Create the criteria try { Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.isNull("endDate")); criteria.add(Restrictions.isNull("parentDataProducer")); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); } catch (HibernateException e) { throw new MetadataAccessException(e.getMessage()); } // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); // Now return it return dataProducersToReturn; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method returns all the <code>DataProducer</code> that have no * parent, are of type Deployment, and match the name criteria given *///www . j a v a2 s . c om public Collection findParentlessDeploymentsByName(String name, boolean exactMatch, String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException { // The collection to return Collection dataProducersToReturn = new ArrayList(); // Create the criteria try { Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.isNull("parentDataProducer")); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); // If exact match if (exactMatch) { criteria.add(Restrictions.eq("name", name)); } else { criteria.add(Restrictions.like("name", "%" + name + "%")); } addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); } catch (HibernateException e) { throw new MetadataAccessException(e.getMessage()); } // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); // Now return it return dataProducersToReturn; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method returns all open deployments (anything without an end date) * /* w w w . j a v a 2 s .c om*/ * @param orderByPropertyName * @param ascendingOrDescending * @param returnFullObjectGraph * @return */ public Collection findCurrentDeployments(String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException { // The collection to return Collection dataProducersToReturn = new ArrayList(); // Create the criteria Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); criteria.add(Restrictions.isNull("endDate")); addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); return dataProducersToReturn; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method returns all the <code>DataProducer</code> that are of type * Deployment, that are associated directly with the given * <code>Device</code> and have no end time (endDate is null). * /*from w w w.j av a2 s . c om*/ * @param device * @param orderByPropertyName * @param ascendingOrDescending * @param returnFullObjectGraph * @return */ public Collection findCurrentDeploymentsOfDevice(Device device, String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException { // First make sure the device exists DeviceDAO deviceDAO = new DeviceDAO(getSession()); Device persistentDevice = null; persistentDevice = (Device) deviceDAO.findEquivalentPersistentObject(device, false); if (persistentDevice == null) throw new MetadataAccessException("A matching device could not be found in the system"); // The collection to return Collection dataProducersToReturn = new ArrayList(); // Create the criteria try { Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("device", persistentDevice)); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); criteria.add(Restrictions.isNull("endDate")); addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); } catch (HibernateException e) { throw new MetadataAccessException(e.getMessage()); } // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); return dataProducersToReturn; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method returns all the <code>DataProducer</code> that are of type * Deployment, that have a specified role (e.g. string "platform" aka * DataProducer.ROLE_PLATFORM) and have no end time (endDate is null). * /* ww w .ja v a2 s . c o m*/ * @param role * @param orderByPropertyName * @param ascendingOrDescending * @param returnFullObjectGraph * @return * @throws MetadataException * @throws MetadataAccessException */ public Collection findCurrentDeploymentsByRole(String role, String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException, MetadataException { if (!DataProducer.isValidRole(role)) { throw new MetadataException( "The role specified (" + role + ") does not match a constant defined in this class"); } // The collection to return Collection dataProducersToReturn = new ArrayList(); // Create the criteria try { Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("role", role)); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); criteria.add(Restrictions.isNull("endDate")); addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); } catch (HibernateException e) { throw new MetadataAccessException(e.getMessage()); } // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); return dataProducersToReturn; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * This method returns all the <code>DataProducer</code> that are of type * Deployment, that have a specified role (e.g. string "platform" aka * DataProducer.ROLE_PLATFORM) and have no end time (endDate is null). * /*from ww w . java 2 s. c om*/ * @param role * @param orderByPropertyName * @param ascendingOrDescending * @param returnFullObjectGraph * @return * @throws MetadataException * @throws MetadataAccessException */ public Collection findCurrentDeploymentsByRoleAndName(String role, String name, boolean exactMatch, String orderByPropertyName, String ascendingOrDescending, boolean returnFullObjectGraph) throws MetadataAccessException, MetadataException { if (!DataProducer.isValidRole(role)) { throw new MetadataException( "The role specified (" + role + ") does not match a constant defined in this class"); } // The collection to return Collection dataProducersToReturn = new ArrayList(); // Create the criteria try { Criteria criteria = getSession().createCriteria(DataProducer.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("role", role)); criteria.add(Restrictions.eq("dataProducerType", DataProducer.TYPE_DEPLOYMENT)); criteria.add(Restrictions.isNull("endDate")); if ((name != null) && (!name.equals(""))) { if (exactMatch) { criteria.add(Restrictions.eq("name", name)); } else { criteria.add(Restrictions.like("name", "%" + name + "%")); } } addOrderByCriteria(criteria, orderByPropertyName, ascendingOrDescending); dataProducersToReturn = criteria.list(); } catch (HibernateException e) { throw new MetadataAccessException(e.getMessage()); } // If the full object graphs are requested if (returnFullObjectGraph) dataProducersToReturn = getRealObjectsAndRelationships(dataProducersToReturn); return dataProducersToReturn; }
From source file:moos.ssds.dao.DataProducerDAO.java
License:LGPL
/** * TODO kgomes document this/* w w w. jav a 2s . co m*/ * * @param countQuery * @param id * @param name * @param exactNameMatch * @param dataProducerType * @param startDate * @param boundedByStartDate * @param endDate * @param boundedByEndDate * @param geospatialLatMin * @param geospatialLatMax * @param geospatialLonMin * @param geospatialLonMax * @param geospatialDepthMin * @param geospatialDepthMax * @param geospatialBenthicAltitudeMin * @param geospatialBenthicAltitudeMax * @param hostName * @param exactHostNameMatch * @param orderByProperty * @param ascendOrDescend * @return * @throws MetadataAccessException */ private Criteria formulatePropertyCriteria(boolean countQuery, Long id, String name, boolean exactNameMatch, String dataProducerType, Date startDate, boolean boundedByStartDate, Date endDate, boolean boundedByEndDate, Double geospatialLatMin, Double geospatialLatMax, Double geospatialLonMin, Double geospatialLonMax, Float geospatialDepthMin, Float geospatialDepthMax, Float geospatialBenthicAltitudeMin, Float geospatialBenthicAltitudeMax, String hostName, boolean exactHostNameMatch, String orderByProperty, String ascendOrDescend) throws MetadataAccessException { // The Criteria to return Criteria criteria = getSession().createCriteria(DataProducer.class); // Make it distinct criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Check for exceptional conditions on the query if ((dataProducerType != null) && (!DataProducer.isValidDataProducerType(dataProducerType))) throw new MetadataAccessException("The dataProducerType (" + dataProducerType + ") does not match a constant defined in the DataProducer class"); if ((geospatialLatMin != null) && (geospatialLatMax != null)) if (geospatialLatMax.doubleValue() < geospatialLatMin.doubleValue()) throw new MetadataAccessException("The maximum latitude specified was less than the minimum."); if ((geospatialLonMin != null) && (geospatialLonMax != null)) if (geospatialLonMax.doubleValue() < geospatialLonMin.doubleValue()) throw new MetadataAccessException("The maximum longitude specified was less than the minimum."); if ((geospatialDepthMin != null) && (geospatialDepthMax != null)) if (geospatialDepthMax.doubleValue() < geospatialDepthMin.doubleValue()) throw new MetadataAccessException("The depth maximum specified was less than the minimum."); if ((geospatialBenthicAltitudeMin != null) && (geospatialBenthicAltitudeMax != null)) if (geospatialBenthicAltitudeMax.doubleValue() < geospatialBenthicAltitudeMin.doubleValue()) throw new MetadataAccessException( "The benthic altitude maximum specified was less than the minimum."); if ((startDate != null) && (endDate != null) && (endDate.before(startDate))) throw new MetadataAccessException("The end date specified (" + endDate + ") is before the start date specified (" + startDate + ")"); // Now build the Criteria if (id != null) { criteria.add(Restrictions.eq("id", id)); } else { if ((name != null) && (!name.equals(""))) { if (exactNameMatch) { criteria.add(Restrictions.eq("name", name)); } else { criteria.add(Restrictions.like("name", "%" + name + "%")); } } if (dataProducerType != null) { criteria.add(Restrictions.eq("dataProducerType", dataProducerType)); } if (startDate != null) { criteria.add( Restrictions.or(Restrictions.gt("endDate", startDate), Restrictions.isNull("endDate"))); if (boundedByStartDate) { criteria.add(Restrictions.gt("startDate", startDate)); } } if (endDate != null) { criteria.add( Restrictions.or(Restrictions.lt("startDate", endDate), Restrictions.isNull("startDate"))); if (boundedByEndDate) { criteria.add(Restrictions.lt("endDate", endDate)); } } if (geospatialLatMin != null) criteria.add(Restrictions.ge("nominalLatitude", geospatialLatMin)); if (geospatialLatMax != null) criteria.add(Restrictions.le("nominalLatitude", geospatialLatMax)); if (geospatialLonMin != null) criteria.add(Restrictions.ge("nominalLongitude", geospatialLonMin)); if (geospatialLonMax != null) criteria.add(Restrictions.le("nominalLongitude", geospatialLonMax)); if (geospatialDepthMin != null) criteria.add(Restrictions.le("nominalDepth", geospatialDepthMin)); if (geospatialDepthMax != null) criteria.add(Restrictions.ge("nominalDepth", geospatialDepthMax)); if (geospatialBenthicAltitudeMin != null) criteria.add(Restrictions.ge("benthicAltitude", geospatialBenthicAltitudeMin)); if (geospatialBenthicAltitudeMax != null) criteria.add(Restrictions.lt("benthicAltitude", geospatialBenthicAltitudeMax)); if ((hostName != null) && (!hostName.equals(""))) { if (exactHostNameMatch) { criteria.add(Restrictions.eq("hostName", hostName)); } else { criteria.add(Restrictions.like("hostName", "%" + hostName + "%")); } } } // Setup if a count query, if not add fetching and ordering if (countQuery) { criteria.setProjection(Projections.rowCount()); } else { addOrderByCriteria(criteria, orderByProperty, ascendOrDescend); } // Now return the Criteria return criteria; }
From source file:moos.ssds.dao.EventDAO.java
License:LGPL
/** * //w ww. j av a 2 s .c o m * @param countQuery * @param id * @param name * @param exactNameMatch * @param startDate * @param boundedByStartDate * @param endDate * @param boundedByEndDate * @param orderByProperty * @param ascendOrDescend * @return * @throws MetadataAccessException */ private Criteria formulatePropertyCriteria(boolean countQuery, Long id, String name, boolean exactNameMatch, Date startDate, boolean boundedByStartDate, Date endDate, boolean boundedByEndDate, String orderByProperty, String ascendOrDescend) throws MetadataAccessException { // The Criteria to return Criteria criteria = getSession().createCriteria(Event.class); // Make it distinct criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Check for exceptional conditions on the query if ((startDate != null) && (endDate != null) && (endDate.before(startDate))) throw new MetadataAccessException("The end date specified (" + endDate + ") is before the start date specified (" + startDate + ")"); // Now build the Criteria if (id != null) { criteria.add(Restrictions.eq("id", id)); } else { if ((name != null) && (!name.equals(""))) { if (exactNameMatch) { criteria.add(Restrictions.eq("name", name)); } else { criteria.add(Restrictions.like("name", "%" + name + "%")); } } if (startDate != null) { criteria.add( Restrictions.or(Restrictions.gt("endDate", startDate), Restrictions.isNull("endDate"))); if (boundedByStartDate) { criteria.add(Restrictions.gt("startDate", startDate)); } } if (endDate != null) { criteria.add( Restrictions.or(Restrictions.lt("startDate", endDate), Restrictions.isNull("startDate"))); if (boundedByEndDate) { criteria.add(Restrictions.lt("endDate", endDate)); } } } // Setup if a count query, if not add fetching and ordering if (countQuery) { criteria.setProjection(Projections.rowCount()); } else { addOrderByCriteria(criteria, orderByProperty, ascendOrDescend); } // Now return the Criteria return criteria; }