Example usage for org.hibernate LockMode UPGRADE

List of usage examples for org.hibernate LockMode UPGRADE

Introduction

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

Prototype

LockMode UPGRADE

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

Click Source Link

Document

An upgrade lock.

Usage

From source file:org.openehealth.ipf.commons.flow.repository.SequenceRepositoryImpl.java

License:Apache License

private FlowNumber lockNumber() {
    return (FlowNumber) getHibernateTemplate().get(FlowNumber.class, DEFAULT_SEQUENCE, LockMode.UPGRADE);
}

From source file:org.opentaps.foundation.entity.hibernate.OpentapsIdentifierGenerator.java

License:Open Source License

/**
 * Returns the select query by database dialect.
 * @param dialect a <code>Dialect</code>
 * @return the <code>String</code> query string.
 *//*from  ww  w .  j a v a  2s  .  c  om*/
protected String buildSelectQuery(Dialect dialect) {
    final String alias = "tbl";
    String query = "select " + StringHelper.qualify(alias, SEQUENCE_VALUE_COLUMN) + " from "
            + SEQUENCE_TABLE_NAME + ' ' + alias + " where " + StringHelper.qualify(alias, SEQUENCE_TYPE_COLUMN)
            + "=?";
    HashMap<String, LockMode> lockMap = new HashMap<String, LockMode>();
    lockMap.put(alias, LockMode.UPGRADE);
    Map<String, String[]> updateTargetColumnsMap = Collections.singletonMap(alias,
            new String[] { SEQUENCE_VALUE_COLUMN });
    return dialect.applyLocksToSql(query, lockMap, updateTargetColumnsMap);
}

From source file:org.photovault.persistence.GenericHibernateDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public T findById(ID id, boolean lock) {
    T entity;//from  w w w.j a va 2 s  .  c o  m
    if (lock)
        entity = (T) getSession().load(getPersistentClass(), id, LockMode.UPGRADE);
    else
        entity = (T) getSession().load(getPersistentClass(), id);
    return entity;
}

From source file:org.seasar.hibernate3.dao.impl.LoadCommand.java

License:Apache License

public void setLockMode(String lockMode) {
    final String NONE = "NONE";
    final String READ = "READ";
    final String UPGRADE = "UPGRADE";

    if (lockMode.equals(NONE)) {
        lockMode_ = LockMode.NONE;/*  w ww  .  j  a  v  a 2s.  c o  m*/

    } else if (lockMode.equals(READ)) {
        lockMode_ = LockMode.READ;

    } else if (lockMode.equals(UPGRADE)) {
        lockMode_ = LockMode.UPGRADE;

    } else {
        lockMode_ = null;
    }
}

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

License:Apache License

@Test
public void testLoadWithLockMode() throws HibernateException {
    TestBean tb = new TestBean();
    given(session.load(TestBean.class, "", LockMode.UPGRADE)).willReturn(tb);
    Object result = hibernateTemplate.load(TestBean.class, "", LockMode.UPGRADE);
    assertTrue("Correct result", result == tb);
    verify(session).flush();//  ww w  . j  a  va 2  s  .c o m
    verify(session).close();
}

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

License:Apache License

@Test
public void testLoadWithEntityNameLockMode() throws HibernateException {
    TestBean tb = new TestBean();
    given(session.load("myEntity", "", LockMode.UPGRADE)).willReturn(tb);
    Object result = hibernateTemplate.load("myEntity", "", LockMode.UPGRADE);
    assertTrue("Correct result", result == tb);
    verify(session).flush();//from  ww  w .  ja  v a2 s. c  om
    verify(session).close();
}

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

License:Apache License

@Test
public void testUpdateWithLockMode() throws HibernateException {
    TestBean tb = new TestBean();
    given(session.getFlushMode()).willReturn(FlushMode.AUTO);
    hibernateTemplate.update(tb, LockMode.UPGRADE);
    verify(session).update(tb);//from ww w .  ja v  a 2 s. c  om
    verify(session).lock(tb, LockMode.UPGRADE);
    verify(session).flush();
    verify(session).close();
}

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

License:Apache License

@Test
public void testUpdateWithEntityNameAndLockMode() throws HibernateException {
    TestBean tb = new TestBean();
    given(session.getFlushMode()).willReturn(FlushMode.AUTO);
    hibernateTemplate.update("myEntity", tb, LockMode.UPGRADE);
    verify(session).update("myEntity", tb);
    verify(session).lock(tb, LockMode.UPGRADE);
    verify(session).flush();/*w w w  .jav a2 s .c om*/
    verify(session).close();
}

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

License:Apache License

@Test
public void testDeleteWithLockMode() throws HibernateException {
    TestBean tb = new TestBean();
    given(session.getFlushMode()).willReturn(FlushMode.AUTO);
    hibernateTemplate.delete(tb, LockMode.UPGRADE);
    verify(session).lock(tb, LockMode.UPGRADE);
    verify(session).delete(tb);/* www  . j  a va  2 s. c  o  m*/
    verify(session).flush();
    verify(session).close();
}

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

License:Apache License

@Test
public void testDeleteWithEntityNameAndLockMode() throws HibernateException {
    TestBean tb = new TestBean();
    given(session.getFlushMode()).willReturn(FlushMode.AUTO);
    hibernateTemplate.delete("myEntity", tb, LockMode.UPGRADE);
    verify(session).lock("myEntity", tb, LockMode.UPGRADE);
    verify(session).delete("myEntity", tb);
    verify(session).flush();// w  w  w. j a  v a  2s.c om
    verify(session).close();
}