@Override public void configure( Type type, Properties params, Dialect dialect, ClassLoaderService classLoaderService) throws MappingException { this.identifierType = type; boolean forceTableUse = ConfigurationHelper.getBoolean(FORCE_TBL_PARAM, params, false); final ObjectName qualifiedSequenceName = determineSequenceName(params, dialect); final String sequenceNameText = qualifiedSequenceName.toText(dialect); final int initialValue = determineInitialValue(params); int incrementSize = determineIncrementSize(params); final String optimizationStrategy = determineOptimizationStrategy(params, incrementSize); incrementSize = determineAdjustedIncrementSize(optimizationStrategy, incrementSize); if (dialect.supportsSequences() && !forceTableUse) { if (!dialect.supportsPooledSequences() && OptimizerFactory.isPooledOptimizer(optimizationStrategy)) { forceTableUse = true; LOG.forcingTableUse(); } } this.databaseStructure = buildDatabaseStructure( type, params, dialect, forceTableUse, qualifiedSequenceName, initialValue, incrementSize); this.optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, ConfigurationHelper.getInt(INITIAL_PARAM, params, -1), classLoaderService); this.databaseStructure.prepare(optimizer); }
/** * Determine the name of the sequence (or table if this resolves to a physical table) to use. * * <p>Called during {@link #configure configuration}. * * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect in effect * @return The sequence name */ protected ObjectName determineSequenceName(Properties params, Dialect dialect) { String sequencePerEntitySuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX); // JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) // overrides. String sequenceName = ConfigurationHelper.getBoolean(CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false) ? params.getProperty(JPA_ENTITY_NAME) + sequencePerEntitySuffix : DEF_SEQUENCE_NAME; final ObjectNameNormalizer normalizer = (ObjectNameNormalizer) params.get(IDENTIFIER_NORMALIZER); sequenceName = normalizer.normalizeIdentifierQuoting( ConfigurationHelper.getString(SEQUENCE_PARAM, params, sequenceName)); if (sequenceName.indexOf('.') < 0) { final String schemaName = normalizer.normalizeIdentifierQuoting(params.getProperty(SCHEMA)); final String catalogName = normalizer.normalizeIdentifierQuoting(params.getProperty(CATALOG)); return new ObjectName(catalogName, schemaName, sequenceName); } else { return ObjectName.parse(sequenceName); } }