Example usage for org.hibernate.id.enhanced TableGenerator getInitialValue

List of usage examples for org.hibernate.id.enhanced TableGenerator getInitialValue

Introduction

In this page you can find the example usage for org.hibernate.id.enhanced TableGenerator getInitialValue.

Prototype

public final int getInitialValue() 

Source Link

Document

The initial value to use when we find no previous state in the generator table corresponding to our sequence.

Usage

From source file:de.innovationgate.webgate.api.jdbc.WGDatabaseImpl.java

License:Open Source License

private TableGenerator getTableGenerator(String seqName, Long startValue)
        throws InstantiationException, IllegalAccessException {

    TableGenerator tg = _generatorCache.get(seqName);
    if (tg != null && (startValue == null || startValue.equals(tg.getInitialValue()))) {
        return tg;
    }//from  ww w. ja v  a  2  s  .c  om

    Properties props = new Properties();
    props.put(TableGenerator.TABLE_PARAM, "cs_sequences");
    props.put(TableGenerator.SEGMENT_COLUMN_PARAM, "name");
    props.put(TableGenerator.SEGMENT_VALUE_PARAM, seqName);
    props.put(TableGenerator.VALUE_COLUMN_PARAM, "value");
    props.put(TableGenerator.OPT_PARAM, "none");
    props.put(TableGenerator.IDENTIFIER_NORMALIZER, _conf.createMappings().getObjectNameNormalizer());

    if (startValue != null) {
        props.put(TableGenerator.INITIAL_PARAM, startValue.intValue());
    }

    tg = TableGenerator.class.newInstance();

    Dialect dialect = ((SessionFactoryImplementor) _sessionFactory).getJdbcServices().getDialect();
    tg.configure(_sessionFactory.getTypeHelper().basic(Long.class), props, dialect);
    _generatorCache.put(seqName, tg);

    return tg;

}