Example usage for org.hibernate LockMode PESSIMISTIC_READ

List of usage examples for org.hibernate LockMode PESSIMISTIC_READ

Introduction

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

Prototype

LockMode PESSIMISTIC_READ

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

Click Source Link

Document

Implemented as PESSIMISTIC_WRITE.

Usage

From source file:de.innovationgate.webgate.api.jdbc.filehandling.CS5P4FileAttachmentHandler.java

License:Open Source License

@Override
protected CS5P4FileAttachmentEntity fetchFileAttachmentEntity(String strFile)
        throws WGAPIException, HibernateException {

    // We cannot query if the entity is transient
    if (((MainEntity) _entity).getCreated() == null) {
        return null;
    }/*from   w  w w.  j a v  a2  s  .c om*/

    String hqlQuery = "select cfm from " + _entityDescriptor.getHQLFileMetaEntity() + " cfm where cfm."
            + _entityDescriptor.getHQLFileMetaParentProperty() + "=:entity and cfm.name=:name";
    Query query = _handling.getParent().getSession().createQuery(hqlQuery);
    query.setLockMode("cfm", LockMode.PESSIMISTIC_READ);
    query.setParameter("entity", _entity);
    query.setParameter("name", strFile);

    Iterator<?> it = query.iterate();
    if (it.hasNext()) {
        return (CS5P4FileAttachmentEntity) it.next();
    } else {
        return null;
    }

}

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

License:Apache License

/**
 * Borrowed from org.hibernate.ejb.util.LockModeTypeHelper
 * @param lockMode//from w w  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.geoserver.taskmanager.data.impl.TaskManagerDaoImpl.java

License:Open Source License

@Override
public Run getCurrentRun(final Task task) {
    return (Run) (getSession().createCriteria(RunImpl.class).setLockMode(LockMode.PESSIMISTIC_READ)
            .createAlias("batchElement", "batchElement").createAlias("batchElement.task", "task")
            .add(Restrictions.eq("task.id", task.getId())).add(Restrictions.isNull("end"))).uniqueResult();
}

From source file:org.geoserver.taskmanager.data.impl.TaskManagerDaoImpl.java

License:Open Source License

@Override
public Run getCommittingRun(final Task task) {
    return (Run) (getSession().createCriteria(RunImpl.class).setLockMode(LockMode.PESSIMISTIC_READ)
            .createAlias("batchElement", "batchElement").createAlias("batchElement.task", "task")
            .add(Restrictions.eq("task.id", task.getId())).add(Restrictions.isNotNull("end"))
            .add(Restrictions.eq("status", Run.Status.COMMITTING))).uniqueResult();
}