Example usage for org.hibernate LockMode PESSIMISTIC_FORCE_INCREMENT

List of usage examples for org.hibernate LockMode PESSIMISTIC_FORCE_INCREMENT

Introduction

In this page you can find the example usage for org.hibernate LockMode PESSIMISTIC_FORCE_INCREMENT.

Prototype

LockMode PESSIMISTIC_FORCE_INCREMENT

To view the source code for org.hibernate LockMode PESSIMISTIC_FORCE_INCREMENT.

Click Source Link

Document

Transaction will immediately increment the entity version.

Usage

From source file:org.brekka.commons.persistence.dao.hibernate.AbstractIdentifiableEntityHibernateDAO.java

License:Apache License

/**
 * Borrowed from org.hibernate.ejb.util.LockModeTypeHelper
 * @param lockMode//ww  w  .ja v a2 s .  c  o  m
 * @return
 */
public static LockMode getLockMode(final LockModeType lockMode) {
    switch (lockMode) {
    case READ:
    case OPTIMISTIC: {
        return LockMode.OPTIMISTIC;
    }
    case OPTIMISTIC_FORCE_INCREMENT:
    case WRITE: {
        return LockMode.OPTIMISTIC_FORCE_INCREMENT;
    }
    case PESSIMISTIC_READ: {
        return LockMode.PESSIMISTIC_READ;
    }
    case PESSIMISTIC_WRITE: {
        return LockMode.PESSIMISTIC_WRITE;
    }
    case PESSIMISTIC_FORCE_INCREMENT: {
        return LockMode.PESSIMISTIC_FORCE_INCREMENT;
    }
    case NONE: {
        return LockMode.NONE;
    }
    default: {
        throw new IllegalStateException("Unknown LockModeType: " + lockMode);
    }
    }
}

From source file:org.obiba.opal.core.upgrade.v2_0_x.database.FixAttributeJoinTableUpgradeStep.java

License:Open Source License

@SuppressWarnings("unchecked")
private void touchValueTablesTimestamps(final Database database) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override/*from w  w  w.  ja  va  2s.  c  om*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            SessionFactory sessionFactory = databaseRegistry.getSessionFactory(database.getName(), null);
            Session currentSession = sessionFactory.getCurrentSession();
            for (ValueTableState table : (List<ValueTableState>) currentSession
                    .createCriteria(ValueTableState.class).list()) {
                log.debug("Touch {} last update", table.getName());
                currentSession.buildLockRequest(new LockOptions(LockMode.PESSIMISTIC_FORCE_INCREMENT))
                        .lock(table);
            }
        }
    });
}