Example usage for org.hibernate.dialect Dialect appendLockHint

List of usage examples for org.hibernate.dialect Dialect appendLockHint

Introduction

In this page you can find the example usage for org.hibernate.dialect Dialect appendLockHint.

Prototype

public String appendLockHint(LockOptions lockOptions, String tableName) 

Source Link

Document

Some dialects support an alternative means to SELECT FOR UPDATE, whereby a "lock hint" is appends to the table name in the from clause.

Usage

From source file:com.farmafene.commons.hibernate.generators.WorkInOther.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  w  w  .  j a  v  a  2s.c  o m*/
 * 
 * @since 1.0.0
 */
private String getSelectQuery(Dialect dialect) {
    StringBuilder sb = new StringBuilder("SELECT ")
            .append(campos.getTarget().getAnnotation(Column.class).name());
    sb.append(" FROM ");
    sb.append(dialect.appendLockHint(LockMode.UPGRADE, db.getNombreSecuencia()));
    writeWhereParameters(null, sb, campos.getLista());
    sb.append(dialect.getForUpdateString());
    return sb.toString();
}

From source file:com.literatejava.hibernate.allocator.LinearBlockAllocator.java

License:Open Source License

public void configure(Type type, Properties params, Dialect dialect) {
    ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get(IDENTIFIER_NORMALIZER);

    this.tableName = ConfigurationHelper.getString(ALLOC_TABLE, params, DEFAULT_TABLE);
    this.sequenceColumn = ConfigurationHelper.getString(SEQUENCE_COLUMN, params, DEFAULT_SEQUENCE_COLUMN);
    this.allocColumn = ConfigurationHelper.getString(ALLOC_COLUMN, params, DEFAULT_ALLOC_COLUMN);

    // get SequenceName;    default to Entities' TableName.
    //      -/*from   w ww. j av  a  2  s .c o  m*/
    this.sequenceName = ConfigurationHelper.getString(SEQUENCE_NAME, params,
            params.getProperty(PersistentIdentifierGenerator.TABLE));
    if (sequenceName == null) {
        throw new IdentifierGenerationException(
                "LinearBlockAllocator: '" + SEQUENCE_NAME + "' must be specified");
    }

    this.blockSize = ConfigurationHelper.getInt(BLOCK_SIZE, params, DEFAULT_BLOCK_SIZE);
    if (blockSize < 1) {
        blockSize = 1;
    }

    // qualify Table Name, if necessary;
    //      --
    if (tableName.indexOf('.') < 0) {
        String schemaName = normalizer.normalizeIdentifierQuoting(params.getProperty(SCHEMA));
        String catalogName = normalizer.normalizeIdentifierQuoting(params.getProperty(CATALOG));
        this.tableName = Table.qualify(catalogName, schemaName, tableName);
    }

    // build SQL strings;
    //      -- use appendLockHint(LockMode) for now, as that is how Hibernate's generators do it.
    //
    this.query = "select " + allocColumn + " from "
            + dialect.appendLockHint(LockMode.PESSIMISTIC_WRITE, tableName) + " where " + sequenceColumn
            + " = ?" + dialect.getForUpdateString();
    this.update = "update " + tableName + " set " + allocColumn + " = ? where " + sequenceColumn + " = ? and "
            + allocColumn + " = ?";

    // setup Return Type & Result Holder.
    //      --
    this.returnType = type;
    this.returnClass = type.getReturnedClass();
    this.resultFactory = IdentifierGeneratorHelper.getIntegralDataTypeHolder(returnClass);

    // done.
}

From source file:org.hyperic.hibernate.id.HQMultipleHiLoPerTableGenerator.java

License:Open Source License

