Example usage for org.hibernate.id.enhanced OptimizerFactory buildOptimizer

List of usage examples for org.hibernate.id.enhanced OptimizerFactory buildOptimizer

Introduction

In this page you can find the example usage for org.hibernate.id.enhanced OptimizerFactory buildOptimizer.

Prototype

@Deprecated
public static Optimizer buildOptimizer(String type, Class returnClass, int incrementSize) 

Source Link

Document

Builds an optimizer

Usage

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

License:Open Source License

/**
 * Configure this instance, given the value of parameters
 * specified by the user as <tt>&lt;param&gt;</tt> elements.
 * This method is called just once, following instantiation.
 *
 * @param type the identifier type, such as GenericGenerator
 * @param params param values, keyed by parameter name
 * @param dialect database dialect//  w w w  .  j  a v  a 2s . c  o m
 * @throws MappingException if an error occurs
 */
public void configure(Type type, Properties params, Dialect dialect) throws MappingException {
    identifierType = type;
    // retrieve entity name, like org.opentaps.base.entities.TestEntity
    String entityName = params.getProperty("entity_name");
    String targetColumn = params.getProperty("target_column");
    idField = ModelUtil.dbNameToVarName(targetColumn);
    // get entity short name, like TestEntity
    sequenceType = entityName.substring(entityName.lastIndexOf(".") + 1);
    // get sequence query, for get current value of sequence
    this.selectQuery = buildSelectQuery(dialect);
    // update sequence query, for update sequence value = value + 1
    this.updateQuery = buildUpdateQuery();
    // insert sequence query, if not exist sequence in sequence table, then will use this sql to insert a record.
    this.insertQuery = buildInsertQuery();

    String defOptStrategy = incrementSize <= 1 ? OptimizerFactory.NONE : OptimizerFactory.POOL;
    //get optimization strategy
    String optimizationStrategy = PropertiesHelper.getString(OPT_PARAM, params, defOptStrategy);
    optimizer = OptimizerFactory.buildOptimizer(optimizationStrategy, Long.class, incrementSize);
}