Example usage for org.hibernate FetchMode JOIN

List of usage examples for org.hibernate FetchMode JOIN

Introduction

In this page you can find the example usage for org.hibernate FetchMode JOIN.

Prototype

FetchMode JOIN

To view the source code for org.hibernate FetchMode JOIN.

Click Source Link

Document

Fetch using an outer join.

Usage

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

License:Apache License

public List<DataStorePE> listDataStores() {
    final Criteria criteria = getSession().createCriteria(ENTITY_CLASS);
    criteria.add(Restrictions.eq("databaseInstance", getDatabaseInstance()));
    criteria.setFetchMode("servicesInternal", FetchMode.JOIN);
    criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
    final List<DataStorePE> list = cast(criteria.list());
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%d data stores have been found.", list.size()));
    }//from  w  w  w . ja va 2  s .  c  o m
    return list;
}

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

License:Apache License

public final <T extends EntityTypePE> List<T> listEntityTypes() throws DataAccessException {
    final DetachedCriteria criteria = DetachedCriteria.forClass(getEntityClass());
    criteria.add(Restrictions.eq("databaseInstance", getDatabaseInstance()));
    final String entityKindName = entityKind.name().toLowerCase();
    criteria.setFetchMode(entityKindName + "TypePropertyTypesInternal", FetchMode.JOIN);
    criteria.setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY);
    final List<T> list = cast(getHibernateTemplate().findByCriteria(criteria));
    return list;//from  w  w  w.  j  a  v a  2s.  co  m
}

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));
    }/*from w  w  w. j  a  v a2s .com*/
    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.ExperimentDAO.java

License:Apache License

public ExperimentPE tryFindByCodeAndProject(final ProjectPE project, final String experimentCode) {
    assert experimentCode != null : "Unspecified experiment code.";
    assert project != null : "Unspecified project.";

    final Criteria criteria = getSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("code", CodeConverter.tryToDatabase(experimentCode)));
    criteria.add(Restrictions.eq("projectInternal", project));
    criteria.setFetchMode("experimentType.experimentTypePropertyTypesInternal", FetchMode.JOIN);
    final ExperimentPE experiment = (ExperimentPE) criteria.uniqueResult();
    if (operationLog.isDebugEnabled()) {
        operationLog/*  ww  w .  j  a  v a  2 s. c o  m*/
                .debug(String.format("Following experiment '%s' has been found for code '%s' and project '%s'.",
                        experiment, experimentCode, project));
    }
    return experiment;
}

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);//from w ww  .  j av a2s  . 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.MaterialDAO.java

License:Apache License

public List<MaterialPE> listMaterialsWithPropertiesAndInhibitor(final MaterialTypePE materialType)
        throws DataAccessException {
    assert materialType != null : "Unspecified material type.";

    final Criteria criteria = getSession().createCriteria(ENTITY_CLASS);
    criteria.add(Restrictions.eq("materialType", materialType));
    final int count = DAOUtils.getCount(criteria);
    if (count <= DAOUtils.MAX_COUNT_FOR_PROPERTIES) {
        criteria.setFetchMode("materialProperties", FetchMode.JOIN);
    } else {/* ww  w  .j  a v  a  2s. c om*/
        operationLog.info(String.format("Found %d materials, disable properties loading.", count));
    }
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    final List<MaterialPE> list = cast(criteria.list());
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%d materials have been found for material type '%s'.", list.size(),
                materialType));
    }
    return list;
}

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

License:Apache License

public MaterialPE tryFindMaterial(MaterialIdentifier identifier) {
    assert identifier != null : "identifier not given";

    String code = CodeConverter.tryToDatabase(identifier.getCode());
    String typeCode = CodeConverter.tryToDatabase(identifier.getTypeCode());

    final Criteria criteria = getSession().createCriteria(ENTITY_CLASS);
    criteria.add(Restrictions.eq("code", code));
    criteria.createCriteria("materialType").add(Restrictions.eq("code", typeCode));
    criteria.setFetchMode("materialType.materialTypePropertyTypesInternal", FetchMode.JOIN);
    final MaterialPE material = (MaterialPE) criteria.uniqueResult();
    if (operationLog.isDebugEnabled()) {
        operationLog//from  w ww  . j av  a  2s  . c  o m
                .debug(String.format("Following material '%s' has been found for " + "code '%s' and type '%s'.",
                        material, code, typeCode));
    }
    return material;
}

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

License:Apache License

public List<PropertyTypePE> listAllPropertyTypesWithRelations() {
    final Criteria criteria = getSession().createCriteria(PropertyTypePE.class);
    criteria.add(Restrictions.eq("databaseInstance", getDatabaseInstance()));
    criteria.setFetchMode("materialTypePropertyTypesInternal", FetchMode.JOIN);
    criteria.setFetchMode("sampleTypePropertyTypesInternal", FetchMode.JOIN);
    criteria.setFetchMode("experimentTypePropertyTypesInternal", FetchMode.JOIN);
    criteria.setFetchMode("dataSetTypePropertyTypesInternal", FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    final List<PropertyTypePE> list = cast(criteria.list());
    if (operationLog.isDebugEnabled()) {
        operationLog.debug(String.format("%s(): %d property types(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), list.size()));
    }/*from w w w . jav  a  2  s  . c om*/
    return list;
}

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

License:Apache License

private final Criteria createListSampleForTypeCriteria(final SampleTypePE sampleType) {
    final Criteria criteria = createListAllSamplesCriteria();
    criteria.add(Restrictions.eq("sampleType", sampleType));
    fetchRelations(criteria, "container", sampleType.getContainerHierarchyDepth());
    fetchRelations(criteria, "generatedFrom", sampleType.getGeneratedFromHierarchyDepth());

    criteria.setFetchMode("experimentInternal", FetchMode.JOIN);

    return criteria;
}

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

License:Apache License

private final void fetchRelations(final Criteria criteria, final String relationName, final int relationDepth) {
    String relationPath = relationName;
    for (int i = 0; i < relationDepth; i++) {
        criteria.setFetchMode(relationPath, FetchMode.JOIN);
        relationPath += "." + relationName;
    }/*from   w w  w.j  av  a 2 s .  co m*/
}