Example usage for org.hibernate Criteria setReadOnly

List of usage examples for org.hibernate Criteria setReadOnly

Introduction

In this page you can find the example usage for org.hibernate Criteria setReadOnly.

Prototype

public Criteria setReadOnly(boolean readOnly);

Source Link

Document

Set the read-only/modifiable mode for entities and proxies loaded by this Criteria.

Usage

From source file:org.grails.orm.hibernate.GrailsHibernateTemplate.java

License:Apache License

/**
 * Prepare the given Criteria object, applying cache settings and/or a
 * transaction timeout.//from  w  ww .  java2  s . c  om
 *
 * @param criteria the Criteria object to prepare
 */
protected void prepareCriteria(Criteria criteria) {
    if (cacheQueries) {
        criteria.setCacheable(true);
    }
    if (shouldPassReadOnlyToHibernate()) {
        criteria.setReadOnly(true);
    }
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.getResource(sessionFactory);
    if (sessionHolder != null && sessionHolder.hasTimeout()) {
        criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
    }
}

From source file:org.n52.sos.ds.hibernate.dao.ObservationDAO.java

License:Open Source License

public ScrollableResults getNotMatchingSeries(Set<Long> procedureIds, Set<Long> observablePropertyIds,
        Set<Long> featureIds, GetObservationRequest request, Set<String> features,
        Criterion temporalFilterCriterion, Session session) throws OwsExceptionReport {
    Criteria c = getObservationCriteriaFor(request, features, temporalFilterCriterion, null, session);
    addAliasAndNotRestrictionFor(c, procedureIds, observablePropertyIds, featureIds);
    return c.setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
}

From source file:org.n52.sos.ds.hibernate.dao.ObservationDAO.java

License:Open Source License

public ScrollableResults getNotMatchingSeries(Set<Long> procedureIds, Set<Long> observablePropertyIds,
        Set<Long> featureIds, GetObservationRequest request, Set<String> features, Session session)
        throws OwsExceptionReport {
    Criteria c = getObservationCriteriaFor(request, features, null, null, session);
    addAliasAndNotRestrictionFor(c, procedureIds, observablePropertyIds, featureIds);
    return c.setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
}

From source file:org.n52.sos.ds.hibernate.dao.series.AbstractSeriesObservationDAO.java

License:Open Source License

public ScrollableResults getSeriesNotMatchingSeries(Set<Long> seriesIDs, GetObservationRequest request,
        Set<String> features, Criterion temporalFilterCriterion, Session session) throws OwsExceptionReport {
    Criteria c = getSeriesObservationCriteriaFor(request, features, temporalFilterCriterion, null, session)
            .createAlias(SeriesObservation.SERIES, "s");
    c.add(Restrictions.not(Restrictions.in("s." + Series.ID, seriesIDs)));
    c.setProjection(Projections.property(SeriesObservation.SERIES));
    return c.setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
}

From source file:org.n52.sos.ds.hibernate.dao.series.AbstractSeriesObservationDAO.java

License:Open Source License

public ScrollableResults getSeriesNotMatchingSeries(Set<Long> seriesIDs, GetObservationRequest request,
        Set<String> features, Session session) throws OwsExceptionReport {
    Criteria c = getSeriesObservationCriteriaFor(request, features, null, null, session)
            .createAlias(SeriesObservation.SERIES, "s");
    c.add(Restrictions.not(Restrictions.in("s." + Series.ID, seriesIDs)));
    return c.setReadOnly(true).scroll(ScrollMode.FORWARD_ONLY);
}

From source file:org.n52.sos.ds.hibernate.dao.series.AbstractSeriesValueDAO.java

License:Open Source License

/**
 * Get {@link Criteria} for parameter// w  ww.  j  a  v  a  2  s.c om
 * 
 * @param request
 *            {@link GetObservationRequest}
 * @param series
 *            Datasource series id
 * @param temporalFilterCriterion
 *            Temporal filter {@link Criterion}
 * @param session
 *            Hibernate Session
 * @return Resulting {@link Criteria}
 * @throws OwsExceptionReport
 *             If an error occurs when adding Spatial Filtering Profile
 *             restrictions
 */
private Criteria getSeriesValueCriteriaFor(GetObservationRequest request, long series,
        Criterion temporalFilterCriterion, Session session) throws OwsExceptionReport {
    final Criteria c = getDefaultObservationCriteria(session).createAlias(SeriesValue.SERIES, "s");

    checkAndAddSpatialFilteringProfileCriterion(c, request, session);

    c.add(Restrictions.eq("s." + Series.ID, series));

    if (CollectionHelper.isNotEmpty(request.getOfferings())) {
        c.createCriteria(SeriesValue.OFFERINGS)
                .add(Restrictions.in(Offering.IDENTIFIER, request.getOfferings()));
    }

    String logArgs = "request, series, offerings";
    if (temporalFilterCriterion != null) {
        logArgs += ", filterCriterion";
        c.add(temporalFilterCriterion);
    }
    addSpecificRestrictions(c, request);
    LOGGER.debug("QUERY getStreamingSeriesValuesFor({}): {}", logArgs, HibernateHelper.getSqlString(c));
    return c.setReadOnly(true);
}

From source file:org.n52.sos.ds.hibernate.dao.ValueDAO.java

License:Open Source License

