Example usage for org.hibernate.criterion Restrictions isNull

List of usage examples for org.hibernate.criterion Restrictions isNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNull.

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

From source file:com.emergya.persistenceGeo.dao.impl.ZoneEntityDaoHibernateImpl.java

License:Open Source License

/**
 * Get a zones list by the zone name /*from   ww w .ja  va  2  s .c o  m*/
 * 
 * @param <code>zoneName</code>
 * @param isEnabled
 * 
 * @return Entities list associated with the zone name or null if not found 
 */
public List<AbstractZoneEntity> getZones(String zoneName, Boolean isEnabled) {

    Criteria criteria = getSession().createCriteria(persistentClass).add(Restrictions.eq("name", zoneName));

    if (isEnabled == null) {
        criteria.add(Restrictions.isNull("enabled"));
    } else if (isEnabled) {
        criteria.add(Restrictions.eq("enabled", isEnabled));
    } else {
        Disjunction dis = Restrictions.disjunction();
        dis.add(Restrictions.isNull("enabled"));
        dis.add(Restrictions.eq("enabled", isEnabled));
        criteria.add(dis);
    }

    return criteria.list();
}

From source file:com.emergya.persistenceGeo.dao.impl.ZoneEntityDaoHibernateImpl.java

License:Open Source License

/**
 * Get a zones list by its type//from   ww w. j  a  v  a2 s. co  m
 *
 * @param <code>zoneType</code>
 * @param isEnabled
 *
 * @return Entities list associated with the zone type or null if not found
 */
public List<AbstractZoneEntity> findByType(String zoneType, Boolean isEnabled) {

    Criteria criteria = getSession().createCriteria(persistentClass).add(Restrictions.eq("type", zoneType));

    if (isEnabled == null) {
        criteria.add(Restrictions.isNull("enabled"));
    } else if (isEnabled) {
        criteria.add(Restrictions.eq("enabled", isEnabled));
    } else {
        Disjunction dis = Restrictions.disjunction();
        dis.add(Restrictions.isNull("enabled"));
        dis.add(Restrictions.eq("enabled", isEnabled));
        criteria.add(dis);
    }

    return criteria.list();
}

From source file:com.emergya.persistenceGeo.dao.impl.ZoneEntityDaoHibernateImpl.java

License:Open Source License

/**
 * Find zone by id//from  w ww  .  j  ava2  s  .c om
 * 
 * @param idParent
 * @param isEnabled
 * 
 * @return zones
 */
public List<AbstractZoneEntity> findByParent(Long idParent, Boolean isEnabled) {
    Criteria criteria = getSession().createCriteria(persistentClass).add(Restrictions.eq("id", idParent))
            .createAlias("zoneList", "child");

    if (isEnabled == null) {
        criteria.add(Restrictions.isNull("enabled"));
    } else if (isEnabled) {
        criteria.add(Restrictions.eq("enabled", isEnabled));
    } else {
        Disjunction dis = Restrictions.disjunction();
        dis.add(Restrictions.isNull("enabled"));
        dis.add(Restrictions.eq("enabled", isEnabled));
        criteria.add(dis);
    }

    return criteria.list();
}

