protected DatabaseStructure buildSequenceStructure( Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize) { return new SequenceStructure( jdbcEnvironment, sequenceName, initialValue, incrementSize, type.getReturnedClass()); }
public void configure(Type type, Properties params, Dialect dialect) throws MappingException { tableName = PropertiesHelper.getString(ID_TABLE, params, DEFAULT_TABLE); pkColumnName = PropertiesHelper.getString(PK_COLUMN_NAME, params, DEFAULT_PK_COLUMN); valueColumnName = PropertiesHelper.getString(VALUE_COLUMN_NAME, params, DEFAULT_VALUE_COLUMN); String schemaName = params.getProperty(SCHEMA); String catalogName = params.getProperty(CATALOG); keySize = PropertiesHelper.getInt(PK_LENGTH_NAME, params, DEFAULT_PK_LENGTH); String keyValue = PropertiesHelper.getString(PK_VALUE_NAME, params, params.getProperty(TABLE)); if (tableName.indexOf('.') < 0) { tableName = Table.qualify(catalogName, schemaName, tableName); } query = "select " + valueColumnName + " from " + dialect.appendLockHint(LockMode.UPGRADE, tableName) + " where " + pkColumnName + " = '" + keyValue + "'" + dialect.getForUpdateString(); update = "update " + tableName + " set " + valueColumnName + " = ? where " + valueColumnName + " = ? and " + pkColumnName + " = '" + keyValue + "'"; insert = "insert into " + tableName + "(" + pkColumnName + ", " + valueColumnName + ") " + "values('" + keyValue + "', ?)"; // hilo config maxLo = PropertiesHelper.getInt(MAX_LO, params, Short.MAX_VALUE); lo = maxLo + 1; // so we "clock over" on the first invocation returnClass = type.getReturnedClass(); }
/** * 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()); } }
protected DatabaseStructure buildTableStructure( Type type, Properties params, JdbcEnvironment jdbcEnvironment, QualifiedName sequenceName, int initialValue, int incrementSize) { final Identifier valueColumnName = determineValueColumnName(params, jdbcEnvironment); return new TableStructure( jdbcEnvironment, sequenceName, valueColumnName, initialValue, incrementSize, type.getReturnedClass()); }
@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); }
private boolean isIntegral(Type type) { return Long.class.isAssignableFrom(type.getReturnedClass()) || Integer.class.isAssignableFrom(type.getReturnedClass()) || long.class.isAssignableFrom(type.getReturnedClass()) || int.class.isAssignableFrom(type.getReturnedClass()); }