public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
    tableName = PropertiesHelper.getString(ID_TABLE, params, DEFAULT_TABLE);
    pkColumnName = PropertiesHelper.getString(PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN);
    valueColumnName = PropertiesHelper.getString(VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN);
    initialHi = PropertiesHelper.getInt(INITIAL_HI, params, DEFAULT_INITIAL_HI);
    String schemaName = params.getProperty(SCHEMA);
    String catalogName = params.getProperty(CATALOG);
    keySize = PropertiesHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH);
    keyValue = PropertiesHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE));

    if (tableName.indexOf('.') < 0) {
        tableName = Table.qualify(catalogName, schemaName, tableName);
    }//from   w  w  w.  j a  v a  2 s  .c o m

    query = "select " + valueColumnName + " from " + dialect.appendLockHint(LockMode.UPGRADE, tableName)
            + " where " + pkColumnName + " = '" + keyValue + "'" + dialect.getForUpdateString();

    update = "update " + tableName + " set " + valueColumnName + " = ? where " + valueColumnName + " = ? and "
            + pkColumnName + " = '" + keyValue + "'";

    insert = "insert into " + tableName + "(" + pkColumnName + ", " + valueColumnName + ") " + "values('"
            + keyValue + "', ?)";

    // hilo config
    maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE);
    lo = maxLo + 1; // so we "clock over" on the first invocation
    returnClass = type.getReturnedClass();

}

From source file:org.intelligentsia.utility.generator.TableGenerator.java

License:Apache License

public void configure(final DataSource dataSource, final Dialect dialect, final String tableName,
        final String keyValue, final long initialValue) {
    this.tableName = tableName;
    this.dataSource = dataSource;
    insert = new StringBuilder("INSERT into ").append(tableName).append(" values ('").append(keyValue)
            .append("', ").append(initialValue).append(")").toString();
    query = new StringBuilder("select NEXT_VAL from ")
            .append(dialect.appendLockHint(new LockOptions(LockMode.PESSIMISTIC_WRITE), tableName))
            .append(" where VAL_ID='").append(keyValue).append("' ").append(dialect.getForUpdateString())
            .toString();//from  w w  w.j ava2  s.  c o  m
    update = new StringBuilder("update ").append(tableName).append(" set NEXT_VAL=? WHERE VAL_ID='")
            .append(keyValue).append("' AND NEXT_VAL=?").toString();
}

From source file:org.jboss.ejb3.entity.JTATableIdGenerator.java

License:Open Source License

public void configure(Type type, Properties params, Dialect dialect) {
    this.tableName = PropertiesHelper.getString(TABLE, params, DEFAULT_TABLE_NAME);
    this.columnName = PropertiesHelper.getString(COLUMN, params, DEFAULT_COLUMN_NAME);
    this.allocationSize = PropertiesHelper.getInt(ALLOCATION_SIZE, params, DEFAULT_ALLOCATION_SIZE);
    String schemaName = params.getProperty(SCHEMA);
    String catalogName = params.getProperty(CATALOG);

    if (true)//  www. j  ava2  s  .  c  om
        throw new RuntimeException("DOES ANYBODY USE THIS?  It IS CURRENTLY BROKEN");

    /*
    getSchemaSeparator does not exist in hibernate anymore since 3.1 release
            
    // prepare table name
    if (tableName.indexOf(dialect.getSchemaSeparator()) < 0)
    {
       tableName = Table.qualify(catalogName, schemaName, tableName, dialect.getSchemaSeparator());
    }
    */

    // prepare SQL statements
    query = "select " + columnName + " from " + dialect.appendLockHint(LockMode.UPGRADE, tableName)
            + dialect.getForUpdateString();
    update = "update " + tableName + " set " + columnName + " = ? where " + columnName + " = ?";

    // set up transaction manager lookup
    // only JBoss transaction manager is supported
    transactionManagerLookup = new JBossTransactionManagerLookup();

    // set the sequence type that should be returned
    returnClass = type.getReturnedClass();

    // debug chosen configuration
    if (log.isDebugEnabled()) {
        log.debug("configuring id generator: " + this.getClass().getName());
        log.debug("tableName=" + tableName);
        log.debug("columnName=" + columnName);
        log.debug("allocationSize=" + allocationSize);
        log.debug("query=" + query);
        log.debug("update=" + update);
        log.debug("returnClass=" + returnClass);
    }
}