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(Object object, LockMode lockMode);

Source Link

Document

Obtain the specified lock level upon the given object.

Usage

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

License:Apache License

public void update(final Object entity, final LockMode lockMode) throws DataAccessException {
    execute(new CombinedHibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException {
            checkWriteOperationAllowed(session);
            session.update(entity);//from  ww w .  j  a v  a 2s .c  om
            if (lockMode != null) {
                session.lock(entity, lockMode);
            }
            return null;
        }

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

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

License:Apache License

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

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

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

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

License:Apache License

public void delete(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(entity, lockMode);
            }/*from   www.  j a v  a 2s. c om*/
            session.delete(entity);
            return null;
        }

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