Example usage for org.hibernate Query setLockMode

List of usage examples for org.hibernate Query setLockMode

Introduction

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

Prototype

Query<R> setLockMode(String alias, LockMode lockMode);

Source Link

Document

Set the LockMode to use for specific alias (as defined in the query's FROM clause).

Usage

From source file:foundation.ETimeRecordNLDAO.java

public static java.util.Iterator iterateETimeRecordNLByQuery(PersistentSession session, String condition,
        String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
    StringBuffer sb = new StringBuffer("From foundation.ETimeRecordNL as ETimeRecordNL");
    if (condition != null)
        sb.append(" Where ").append(condition);
    if (orderBy != null)
        sb.append(" Order By ").append(orderBy);
    try {/*from   w w  w. ja  v a  2 s .  c  o m*/
        Query query = session.createQuery(sb.toString());
        query.setLockMode("this", lockMode);
        return query.iterate();
    } catch (Exception e) {
        e.printStackTrace();
        throw new PersistentException(e);
    }
}

From source file:gov.nih.nci.caarray.dao.SearchDaoImpl.java

License:BSD License

/**
 * {@inheritDoc}//from  ww  w  . j  a  v a2 s.c om
 */
@SuppressWarnings(UNCHECKED)
public <T extends PersistentObject> T retrieve(Class<T> entityClass, Long entityId, LockMode lockMode) {
    Query q = getCurrentSession().createQuery("from " + entityClass.getName() + " o where o.id = :id");
    q.setLong("id", entityId);
    q.setLockMode("o", lockMode);
    return (T) q.uniqueResult();
}

From source file:hibernate.Class1.java

public static List queryClass1(PersistentSession session, String condition, String orderBy,
        org.hibernate.LockMode lockMode) throws PersistentException {
    StringBuffer sb = new StringBuffer("From hibernate.Class1 as Class1");
    if (condition != null)
        sb.append(" Where ").append(condition);
    if (orderBy != null)
        sb.append(" Order By ").append(orderBy);
    try {//www . j  ava  2  s. c  o m
        Query query = session.createQuery(sb.toString());
        query.setLockMode("this", lockMode);
        return query.list();
    } catch (Exception e) {
        e.printStackTrace();
        throw new PersistentException(e);
    }
}

From source file:hibernate.Class1.java

public static java.util.Iterator iterateClass1ByQuery(PersistentSession session, String condition,
        String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
    StringBuffer sb = new StringBuffer("From hibernate.Class1 as Class1");
    if (condition != null)
        sb.append(" Where ").append(condition);
    if (orderBy != null)
        sb.append(" Order By ").append(orderBy);
    try {//from   w w  w .j a  v  a 2s.  c om
        Query query = session.createQuery(sb.toString());
        query.setLockMode("this", lockMode);
        return query.iterate();
    } catch (Exception e) {
        e.printStackTrace();
        throw new PersistentException(e);
    }
}

From source file:itensil.repository.hibernate.RepositoryEntity.java

License:Open Source License

/**
 *
 * @param uri/* w  w w . j  a v a  2s  . com*/
 * @return node object
 * @throws AccessDeniedException
 * @throws NotFoundException
 */
public MutableRepositoryNode getNodeByUri(String uri, boolean forUpdate)
        throws AccessDeniedException, NotFoundException {

    User caller = SecurityAssociation.getUser();
    authorizedCheck(caller);

    String localUri = localizeUri(uri);

    Session session = HibernateUtil.getSession();
    Query qry = session.getNamedQuery("Repo.getNodeByUri");
    qry.setEntity("repo", this);
    qry.setString("uri", localUri);
    if (forUpdate)
        qry.setLockMode("node", LockMode.UPGRADE);
    NodeEntity node = (NodeEntity) qry.uniqueResult();
    if (node == null) {
        if (!existingAncestorBlock(caller, localUri)) {
            throw new NotFoundException(uri);
        } else {
            throw new AccessDeniedException(uri, "read");
        }
    }
    if (!hasPermission(caller, node, DefaultNodePermission.READ)) {
        throw new AccessDeniedException(uri, "read");
    }
    node.setRepoEntity(this);
    return node;
}

From source file:itensil.repository.hibernate.RepositoryEntity.java

License:Open Source License

/**
 *
 * @param nodeId/* w  w w .j  ava 2s . c om*/
 * @return node object
 * @throws AccessDeniedException
 * @throws NotFoundException
 */
public MutableRepositoryNode getNode(String nodeId, boolean forUpdate)
        throws AccessDeniedException, NotFoundException {

    User caller = SecurityAssociation.getUser();
    authorizedCheck(caller);
    Session session = HibernateUtil.getSession();

    Query qry = session.getNamedQuery("Repo.getNode");
    qry.setString("id", nodeId);
    qry.setEntity("repo", this);
    if (forUpdate)
        qry.setLockMode("node", LockMode.UPGRADE);

    NodeEntity node = (NodeEntity) qry.uniqueResult();

    if (node == null) {
        throw new NotFoundException(nodeId);
    }
    if (!hasPermission(caller, node, DefaultNodePermission.READ)) {
        throw new AccessDeniedException(nodeId, "read");
    }
    node.setRepoEntity(this);
    return node;
}

From source file:ma.massarpro.dao.impl.Absence_retardDAOImpl.java

public Absence_retard[] listAbsence_retardByQuery(PersistentSession session, String condition, String orderBy,
        org.hibernate.LockMode lockMode) {
    StringBuffer sb = new StringBuffer("From ma.massarpro.beans.Absence_retard as Absence_retard");
    if (condition != null)
        sb.append(" Where ").append(condition);
    if (orderBy != null)
        sb.append(" Order By ").append(orderBy);
    try {//from  w w w .  j ava  2s  . c  o  m
        Query query = session.createQuery(sb.toString());
        query.setLockMode("this", lockMode);
        List list = query.list();
        return (Absence_retard[]) list.toArray(new Absence_retard[list.size()]);
    } catch (Exception e) {
        _logger.error("listAbsence_retardByQuery(PersistentSession session, String condition, String orderBy)",
                e);
        throw new RuntimeException(e);
    }
}

From source file:ma.massarpro.dao.impl.Absence_retardDAOImpl.java

public static java.util.Iterator iterateAbsence_retardByQuery(PersistentSession session, String condition,
        String orderBy, org.hibernate.LockMode lockMode) {
    StringBuffer sb = new StringBuffer("From ma.massarpro.beans.Absence_retard as Absence_retard");
    if (condition != null)
        sb.append(" Where ").append(condition);
    if (orderBy != null)
        sb.append(" Order By ").append(orderBy);
    try {// w  w  w.j  a va 2s.c o  m
        Query query = session.createQuery(sb.toString());
        query.setLockMode("this", lockMode);
        return query.iterate();
    } catch (Exception e) {
        _logger.error(
                "iterateAbsence_retardByQuery(PersistentSession session, String condition, String orderBy)", e);
        throw new RuntimeException(e);
    }
}

From source file:ma.massarpro.dao.impl.AdministrateurDAOImpl.java

public Administrateur[] listAdministrateurByQuery(PersistentSession session, String condition, String orderBy,
        org.hibernate.LockMode lockMode) {
    StringBuffer sb = new StringBuffer("From ma.massarpro.beans.Administrateur as Administrateur");
    if (condition != null)
        sb.append(" Where ").append(condition);
    if (orderBy != null)
        sb.append(" Order By ").append(orderBy);
    try {// w  ww .ja va  2  s. c om
        Query query = session.createQuery(sb.toString());
        query.setLockMode("this", lockMode);
        List list = query.list();
        return (Administrateur[]) list.toArray(new Administrateur[list.size()]);
    } catch (Exception e) {
        _logger.error("listAdministrateurByQuery(PersistentSession session, String condition, String orderBy)",
                e);
        throw new RuntimeException(e);
    }
}

From source file:ma.massarpro.dao.impl.AdministrateurDAOImpl.java

public static java.util.Iterator iterateAdministrateurByQuery(PersistentSession session, String condition,
        String orderBy, org.hibernate.LockMode lockMode) {
    StringBuffer sb = new StringBuffer("From ma.massarpro.beans.Administrateur as Administrateur");
    if (condition != null)
        sb.append(" Where ").append(condition);
    if (orderBy != null)
        sb.append(" Order By ").append(orderBy);
    try {/* ww  w  .j  av a2  s  .  co  m*/
        Query query = session.createQuery(sb.toString());
        query.setLockMode("this", lockMode);
        return query.iterate();
    } catch (Exception e) {
        _logger.error(
                "iterateAdministrateurByQuery(PersistentSession session, String condition, String orderBy)", e);
        throw new RuntimeException(e);
    }
}