From source file:com.enonic.cms.store.dao.GroupEntityDao.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
public List<GroupEntity> findByQuery(final GroupQuery spec) {
    return (List<GroupEntity>) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Criteria crit = session.createCriteria(GroupEntity.class).setCacheable(true);

            if (spec.getUserStoreKey() != null) {
                crit.add(Restrictions.eq("userStore.key", spec.getUserStoreKey().toInt()));
            } else if (spec.isGlobalOnly()) {
                crit.add(Restrictions.isNull("userStore.key"));
            }/*from   w w  w  .j a va2 s . c  o m*/

            if (!spec.isIncludeDeleted()) {
                crit.add(Restrictions.eq("deleted", 0));
            }
            if (spec.getQuery() != null && spec.getQuery().length() > 0) {
                crit.add(Restrictions.ilike("name", spec.getQuery(), MatchMode.ANYWHERE));
            }

            if (spec.getOrderBy() != null && !spec.getOrderBy().equals("")) {
                if (spec.isOrderAscending()) {
                    crit.addOrder(Order.asc(spec.getOrderBy()).ignoreCase());
                } else {
                    crit.addOrder(Order.desc(spec.getOrderBy()).ignoreCase());
                }
            }

            if (spec.getGroupTypes() != null) {
                Collection<GroupType> gt = new ArrayList<GroupType>(spec.getGroupTypes());
                if (spec.isIncludeBuiltInGroups()) {
                    if (!spec.isIncludeAnonymousGroups()) {
                        gt.remove(GroupType.ANONYMOUS);
                    }
                } else {
                    gt.removeAll(GroupType.getBuiltInTypes());
                }
                if (spec.isIncludeUserGroups()) {
                    gt.add(GroupType.USER);
                }
                crit.add(Restrictions.in("type", GroupType.getIntegerValues(gt)));
            } else {
                Collection<GroupType> notGroupType = new ArrayList<GroupType>();
                if (!spec.isIncludeBuiltInGroups()) {
                    notGroupType.addAll(GroupType.getBuiltInTypes());
                    if (spec.isIncludeAnonymousGroups()) {
                        notGroupType.remove(GroupType.ANONYMOUS);
                    }
                }
                if (!spec.isIncludeUserGroups()) {
                    notGroupType.add(GroupType.USER);
                }
                if (!spec.isIncludeAnonymousGroups() && !notGroupType.contains(GroupType.ANONYMOUS)) {
                    notGroupType.add(GroupType.ANONYMOUS);
                }
                crit.add(Restrictions.not(Restrictions.in("type", GroupType.getIntegerValues(notGroupType))));
            }

            crit.setFirstResult(spec.getIndex());
            List list = crit.list();
            if (spec.getCount() == null) {
                return list;
            } else {
                return list.subList(0, Math.min(spec.getCount(), list.size()));
            }
        }
    });
}

From source file:com.ephesoft.dcma.da.dao.BatchClassEmailConfigDaoImpl.java

License:Open Source License

/**
 * An api to get all the batch class email configs.
 * //from www  .  j a v  a  2  s . co  m
 * @return List<BatchClassEmailConfiguration>
 */
@Override
public List<BatchClassEmailConfiguration> getAllEmailConfigs() {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return find(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassCmisConfigDaoImpl.java

License:Open Source License

/**
 * An api to get all the batch class cmis configs.
 * //w w  w  . j a  va2s .c  o m
 * @return List<BatchClassCmisConfiguration>
 */
@Override
public List<BatchClassCmisConfiguration> getAllCmisConfigs() {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return find(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java

License:Open Source License

/**
 * An api to fetch BatchClass by batch Class name.
 * /*from   ww  w.ja  v a  2  s.  c o m*/
 * @param batchClassName {@link String}
 * @return {@link BatchClass}
 */
@Override
public BatchClass getBatchClassbyName(final String batchClassName) {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.eq(NAME, batchClassName));
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return this.findSingle(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java

License:Open Source License

/**
 * An api to fetch BatchClass by batch Class processName.
 * //from  ww w . j  a v a 2s  .c om
 * @param processName {@link String}
 * @return {@link BatchClass}
 */
@Override
public BatchClass getBatchClassbyProcessName(final String processName) {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.eq(PROCESS_NAME, processName));
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return this.findSingle(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java

License:Open Source License

/**
 * This API will fetch all the unlocked batch classes.
 * /*from w  ww.jav a2s  .  c o  m*/
 * @return List<BatchClass>
 */
@Override
public List<BatchClass> getAllUnlockedBatchClasses() {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.isNull(CURRENT_USER));
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return this.find(criteria);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchClassDaoImpl.java

License:Open Source License

/**
 * To get Batch Class by Identifier.//from  ww w.  j a  v  a 2 s.c o  m
 * @param batchClassIdentifier String
 * @return BatchClass
 */
@Override
public BatchClass getBatchClassByIdentifier(final String batchClassIdentifier) {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.eq(IDENTIFIER, batchClassIdentifier));
    criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
    return this.findSingle(criteria);
}