Example usage for org.hibernate.criterion DetachedCriteria forClass

List of usage examples for org.hibernate.criterion DetachedCriteria forClass

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forClass.

Prototype

public static DetachedCriteria forClass(Class clazz) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity, by its Class.

Usage

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.ExperimentDAO.java

License:Apache License

public List<ExperimentPE> listExperimentsWithProperties(final ExperimentTypePE experimentTypeOrNull,
        final ProjectPE project) throws DataAccessException {
    assert project != null : "Unspecified project.";

    final DetachedCriteria criteria = DetachedCriteria.forClass(getEntityClass());
    if (experimentTypeOrNull != null) {
        criteria.add(Restrictions.eq("experimentType", experimentTypeOrNull));
    }/* ww  w.  j av a 2s .c om*/
    criteria.add(Restrictions.eq("projectInternal", project));
    criteria.setFetchMode("experimentProperties", FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    final List<ExperimentPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%d experiments have been found for project '%s'%s.", list.size(),
                project,
                (experimentTypeOrNull == null) ? "" : " and experiment type '" + experimentTypeOrNull + "'"));
    }
    return list;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.ExternalDataDAO.java

License:Apache License

public boolean hasExternalData(SamplePE sample) throws DataAccessException {
    final DetachedCriteria criteria = DetachedCriteria.forClass(ExternalDataPE.class);
    criteria.add(Restrictions.eq("sampleInternal", sample));
    criteria.setProjection(Projections.rowCount());
    Integer count = (Integer) getHibernateTemplate().findByCriteria(criteria).get(0);
    return count > 0;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.ExternalDataDAO.java

License:Apache License

public final List<ExternalDataPE> listExternalData(final DataStorePE dataStore) throws DataAccessException {
    assert dataStore != null : "Unspecified data store.";
    final DetachedCriteria criteria = DetachedCriteria.forClass(ExternalDataPE.class);
    criteria.add(Restrictions.eq("dataStore", dataStore));
    final List<ExternalDataPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s(%s): %d data set(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), dataStore, list.size()));
    }/*  www. ja  va 2 s .  c  o  m*/
    return list;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.ExternalDataDAO.java

License:Apache License

public ExternalDataPE tryToFindFullDataSetByCode(String dataSetCode, boolean withPropertyTypes) {
    assert dataSetCode != null : "Unspecified data set code";

    final String mangledCode = CodeConverter.tryToDatabase(dataSetCode);
    final Criterion codeEq = Restrictions.eq("code", mangledCode);

    final DetachedCriteria criteria = DetachedCriteria.forClass(ENTITY_CLASS);
    criteria.add(codeEq);//w ww  . j  a v  a2  s . c  o  m
    if (withPropertyTypes) {
        criteria.setFetchMode("dataSetType.dataSetTypePropertyTypesInternal", FetchMode.JOIN);
    }
    criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
    final List<ExternalDataPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    final ExternalDataPE entity = tryFindEntity(list, "data set");
    if (operationLog.isDebugEnabled()) {
        operationLog
                .debug(String.format("External data '%s' found for data set code '%s'.", entity, dataSetCode));
    }
    return entity;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.FilterDAO.java

License:Apache License

public List<FilterPE> listFilters(String gridId) {
    assert gridId != null : "Unspecified grid ID.";

    final DetachedCriteria criteria = DetachedCriteria.forClass(getEntityClass());
    criteria.add(Restrictions.eq("databaseInstance", getDatabaseInstance()));
    criteria.add(Restrictions.eq("gridId", gridId));
    final List<FilterPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s(%s): %d filters(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), gridId, list.size()));
    }/*from ww w  .  j  av a 2s  . co m*/
    return list;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.GroupDAO.java

License:Apache License

public final List<GroupPE> listGroups(final DatabaseInstancePE databaseInstance) throws DataAccessException {
    assert databaseInstance != null : "Unspecified database instance.";

    final DetachedCriteria criteria = DetachedCriteria.forClass(getEntityClass());
    criteria.add(Restrictions.eq("databaseInstance", databaseInstance));
    final List<GroupPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s(%s): %d group(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), databaseInstance, list.size()));
    }/*from w ww. j  a v  a2s. c o  m*/
    return list;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.PermIdDAO.java

License:Apache License

public IEntityInformationHolderDTO tryToFindByPermId(String permId, EntityKind entityKind) {
    assert permId != null : "Unspecified permId";
    final DetachedCriteria criteria = DetachedCriteria.forClass(entityKind.getEntityClass());
    criteria.add(Restrictions.eq("permId", permId));
    final List<IEntityInformationHolderDTO> list = cast(getHibernateTemplate().findByCriteria(criteria));
    final IEntityInformationHolderDTO entity = tryFindEntity(list, entityKind.name());
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s '%s' found for permId '%s'.", entityKind.name(), entity, permId));
    }/*from   w w w .j  a va2  s.  c o  m*/
    return entity;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.ProjectDAO.java

License:Apache License

public List<ProjectPE> listProjects(final GroupPE group) {
    assert group != null : "Unspecified group.";

    final DetachedCriteria criteria = DetachedCriteria.forClass(ProjectPE.class);
    criteria.add(Restrictions.eq("group", group));
    final List<ProjectPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s(%s): %d project(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), group, list.size()));
    }// w w w .  j a  va 2  s  .  c o m
    return list;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.RoleAssignmentDAO.java

License:Apache License

public final List<RoleAssignmentPE> listRoleAssignmentsByPerson(final PersonPE person) {
    assert person != null : "Unspecified person.";

    final DetachedCriteria criteria = DetachedCriteria.forClass(ENTITY_CLASS);
    criteria.add(Restrictions.eq("personInternal", person));
    final List<RoleAssignmentPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s(%s): %d role assignment(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), person, list.size()));
    }//from   www.jav  a  2  s .com
    return list;
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleTypeDAO.java

License:Apache License

public final List<SampleTypePE> listSampleTypes() throws DataAccessException {
    final DetachedCriteria criteria = DetachedCriteria.forClass(getEntityClass());
    criteria.add(Restrictions.eq("databaseInstance", getDatabaseInstance()));
    criteria.setFetchMode("sampleTypePropertyTypesInternal", FetchMode.JOIN);
    criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
    final List<SampleTypePE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s: %d sample type(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), list.size()));
    }/*from   w w w .ja  va 2 s .co  m*/
    return list;
}