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:eu.jangos.realm.controller.characters.CharacterService.java

License:Apache License

/**
 * Indicates whether the account given in parameter has characters already
 * created in the opposite faction.//from w w w  .  j a  va2 s  .  c  o m
 *
 * @param account The account for which it needs to be checked.
 * @param faction The faction for which this account is trying to create a
 * character.
 * @return True if the account has already created characters in the enemy
 * faction.
 */
private boolean hasCharacterInEnemyFaction(Account account, FactionEnum faction) {
    try (Session session = HibernateUtil.getCharSession().openSession()) {
        Disjunction or = Restrictions.disjunction();
        for (RaceEnum race : FactionEnum.getRacesForFactions(faction)) {
            or.add(Restrictions.eq("race", race.getValue()));
        }

        return (((long) session.createCriteria(Characters.class)
                .add(Restrictions.and(Restrictions.isNull("deleted"),
                        Restrictions.eq("fkAccount", account.getId()), or))
                .setProjection(Projections.rowCount()).uniqueResult()) != 0);

    } catch (HibernateException he) {
        return false;
    }
}

From source file:eu.jangos.realm.controller.characters.CharacterService.java

License:Apache License

/**
 * Return whether the name is already in use in database.
 *
 * @param name The name to be checked./*from w w w.  ja  v a 2 s.c o m*/
 * @return True if the name is already in use.
 */
private boolean nameInUse(String name) {
    if (name == null || name.isEmpty()) {
        logger.debug("Name parameter is empty, exiting. exist = false.");
        return false;
    }

    try (Session session = HibernateUtil.getCharSession().openSession()) {
        Characters character = (Characters) session.createCriteria(Characters.class)
                .add(Restrictions.and(Restrictions.isNull("deleted"), Restrictions.like("name", name)))
                .uniqueResult();
        logger.debug("The character " + name + " is found.");
        return (character != null);
    } catch (HibernateException he) {
        logger.error("The character " + name + " doesn't exist, exiting.");
        return true;
    }
}

From source file:flexmud.engine.context.ClientContextHandler.java

License:Open Source License

public void loadAndSetFirstContext() {
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Context.class);
    detachedCriteria.add(Restrictions.isNull(Context.PARENT_GROUP_PROPERTY));
    List<Context> contexts = (List<Context>) HibernateUtil.fetch(detachedCriteria);

    Context firstContext;/* w ww  . j a  v a 2  s  .c o  m*/
    if (contexts != null && !contexts.isEmpty()) {
        firstContext = contexts.get(0);
        firstContext.init();
        setContext(firstContext);
    } else {
        setContext(null);
    }
}

From source file:fr.gael.dhus.database.dao.MetadataDefinitionDao.java

License:Open Source License

private synchronized MetadataDefinition find(String name, String category, String type, String queryable) {
    MetadataDefinition result = getHibernateTemplate().execute((Session session) -> {
        Criteria criteria = session.createCriteria(MetadataDefinition.class);

        Criterion categoryRestriction = (category == null) ? Restrictions.isNull(CATEGORY)
                : Restrictions.eq(CATEGORY, category);
        criteria.add(categoryRestriction);

        Criterion nameRestriction = (name == null) ? Restrictions.isNull(NAME) : Restrictions.eq(NAME, name);
        criteria.add(nameRestriction);/*from  w  w  w  .  j  a v  a  2  s. c o m*/

        Criterion typeRestriction = (type == null) ? Restrictions.isNull(TYPE) : Restrictions.eq(TYPE, type);
        criteria.add(typeRestriction);

        Criterion queryableRestriction = (queryable == null) ? Restrictions.isNull(QUERYABLE)
                : Restrictions.eq(QUERYABLE, queryable);
        criteria.add(queryableRestriction);

        return (MetadataDefinition) criteria.uniqueResult();
    });
    return result;
}

From source file:fr.mcc.ginco.dao.hibernate.ThesaurusArrayDAO.java

License:CeCILL license

@Override
public List<ThesaurusArray> getArraysWithoutSuperordinatedConcept(String thesaurusId) {
    Criteria criteria = getCurrentSession().createCriteria(ThesaurusArray.class, "ta");
    criteria.add(Restrictions.isNull("ta.superOrdinateConcept"));
    selectThesaurus(criteria, thesaurusId);
    return criteria.list();
}

From source file:fr.mcc.ginco.dao.hibernate.ThesaurusArrayDAO.java

License:CeCILL license

@Override
public List<ThesaurusArray> getArraysWithoutParentArray(String thesaurusId) {
    Criteria criteria = getCurrentSession().createCriteria(ThesaurusArray.class, "ta");
    criteria.add(Restrictions.isNull("ta.parent.identifier"));
    selectThesaurus(criteria, thesaurusId);
    return criteria.list();
}

