Example usage for org.hibernate.dialect Dialect applyLocksToSql

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

Introduction

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

Prototype

public String applyLocksToSql(String sql, LockOptions aliasedLockOptions,
        Map<String, String[]> keyColumnNames) 

Source Link

Document

Modifies the given SQL by applying the appropriate updates for the specified lock modes and key columns.

Usage

From source file:net.e6tech.elements.persist.hibernate.ModifiedTableGenerator.java

License:Apache License

@SuppressWarnings("unchecked")
protected String buildSelectQuery(Dialect dialect) {
    final String alias = "tbl";
    final String query = "select " + StringHelper.qualify(alias, valueColumnName) + " from " + renderedTableName
            + ' ' + alias + " where " + StringHelper.qualify(alias, segmentColumnName) + "=?";
    final LockOptions lockOptions = new LockOptions(LockMode.PESSIMISTIC_WRITE);
    lockOptions.setAliasSpecificLockMode(alias, LockMode.PESSIMISTIC_WRITE);
    final Map updateTargetColumnsMap = Collections.singletonMap(alias, new String[] { valueColumnName });
    return dialect.applyLocksToSql(query, lockOptions, updateTargetColumnsMap);
}

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.
 *//*  w  w w  .  j  a  va2 s  .  co m*/
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);
}