Example usage for org.hibernate Session lock

List of usage examples for org.hibernate Session lock

Introduction

In this page you can find the example usage for org.hibernate Session lock.

Prototype

void lock(String entityName, Object object, LockMode lockMode);

Source Link

Document

Obtain the specified lock level upon the given object.

Usage

From source file:com.jdon.persistence.hibernate.HibernateTemplate.java

License:Apache License

public void lock(final String entityName, final Object entity, final LockMode lockMode) throws Exception {

    doHibernate(new HibernateCallback() {
        public Object execute(Session session) throws HibernateException {
            session.lock(entityName, entity, lockMode);
            return null;
        }/*from w ww. j  a v  a 2s.  c o m*/
    });
}

From source file:org.opengoss.dao.hibernate.DataAccessor.java

License:Apache License

public void lock(final String entityName, final Object entity, final LockMode lockMode) throws DaoException {

    execute(new IAccessorCallback() {
        public Object call(Session session) throws HibernateException {
            session.lock(entityName, entity, lockMode);
            return null;
        }/*from www . j a  v a 2s  .com*/
    });
}

From source file:org.springframework.orm.hibernate3.HibernateTemplate.java

License:Apache License

@Override
public void lock(final String entityName, final Object entity, final LockMode lockMode)
        throws DataAccessException {

    executeWithNativeSession(new HibernateCallback<Object>() {
        @Override/*from w  ww . j  a v a  2  s  .com*/
        public Object doInHibernate(Session session) throws HibernateException {
            session.lock(entityName, entity, lockMode);
            return null;
        }
    });
}

From source file:org.springframework.orm.hibernate3.HibernateTemplate.java

License:Apache License

@Override
public void delete(final String entityName, final Object entity, final LockMode lockMode)
        throws DataAccessException {

    executeWithNativeSession(new HibernateCallback<Object>() {
        @Override/*from w w  w.j  a va 2  s.c om*/
        public Object doInHibernate(Session session) throws HibernateException {
            checkWriteOperationAllowed(session);
            if (lockMode != null) {
                session.lock(entityName, entity, lockMode);
            }
            session.delete(entityName, entity);
            return null;
        }
    });
}

From source file:org.springframework.orm.hibernate3.StatelessHibernateTemplate.java

License:Apache License

public void lock(final String entityName, final Object entity, final LockMode lockMode)
        throws DataAccessException {

    execute(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            session.lock(entityName, entity, lockMode);
            return null;
        }//  w w  w. ja  v  a2  s . c om
    }, true);
}

From source file:org.springframework.orm.hibernate3.StatelessHibernateTemplate.java

License:Apache License

public void delete(final String entityName, final Object entity, final LockMode lockMode)
        throws DataAccessException {

    execute(new CombinedHibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            checkWriteOperationAllowed(session);
            if (lockMode != null) {
                session.lock(entityName, entity, lockMode);
            }/*from   w w  w  .j a  v a 2 s .  c  o  m*/
            session.delete(entityName, entity);
            return null;
        }

        public Object doInHibernate(StatelessSession session) throws HibernateException {
            if (lockMode != null) {
                throw new IllegalStateException("Locking not supported for StatelessSession");
            }
            session.delete(entityName, entity);
            return null;
        }
    }, true);
}