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:edu.wisc.my.portlets.bookmarks.dao.hibernate.HibernateBookmarkStore.java

License:Apache License

/**
 * There are two different Criterion for if a property is null or checking equality. This is a
 * convience method to return the one based on if value is null or not.
 *//*  w w w.  j a  v  a  2  s  .  c o  m*/
private Criterion smartEqual(String property, Object value) {
    if (value == null) {
        return Restrictions.isNull(property);
    } else {
        return Restrictions.eq(property, value);
    }
}

From source file:edu.wustl.geneconnect.bizlogic.ResultProcessor.java

License:BSD License

/**
 * Create new DetachedCriteria from old one excluding confidence and frequency
 * @return//from   w w  w.java 2  s  .c o m
 * @throws Exception
 */
public DetachedCriteria createNewCriteria() throws Exception {
    /**
     * Create root DetachedCriteria for GenomicIdentifierSet
     */
    DetachedCriteria genomicIdSetCriteria = DetachedCriteria.forClass(GenomicIdentifierSet.class);
    //System.out.println("caCore deprepnputDsList.size() :  " + inputDsList.size());
    Map addedAssociation = new HashMap();
    for (int i = 0; i < selectedInputValueList.size(); i++) {
        String predicate = (String) selectedInputValueList.get(i);
        int ind = predicate.indexOf("=");
        String dsName = predicate.substring(0, ind);

        String dsValue = predicate.substring(ind + 1, predicate.length());

        // Get Class of data source i.e Gene,MRNA or Protein
        String className = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, dsName,
                Constants.CLASS);

        String roleName = MetadataManager.getRoleName("GenomicIdentifierSet", className);

        // get attribute name of Gene.MRNA or protein representing data source 
        String classAttribute = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, dsName,
                Constants.ATTRIBUTE);
        // get type of attribute
        String attributeType = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, dsName,
                Constants.TYPE);

        log.info("Adding " + roleName + ":" + classAttribute);
        /**
         * Create DetachedCriteria for search on given datasource and its genomicId
         */
        /**
         * Check if Criteria already created.IF yed teh get teh DetachedCriteria object from Map
         * else crete new DetachedCriteria 
         */
        DetachedCriteria genomicCriteria = (DetachedCriteria) addedAssociation.get(roleName);
        if (genomicCriteria == null) {
            genomicCriteria = genomicIdSetCriteria.createCriteria(roleName);
            addedAssociation.put(roleName, genomicCriteria);
        }
        if (attributeType.equalsIgnoreCase("java.lang.Long")) {
            Long longValue = null;
            try {
                longValue = new Long(dsValue);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new Exception("Genomic Identifier for DataSource " + dsName + " must be Integer");
            }
            genomicCriteria.add(Restrictions.eq(classAttribute, longValue));
        } else {
            genomicCriteria.add(Restrictions.eq(classAttribute, dsValue));
        }
    }

    for (int j = 0; j < selectedOutputDataSourceList.size(); j++) {
        String outputDSName = (String) selectedOutputDataSourceList.get(j);
        String outputClassName = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, outputDSName,
                Constants.CLASS);
        String roleName = MetadataManager.getRoleName("GenomicIdentifierSet", outputClassName);
        DetachedCriteria outputGenomicCriteria = (DetachedCriteria) addedAssociation.get(roleName);
        if (outputGenomicCriteria == null) {
            outputGenomicCriteria = genomicIdSetCriteria.createCriteria(roleName);
            addedAssociation.put(roleName, outputGenomicCriteria);
        }

        String outputAttribute = MetadataManager.getDataSourceAttribute(Constants.DATASOURCE_NAME, outputDSName,
                Constants.OUTPUT_ATTRIBUTE);
        log.info("Adding " + roleName + ":" + outputAttribute);
        outputGenomicCriteria.add(Restrictions.eq(outputAttribute, new Boolean(true)));
    }
    Map currentNode = new HashMap();

    if (ontList.size() > 0) {
        DetachedCriteria ontCrit = genomicIdSetCriteria.createCriteria("orderOfNodeTraversalCollection");
        currentNode.put(CURRENT_NODE, ontCrit);
    }
    for (int i = 0; i < ontList.size(); i++) {

        DetachedCriteria ontCrit = (DetachedCriteria) currentNode.get(CURRENT_NODE);
        GCCriteria f = (GCCriteria) ontList.get(i);
        String ds = f.getDataSource();
        List type = f.getType();
        String linkType = null;
        if (type.size() > 0)
            linkType = (String) type.get(0);
        ontCrit.createCriteria("sourceDataSource").add(Restrictions.eq("name", ds));
        log.info("Adding ONT ds " + ds);
        DetachedCriteria ontCritF1 = null;
        if (linkType != null) {
            ontCrit.createCriteria("linkType").add(Restrictions.eq("type", linkType));
            ontCritF1 = ontCrit.createCriteria("childOrderOfNodeTraversal");
            currentNode.remove(CURRENT_NODE);
            currentNode.put(CURRENT_NODE, ontCritF1);
            log.info("Adding ONT link " + linkType);
        } else {
            ontCrit.add(Restrictions.isNull("childOrderOfNodeTraversal"));
            log.info("Adding ISNULL next ");
        }
    }
    return genomicIdSetCriteria;
}

