Example usage for org.hibernate.id MultipleHiLoPerTableGenerator configure

List of usage examples for org.hibernate.id MultipleHiLoPerTableGenerator configure

Introduction

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

Prototype

@SuppressWarnings({ "StatementWithEmptyBody", "deprecation" })
    public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException 

Source Link

Usage

From source file:gov.medicaid.services.impl.SequenceGeneratorBean.java

License:Apache License

/**
 * Creates a new sequence if necessary./*from  w w  w  .  j a  va  2 s.c  o m*/
 *
 * @param sequenceName the sequence to get the next set of values for
 * @return the generator
 */
private MultipleHiLoPerTableGenerator configure(String sequenceName) {
    Properties params = new Properties();
    params.put(MultipleHiLoPerTableGenerator.ID_TABLE, "CMS_SEQUENCE");
    params.put(MultipleHiLoPerTableGenerator.PK_COLUMN_NAME, "SEQ_NAME");
    params.put(MultipleHiLoPerTableGenerator.PK_VALUE_NAME, sequenceName);
    params.put(MultipleHiLoPerTableGenerator.VALUE_COLUMN_NAME, "NEXT_HI");
    params.put(MultipleHiLoPerTableGenerator.MAX_LO, MAXIMUM_LO);
    params.put(MultipleHiLoPerTableGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() {
        /**
         * Returns false.
         */
        protected boolean isUseQuotedIdentifiersGlobally() {
            return false;
        }

        /**
         * Returns the default naming strategy.
         */
        protected NamingStrategy getNamingStrategy() {
            return EJB3NamingStrategy.INSTANCE;
        }
    });

    Session sess = (Session) em.getDelegate();
    SessionFactoryImplementor impl = (SessionFactoryImplementor) sess.getSessionFactory();
    MultipleHiLoPerTableGenerator generator = new MultipleHiLoPerTableGenerator();
    generator.configure(LongType.INSTANCE, params, impl.getDialect());
    generators.put(sequenceName, generator);
    return generator;
}