/**
 * Get {@link Criteria} for parameter/*w ww.  j  av a  2s . c  o m*/
 * 
 * @param request
 *            {@link GetObservationRequest}
 * @param procedure
 *            Datasource procedure id
 * @param observableProperty
 *            Datasource procedure id
 * @param featureOfInterest
 *            Datasource procedure id
 * @param temporalFilterCriterion
 *            Temporal filter {@link Criterion}
 * @param session
 *            Hibernate Session
 * @return Resulting {@link Criteria}
 * @throws OwsExceptionReport
 *             If an error occurs when adding Spatial Filtering Profile
 *             restrictions
 */
private Criteria getValueCriteriaFor(GetObservationRequest request, long procedure, long observableProperty,
        long featureOfInterest, Criterion temporalFilterCriterion, Session session) throws OwsExceptionReport {
    final Criteria c = getDefaultObservationCriteria(ObservationValue.class, session)
            .createAlias(ObservationValue.PROCEDURE, "p").createAlias(ObservationValue.FEATURE_OF_INTEREST, "f")
            .createAlias(ObservationValue.OBSERVABLE_PROPERTY, "o");

    checkAndAddSpatialFilteringProfileCriterion(c, request, session);

    c.add(Restrictions.eq("p." + Procedure.ID, procedure));
    c.add(Restrictions.eq("o." + ObservableProperty.ID, observableProperty));
    c.add(Restrictions.eq("f." + FeatureOfInterest.ID, featureOfInterest));

    if (CollectionHelper.isNotEmpty(request.getOfferings())) {
        c.createCriteria(ObservationValue.OFFERINGS)
                .add(Restrictions.in(Offering.IDENTIFIER, request.getOfferings()));
    }

    String logArgs = "request, series, offerings";
    if (temporalFilterCriterion != null) {
        logArgs += ", filterCriterion";
        c.add(temporalFilterCriterion);
    }
    addSpecificRestrictions(c, request);
    LOGGER.debug("QUERY getStreamingValuesFor({}): {}", logArgs, HibernateHelper.getSqlString(c));
    return c.setReadOnly(true);
}

From source file:org.osiam.storage.dao.GetInternalIdSkeleton.java

License:Open Source License

protected <T> SCIMSearchResult<T> search(Class<T> clazz, String filter, int count, int startIndex,
        String sortBy, String sortOrder) {
    Session session = (Session) em.getDelegate();
    Criteria criteria = session.createCriteria(clazz);
    criteria.setReadOnly(true);
    criteria.setCacheMode(CacheMode.GET);
    criteria.setCacheable(true);/*from   ww  w. j  a va  2  s  .  com*/
    if (filter != null && !filter.isEmpty()) {
        criteria = criteria.add(filterParser.parse(filter).buildCriterion());
    }
    createAliasesForCriteria(criteria);
    criteria.setMaxResults(count);
    long totalResult = getTotalResults(criteria);
    setSortOrder(sortBy, sortOrder, criteria);
    criteria.setFirstResult(startIndex);
    Criteria criteria1 = criteria.setProjection(null).setResultTransformer(Criteria.ROOT_ENTITY);
    List list = criteria1.list();
    return new SCIMSearchResult(list, totalResult);
}

From source file:persist.StatusDAOHibernate.java

@Override
public List<Status> findAll() {
    Criteria criteria = sesion.createCriteria(Persona.class);
    criteria.setReadOnly(true);
    return criteria.list();
}

From source file:ubic.gemma.persistence.service.expression.bioAssayData.BioAssayDimensionDaoImpl.java

License:Apache License

@Override
public BioAssayDimension find(BioAssayDimension bioAssayDimension) {

    if (bioAssayDimension.getBioAssays().isEmpty()) {
        throw new IllegalArgumentException("BioAssayDimension had no BioAssays");
    }/*from  w  w  w .j  ava 2 s . c o m*/

    Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(BioAssayDimension.class);
    queryObject.setReadOnly(true);
    queryObject.setFlushMode(FlushMode.MANUAL);

    if (StringUtils.isNotBlank(bioAssayDimension.getName())) {
        queryObject.add(Restrictions.eq("name", bioAssayDimension.getName()));
    }

    if (StringUtils.isNotBlank(bioAssayDimension.getDescription())) {
        queryObject.add(Restrictions.eq("description", bioAssayDimension.getDescription()));
    }

    queryObject.add(Restrictions.sizeEq("bioAssays", bioAssayDimension.getBioAssays().size()));

    Collection<String> names = new HashSet<>();
    for (BioAssay bioAssay : bioAssayDimension.getBioAssays()) {
        names.add(bioAssay.getName());
    }
    queryObject.createCriteria("bioAssays").add(Restrictions.in("name", names));

    BioAssayDimension candidate = (BioAssayDimension) queryObject.uniqueResult();

    if (candidate == null)
        return null;

    // Now check that the bioassays and order are exactly the same.
    Collection<BioAssay> desiredBioAssays = bioAssayDimension.getBioAssays();
    Collection<BioAssay> candidateBioAssays = candidate.getBioAssays();

    assert desiredBioAssays.size() == candidateBioAssays.size();

    Iterator<BioAssay> dit = desiredBioAssays.iterator();
    Iterator<BioAssay> cit = candidateBioAssays.iterator();

    while (dit.hasNext()) {
        BioAssay d = dit.next();
        BioAssay c = cit.next();
        if (!c.equals(d))
            return null;
    }

    return candidate;

}