dialect ); table.addInitCommand( generateInsertInitCommand() ); this.selectQuery = buildSelectQuery( dialect ); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery();
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { if (params.get("table_name") == null) { params.put("table_name", "SEQUENCE_GENERATOR"); } if (params.get("segment_column_name") == null) { params.put("segment_column_name", DEFAULT_SEGMENT_COLUMN_NAME); } if (params.get("value_column_name") == null) { params.put("value_column_name", DEFAULT_VALUE_COLUMN_NAME); } if (params.get("increment_size") == null) { params.put("increment_size", DEFAULT_INCREMENT_SIZE); } super.configure(type, params, dialect); entityName = (String) params.get(ENTITY_NAME_PARAM); }
/** * Determine the segment value corresponding to this generator instance. * <p/> * Called during {@link #configure configuration}. * * @see #getSegmentValue() * @param params The params supplied in the generator config (plus some standard useful extras). * @return The name of the value column */ @SuppressWarnings("WeakerAccess") protected String determineSegmentValue(Properties params) { String segmentValue = params.getProperty( SEGMENT_VALUE_PARAM ); if ( StringHelper.isEmpty( segmentValue ) ) { segmentValue = determineDefaultSegmentValue( params ); } return segmentValue; }
@Override public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException { storeLastUsedValue = serviceRegistry.getService( ConfigurationService.class ) .getSetting( AvailableSettings.TABLE_GENERATOR_STORE_LAST_USED, StandardConverters.BOOLEAN, true ); identifierType = type; final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class ); qualifiedTableName = determineGeneratorTableName( params, jdbcEnvironment, serviceRegistry ); segmentColumnName = determineSegmentColumnName( params, jdbcEnvironment ); valueColumnName = determineValueColumnName( params, jdbcEnvironment ); segmentValue = determineSegmentValue( params ); segmentValueLength = determineSegmentColumnSize( params ); initialValue = determineInitialValue( params ); incrementSize = determineIncrementSize( params ); final String optimizationStrategy = ConfigurationHelper.getString( OPT_PARAM, params, OptimizerFactory.determineImplicitOptimizerName( incrementSize, params ) ); int optimizerInitialValue = ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 ); optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, optimizerInitialValue ); }
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { identifierType = type; tableName = determineGeneratorTableName( params, dialect ); segmentColumnName = determineSegmentColumnName( params, dialect ); valueColumnName = determineValueColumnName( params, dialect ); segmentValue = determineSegmentValue( params ); segmentValueLength = determineSegmentColumnSize( params ); initialValue = determineInitialValue( params ); incrementSize = determineIncrementSize( params ); this.selectQuery = buildSelectQuery( dialect ); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery(); // if the increment size is greater than one, we prefer pooled optimization; but we // need to see if the user prefers POOL or POOL_LO... String defaultPooledOptimizerStrategy = ConfigurationHelper.getBoolean( Environment.PREFER_POOLED_VALUES_LO, params, false ) ? OptimizerFactory.StandardOptimizerDescriptor.POOLED_LO.getExternalName() : OptimizerFactory.StandardOptimizerDescriptor.POOLED.getExternalName(); final String defaultOptimizerStrategy = incrementSize <= 1 ? OptimizerFactory.StandardOptimizerDescriptor.NONE.getExternalName() : defaultPooledOptimizerStrategy; final String optimizationStrategy = ConfigurationHelper.getString( OPT_PARAM, params, defaultOptimizerStrategy ); optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 ) ); }
@Test @TestForIssue( jiraKey = "HHH-9850" ) public void testNewGeneratorTableCreationOnDb2() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.DIALECT, DB2Dialect.class.getName() ) .build(); try { Metadata metadata = new MetadataSources( ssr ) .buildMetadata(); assertEquals( 0, metadata.getDatabase().getDefaultNamespace().getTables().size() ); TableGenerator generator = new TableGenerator(); Properties properties = new Properties(); generator.configure( IntegerType.INSTANCE, properties, ssr ); generator.registerExportables( metadata.getDatabase() ); assertEquals( 1, metadata.getDatabase().getDefaultNamespace().getTables().size() ); final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next(); final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata ); assertContains( "sequence_name varchar(255) not null", createCommands[0] ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); } }
if(instanceSeqId == null) { logger.warn("没有找到对应的实例,采用缺省的的主键生成方式"); id = "" + super.generate(session, obj); tableGenerator = new TableGenerator(); tableGenerator.configure(new IntegerType(), defaultParams, defaultDialet); multiTenantTableGenerator.put(instanceSeqId, tableGenerator); logger.info("创建{}的主键生成器。", instanceSeqId); id = "" + tableGenerator.generate(session, obj);
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { identifierType = type; tableName = determineGeneratorTableName( params, dialect ); segmentColumnName = determineSegmentColumnName( params, dialect ); valueColumnName = determineValueColumnName( params, dialect ); segmentValue = determineSegmentValue( params ); segmentValueLength = determineSegmentColumnSize( params ); initialValue = determineInitialValue( params ); incrementSize = determineIncrementSize( params ); this.selectQuery = buildSelectQuery( dialect ); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery(); // if the increment size is greater than one, we prefer pooled optimization; but we // need to see if the user prefers POOL or POOL_LO... String defaultPooledOptimizerStrategy = ConfigurationHelper.getBoolean( Environment.PREFER_POOLED_VALUES_LO, params, false ) ? OptimizerFactory.StandardOptimizerDescriptor.POOLED_LO.getExternalName() : OptimizerFactory.StandardOptimizerDescriptor.POOLED.getExternalName(); final String defaultOptimizerStrategy = incrementSize <= 1 ? OptimizerFactory.StandardOptimizerDescriptor.NONE.getExternalName() : defaultPooledOptimizerStrategy; final String optimizationStrategy = ConfigurationHelper.getString( OPT_PARAM, params, defaultOptimizerStrategy ); optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getReturnedClass(), incrementSize, ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 ) ); }
@Override public void configure(JavaTypeDescriptor javaTypeDescriptor, Properties params, ServiceRegistry serviceRegistry) throws MappingException { storeLastUsedValue = serviceRegistry.getService( ConfigurationService.class ) .getSetting( AvailableSettings.TABLE_GENERATOR_STORE_LAST_USED, StandardConverters.BOOLEAN, true ); identifierType = javaTypeDescriptor; final JdbcEnvironment jdbcEnvironment = serviceRegistry.getService( JdbcEnvironment.class ); qualifiedTableName = determineGeneratorTableName( params, jdbcEnvironment, serviceRegistry ); segmentColumnName = determineSegmentColumnName( params, jdbcEnvironment ); valueColumnName = determineValueColumnName( params, jdbcEnvironment ); segmentValue = determineSegmentValue( params ); segmentValueLength = determineSegmentColumnSize( params ); initialValue = determineInitialValue( params ); incrementSize = determineIncrementSize( params ); final String optimizationStrategy = ConfigurationHelper.getString( OPT_PARAM, params, OptimizerFactory.determineImplicitOptimizerName( incrementSize, params ) ); int optimizerInitialValue = ConfigurationHelper.getInt( INITIAL_PARAM, params, -1 ); optimizer = OptimizerFactory.buildOptimizer( optimizationStrategy, identifierType.getJavaType(), incrementSize, optimizerInitialValue ); }
dialect ); table.addInitCommand( generateInsertInitCommand() ); this.selectQuery = buildSelectQuery( dialect ); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery();
/** * Determine the segment value corresponding to this generator instance. * <p/> * Called during {@link #configure configuration}. * * @see #getSegmentValue() * @param params The params supplied in the generator config (plus some standard useful extras). * @return The name of the value column */ @SuppressWarnings("WeakerAccess") protected String determineSegmentValue(Properties params) { String segmentValue = params.getProperty( SEGMENT_VALUE_PARAM ); if ( StringHelper.isEmpty( segmentValue ) ) { segmentValue = determineDefaultSegmentValue( params ); } return segmentValue; }
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { super.configure(type, params, dialect); }
/** * Determine the segment value corresponding to this generator instance. * <p/> * Called during {@link #configure configuration}. * * @see #getSegmentValue() * @param params The params supplied in the generator config (plus some standard useful extras). * @return The name of the value column */ protected String determineSegmentValue(Properties params) { String segmentValue = params.getProperty( SEGMENT_VALUE_PARAM ); if ( StringHelper.isEmpty( segmentValue ) ) { segmentValue = determineDefaultSegmentValue( params ); } return segmentValue; }
@Override public void configure(Type type, Properties params, Dialect dialect) throws MappingException { // 如果这里写成super.configure(type, params, dialect);会造成死循环 // 因为TableGenerator默认Integer类型主键 this.defaultParams = params; this.defaultDialet = dialect; super.configure(new IntegerType(), params, dialect); // format = params.getProperty("format"); }
/** * Determine the segment value corresponding to this generator instance. * <p/> * Called during {@link #configure configuration}. * * @see #getSegmentValue() * @param params The params supplied in the generator config (plus some standard useful extras). * @return The name of the value column */ protected String determineSegmentValue(Properties params) { String segmentValue = params.getProperty( SEGMENT_VALUE_PARAM ); if ( StringHelper.isEmpty( segmentValue ) ) { segmentValue = determineDefaultSegmentValue( params ); } return segmentValue; }