public void visitGenerators(Configuration cfg, IssueCollector collector) { Iterator iter = iterateGenerators(cfg); Set sequences = Collections.EMPTY_SET; if (dialect.supportsSequences()) { sequences = reader.readSequences(dialect.getQuerySequencesString()); } // TODO: move this check into something that could check per class or collection instead. while (iter.hasNext()) { PersistentIdentifierGenerator generator = (PersistentIdentifierGenerator) iter.next(); Object key = generator.generatorKey(); if (!isSequence(key, sequences) && !isTable(key)) { collector.reportIssue( new Issue( "MISSING_ID_GENERATOR", Issue.HIGH_PRIORITY, "Missing sequence or table: " + key)); } } }
@Override public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException { final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService(JdbcEnvironment.class); final Dialect dialect = jdbcEnvironment.getDialect(); this.identifierType = type; boolean forceTableUse = ConfigurationHelper.getBoolean(FORCE_TBL_PARAM, params, false); final QualifiedName sequenceName = determineSequenceName(params, dialect, jdbcEnvironment); 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, jdbcEnvironment, forceTableUse, sequenceName, initialValue, incrementSize); this.optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, ConfigurationHelper.getInt(INITIAL_PARAM, params, -1)); this.databaseStructure.prepare(optimizer); }
@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); }
/** * Build the database structure. * * @param type The Hibernate type of the identifier property * @param params The params supplied in the generator config (plus some standard useful extras). * @param dialect The dialect being used. * @param forceTableUse Should a table be used even if the dialect supports sequences? * @param sequenceName The name to use for the sequence or table. * @param initialValue The initial value. * @param incrementSize the increment size to use (after any adjustments). * @return An abstraction for the actual database structure in use (table vs. sequence). */ protected DatabaseStructure buildDatabaseStructure( Type type, Properties params, Dialect dialect, boolean forceTableUse, ObjectName sequenceName, int initialValue, int incrementSize) { final boolean useSequence = dialect.supportsSequences() && !forceTableUse; if (useSequence) { return new SequenceStructure( dialect, sequenceName, initialValue, incrementSize, type.getReturnedClass()); } else { Identifier valueColumnName = determineValueColumnName(params, dialect); return new TableStructure( dialect, sequenceName, valueColumnName, initialValue, incrementSize, type.getReturnedClass()); } }
public boolean isMatch(Dialect dialect) { return dialect.supportsSequences(); }