From source file:ee.ria.xroad.opmonitordaemon.OperationalDataRecordManager.java

License:Open Source License

private static Criterion getMemberCriterion(ClientId member, boolean isClient) {
    return Restrictions.and(
            Restrictions.eq(isClient ? CLIENT_XROAD_INSTANCE : SERVICE_XROAD_INSTANCE,
                    member.getXRoadInstance()),
            Restrictions.eq(isClient ? CLIENT_MEMBER_CLASS : SERVICE_MEMBER_CLASS, member.getMemberClass()),
            Restrictions.eq(isClient ? CLIENT_MEMBER_CODE : SERVICE_MEMBER_CODE, member.getMemberCode()),
            member.getSubsystemCode() == null
                    ? Restrictions.isNull(isClient ? CLIENT_SUBSYSTEM_CODE : SERVICE_SUBSYSTEM_CODE)
                    : Restrictions.eq(isClient ? CLIENT_SUBSYSTEM_CODE : SERVICE_SUBSYSTEM_CODE,
                            member.getSubsystemCode()));
}

From source file:ee.ria.xroad.proxy.messagelog.LogRecordManager.java

License:Open Source License

private Criteria createRecordCriteria(Session session, String queryId, ClientId clientId, boolean isResponse) {
    Criteria criteria = session.createCriteria(MessageRecord.class);
    criteria.add(Restrictions.eq("queryId", queryId));
    criteria.add(Restrictions.eq("memberClass", clientId.getMemberClass()));
    criteria.add(Restrictions.eq("memberCode", clientId.getMemberCode()));
    String subsystemCode = clientId.getSubsystemCode();
    criteria.add(subsystemCode == null ? Restrictions.isNull("subsystemCode")
            : Restrictions.eq("subsystemCode", subsystemCode));
    criteria.add(Restrictions.eq("response", isResponse));
    return criteria;
}

From source file:es.emergya.bbdd.dao.RecursoHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
public Recurso[] getNotAsigned(Patrulla p) {
    Recurso[] res = new Recurso[0];
    try {/*from  w ww  . j  av a  2 s  . c  o  m*/
        if (p == null || p.getId() == null) {
            return getByFilter(filter).toArray(new Recurso[0]);
        }
        log.debug("getNotAsigned(" + p.getId() + ")");
        Session currentSession = getSession();
        currentSession.clear();
        Criterion rhs = Restrictions.isNull("patrullas");
        Criterion lhs = Restrictions.ne("patrullas", currentSession.load(Patrulla.class, p.getId()));
        Criteria criteria = currentSession.createCriteria(Recurso.class)
                .add(Restrictions.eq("habilitado", true)).add(Restrictions.or(lhs, rhs));
        criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]);

        for (Recurso r : res)
            try {
                r.getPatrullas().getId();
            } catch (Throwable t) {
            }

    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

From source file:es.emergya.bbdd.dao.RecursoHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Recurso[] getNotAsigned(Flota p) {
    Recurso[] res = new Recurso[0];
    if (p == null || p.getId() == null) {
        return getByFilter(new Recurso()).toArray(new Recurso[0]);
    }//  w  w w  .  j  ava 2s  .  co m
    try {
        log.debug("getNotAsigned(" + p.getId() + ")");
        Session currentSession = getSession();
        currentSession.clear();
        Criterion rhs = Restrictions.isNull("flotas");
        Criterion lhs = Restrictions.ne("flotas", currentSession.load(Patrulla.class, p.getId()));
        Criteria criteria = currentSession.createCriteria(Recurso.class).add(Restrictions.or(lhs, rhs));
        criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]);

        for (Recurso r : res)
            try {
                r.getFlotas().getId();
            } catch (Throwable t) {
            }
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

