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

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

Introduction

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

Prototype

@Override
    public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException 

Source Link

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;
    }//  w w w .  j  a  v a 2  s. com

    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;

}