Example usage for org.hibernate Query setLockOptions

List of usage examples for org.hibernate Query setLockOptions

Introduction

In this page you can find the example usage for org.hibernate Query setLockOptions.

Prototype

Query<R> setLockOptions(LockOptions lockOptions);

Source Link

Document

Set the lock options for the query.

Usage

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final int maxResults,
        final QueryType type) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }//from  w w w .j a v  a2s .c  o m
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final int maxResults,
        final QueryType type, final Object... params) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }//www. ja  va  2  s  .  c  om
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    applyParameters(query, params);
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final int maxResults,
        final QueryType type, final NamedParam... params) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }//w  w w . j  a va 2s.c  o  m
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    applyParameters(query, params);
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final boolean cacheable,
        final int maxResults, final QueryType type) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }//ww w. ja  v  a 2 s .  c o  m
    query.setCacheable(cacheable);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final boolean cacheable,
        final int maxResults, final QueryType type, final Object... params) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }//from ww  w.j ava  2 s.c om
    query.setCacheable(cacheable);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    applyParameters(query, params);
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final boolean cacheable,
        final int maxResults, final QueryType type, final NamedParam... params) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }/*  w  w  w.  j ava 2  s .co m*/
    query.setCacheable(cacheable);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    applyParameters(query, params);
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final QueryType type) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }/*w  w w.j av  a 2s .c om*/
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final QueryType type,
        final Object... params) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }/*from   ww  w  .  j a va2s . c o  m*/
    applyParameters(query, params);
    return query;
}

From source file:ch.algotrader.dao.AbstractDao.java

License:Open Source License

protected Query prepareQuery(final LockOptions lockOptions, final String queryString, final QueryType type,
        final NamedParam... params) {

    Query query = createQuery(queryString, type);
    if (lockOptions != null) {
        query.setLockOptions(lockOptions);
    }/*from w  w  w . j  a  v  a  2s.  com*/
    applyParameters(query, params);
    return query;
}

From source file:com.evolveum.midpoint.repo.sql.helpers.ObjectRetriever.java

License:Apache License

public <T extends ObjectType> PrismObject<T> getObjectInternal(Session session, Class<T> type, String oid,
        Collection<SelectorOptions<GetOperationOptions>> options, boolean lockForUpdate,
        OperationResult operationResult)
        throws ObjectNotFoundException, SchemaException, DtoTranslationException {

    boolean lockedForUpdateViaHibernate = false;
    boolean lockedForUpdateViaSql = false;

    LockOptions lockOptions = new LockOptions();
    //todo fix lock for update!!!!!
    if (lockForUpdate) {
        if (getConfiguration().isLockForUpdateViaHibernate()) {
            lockOptions.setLockMode(LockMode.PESSIMISTIC_WRITE);
            lockedForUpdateViaHibernate = true;
        } else if (getConfiguration().isLockForUpdateViaSql()) {
            LOGGER.trace("Trying to lock object {} for update (via SQL)", oid);
            long time = System.currentTimeMillis();
            SQLQuery q = session.createSQLQuery("select oid from m_object where oid = ? for update");
            q.setString(0, oid);//from   w  ww .  j ava 2  s  .  com
            Object result = q.uniqueResult();
            if (result == null) {
                return throwObjectNotFoundException(type, oid);
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Locked via SQL (in {} ms)", System.currentTimeMillis() - time);
            }
            lockedForUpdateViaSql = true;
        }
    }

    if (LOGGER.isTraceEnabled()) {
        if (lockedForUpdateViaHibernate) {
            LOGGER.trace("Getting object {} with locking for update (via hibernate)", oid);
        } else if (lockedForUpdateViaSql) {
            LOGGER.trace("Getting object {}, already locked for update (via SQL)", oid);
        } else {
            LOGGER.trace("Getting object {} without locking for update", oid);
        }
    }

    GetObjectResult fullObject = null;
    if (!lockForUpdate) {
        Query query = session.getNamedQuery("get.object");
        query.setString("oid", oid);
        query.setResultTransformer(GetObjectResult.RESULT_TRANSFORMER);
        query.setLockOptions(lockOptions);

        fullObject = (GetObjectResult) query.uniqueResult();
    } else {
        // we're doing update after this get, therefore we load full object right now
        // (it would be loaded during merge anyway)
        // this just loads object to hibernate session, probably will be removed later. Merge after this get
        // will be faster. Read and use object only from fullObject column.
        // todo remove this later [lazyman]
        Criteria criteria = session.createCriteria(ClassMapper.getHQLTypeClass(type));
        criteria.add(Restrictions.eq("oid", oid));

        criteria.setLockMode(lockOptions.getLockMode());
        RObject obj = (RObject) criteria.uniqueResult();

        if (obj != null) {
            obj.toJAXB(prismContext, null).asPrismObject();
            fullObject = new GetObjectResult(obj.getFullObject(), obj.getStringsCount(), obj.getLongsCount(),
                    obj.getDatesCount(), obj.getReferencesCount(), obj.getPolysCount(), obj.getBooleansCount());
        }
    }

    LOGGER.trace("Got it.");
    if (fullObject == null) {
        throwObjectNotFoundException(type, oid);
    }

    LOGGER.trace("Transforming data to JAXB type.");
    PrismObject<T> prismObject = updateLoadedObject(fullObject, type, oid, options, session, operationResult);
    validateObjectType(prismObject, type);

    // this was implemented to allow report parsing errors as warnings to upper layers;
    // however, it causes problems when serialization problems are encountered: in such cases, we put
    // FATAL_ERROR to the result here, and it should be then removed or muted (which is a complication)
    // -- so, as the parsing errors are not implemented, we disabled this code as well

    //         subResult.computeStatusIfUnknown();
    //         if (subResult.isWarning() || subResult.isError() || subResult.isInProgress()) {
    //            prismObject.asObjectable().setFetchResult(subResult.createOperationResultType());
    //         }

    return prismObject;
}