From source file:es.sm2.openppm.core.dao.CompanyDAO.java

License:Open Source License

/**
 * Find active companies//from   w  w  w .j  a va 2s .  c o  m
 * 
 * @return
 */
@SuppressWarnings("unchecked")
public List<Company> findActives() {

    Criteria crit = getSession().createCriteria(getPersistentClass()).add(Restrictions.disjunction()
            .add(Restrictions.eq(Company.DISABLE, Boolean.FALSE)).add(Restrictions.isNull(Company.DISABLE)));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.ContactDAO.java

License:Open Source License

/**
 * Search Contacts by filter/*from  w  w  w  . java2  s .c  om*/
 * @param resourcepools
  * @param fullName
  * @param fileAs
  * @param performingorg
  * @param company
  * @param skills
  *@param jobcategories @return
 */
@SuppressWarnings("unchecked")
public List<Contact> searchByFilter(String fullName, String fileAs, Performingorg performingorg,
        Company company, List<Resourcepool> resourcepools, List<Skill> skills,
        List<Jobcategory> jobcategories) {

    Contact example = new Contact();
    example.setFileAs(fileAs);
    example.setFullName(fullName);

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .add(Example.create(example).ignoreCase().enableLike(MatchMode.ANYWHERE))
            .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true)));

    // Company
    //
    crit.createCriteria(Contact.COMPANY).add(Restrictions.idEq(company.getIdCompany()))
            .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

    // Employee
    Criteria critEmployee = crit.createCriteria(Contact.EMPLOYEES, CriteriaSpecification.LEFT_JOIN);

    if (performingorg != null && performingorg.getIdPerfOrg() != null && performingorg.getIdPerfOrg() != -1) {

        critEmployee.createCriteria(Employee.PERFORMINGORG)
                .add(Restrictions.idEq(performingorg.getIdPerfOrg()));
    }

    if (ValidateUtil.isNotNull(resourcepools)) {
        critEmployee.add(Restrictions.in(Employee.RESOURCEPOOL, resourcepools));
    }

    if (ValidateUtil.isNotNull(skills)) {
        critEmployee.createCriteria(Employee.SKILLSEMPLOYEES)
                .add(Restrictions.in(Skillsemployee.SKILL, skills));
    }

    if (ValidateUtil.isNotNull(jobcategories)) {
        critEmployee.createCriteria(Employee.JOBCATEMPLOYEES)
                .add(Restrictions.in(Jobcatemployee.JOBCATEGORY, jobcategories));
    }

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.ContactDAO.java

License:Open Source License

/**
 * Find owners LLAA//from w ww  .j  a v  a  2s . c om
 *
 * @param company
 * @return
 */
public List<Contact> findUsedInLLAA(Company company) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .add(Restrictions.eq(Contact.COMPANY, company))
            .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true)))
            .addOrder(Order.asc(Contact.FULLNAME));

    crit.createCriteria(Contact.LEARNEDLESSONS).add(Restrictions.eq(LearnedLesson.COMPANY, company));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.DocumentprojectDAO.java

License:Open Source License

/**
 * Find documents by type in the project
 * @param project/*from w  ww  . ja  v a2 s  . c o  m*/
 * @param type
 * @return
 */
@SuppressWarnings("unchecked")
public List<Documentproject> findListByType(Project project, String type, Boolean isFile) {

    List<Documentproject> list = null;

    // Filter by project
    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Documentproject.PROJECT, project));

    if (isFile) {
        crit.add(Restrictions.isNotNull(Documentproject.MIME));
    } else {
        crit.add(Restrictions.isNull(Documentproject.MIME));
    }

    // Filter by type
    if (type != null) {
        crit.add(Restrictions.eq(Documentproject.TYPE, type));
    } else {

        crit.add(Restrictions.disjunction()
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_INITIATING))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_RISK))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_PLANNING))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_CONTROL))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_PROCUREMENT))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_CLOSURE))
                .add(Restrictions.eq(Documentproject.TYPE, Constants.DOCUMENT_INVESTMENT)));
    }

    // Order
    crit.addOrder(Order.asc(Documentproject.TYPE));

    list = crit.list();
    return list;
}