From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java

License:CeCILL license

private void selectNoParents(Criteria criteria) {
    criteria.add(Restrictions.or(Restrictions.isNull("tc.parentConcepts"),
            Restrictions.isEmpty("tc.parentConcepts")));
}

From source file:fr.mcc.ginco.dao.hibernate.ThesaurusTermDAO.java

License:CeCILL license

/**
 * This method constructs a criteria to get sandboxed terms
 * @param criteria/*from  w ww.  jav a  2 s .c  om*/
 * @param startIndex
 * @param limit
 * @param idThesaurus
 */
private void getSandboxedTerms(Criteria criteria, Integer startIndex, Integer limit, String idThesaurus) {
    criteria.setMaxResults(limit).add(Restrictions.eq(THESAURUS_IDENTIFIER, idThesaurus))
            .add(Restrictions.isNull(CONCEPT)).setFirstResult(startIndex).addOrder(Order.asc(LEXICAL_VALUE));
}

From source file:fr.mcc.ginco.dao.hibernate.ThesaurusTermDAO.java

License:CeCILL license

/**
 * This method constructs a criteria to count sandboxed terms
 * @param criteria/*from  w  ww. java2  s.  co  m*/
 * @param idThesaurus
 */
private void countAllSandboxedTerms(Criteria criteria, String idThesaurus) {
    criteria.add(Restrictions.eq(THESAURUS_IDENTIFIER, idThesaurus)).add(Restrictions.isNull(CONCEPT))
            .setProjection(Projections.rowCount());
}

From source file:gov.nih.nci.caarray.dao.FileDaoImpl.java

License:BSD License

/**
 * {@inheritDoc}//w  w  w .j av  a2s .c  o m
 */
@Override
@SuppressWarnings({ "unchecked", "PMD" })
public List<CaArrayFile> searchFiles(PageSortParams<CaArrayFile> params, FileSearchCriteria criteria) {
    final Criteria c = getCurrentSession().createCriteria(CaArrayFile.class);

    if (criteria.getExperiment() != null) {
        c.add(Restrictions.eq("project", criteria.getExperiment().getProject()));
    }

    if (!criteria.getTypes().isEmpty()) {
        c.add(Restrictions.in("type",
                Sets.newHashSet(FileTypeRegistryImpl.namesForTypes(criteria.getTypes()))));
    }

    if (criteria.getExtension() != null) {
        String extension = criteria.getExtension();
        if (!extension.startsWith(".")) {
            extension = "." + extension;
        }
        c.add(Restrictions.ilike("name", "%" + extension));
    }

    if (!criteria.getCategories().isEmpty()) {
        final Disjunction categoryCriterion = Restrictions.disjunction();
        if (criteria.getCategories().contains(FileCategory.DERIVED_DATA)) {
            categoryCriterion.add(Restrictions.in("type", Sets.newHashSet(
                    FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getDerivedArrayDataTypes()))));
        }
        if (criteria.getCategories().contains(FileCategory.RAW_DATA)) {
            categoryCriterion.add(Restrictions.in("type", Sets
                    .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getRawArrayDataTypes()))));
        }
        if (criteria.getCategories().contains(FileCategory.MAGE_TAB)) {
            categoryCriterion.add(Restrictions.in("type",
                    Sets.newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getMageTabTypes()))));
        }
        if (criteria.getCategories().contains(FileCategory.ARRAY_DESIGN)) {
            categoryCriterion.add(Restrictions.in("type", Sets
                    .newHashSet(FileTypeRegistryImpl.namesForTypes(this.typeRegistry.getArrayDesignTypes()))));
        }
        if (criteria.getCategories().contains(FileCategory.OTHER)) {
            categoryCriterion.add(Restrictions.isNull("type"));
        }
        c.add(categoryCriterion);
    }

    if (!criteria.getExperimentNodes().isEmpty()) {
        final Collection<Long> fileIds = new LinkedList<Long>();
        for (final AbstractExperimentDesignNode node : criteria.getExperimentNodes()) {
            for (final CaArrayFile f : node.getAllDataFiles()) {
                fileIds.add(f.getId());
            }
        }
        if (!fileIds.isEmpty()) {
            c.add(Restrictions.in("id", fileIds));
        } else {
            return Collections.emptyList();
        }
    }

    c.setFirstResult(params.getIndex());
    if (params.getPageSize() > 0) {
        c.setMaxResults(params.getPageSize());
    }
    c.addOrder(toOrder(params));

    return c.list();
}