@Before public void setUp() throws Exception { serviceRegistry = new StandardServiceRegistryBuilder() .enableAutoClose() .applySetting( AvailableSettings.HBM2DDL_AUTO, "create-drop" ) .build(); generator = new SequenceStyleGenerator(); // Build the properties used to configure the id generator Properties properties = new Properties(); properties.setProperty( SequenceStyleGenerator.SEQUENCE_PARAM, TEST_SEQUENCE ); properties.setProperty( SequenceStyleGenerator.OPT_PARAM, "legacy-hilo" ); properties.setProperty( SequenceStyleGenerator.INCREMENT_PARAM, "0" ); // JPA allocationSize of 1 properties.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, new ObjectNameNormalizer() { @Override protected MetadataBuildingContext getBuildingContext() { return new MetadataBuildingContextTestingImpl( serviceRegistry ); } } ); generator.configure( StandardBasicTypes.LONG, properties, serviceRegistry ); final Metadata metadata = new MetadataSources( serviceRegistry ).buildMetadata(); generator.registerExportables( metadata.getDatabase() ); sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory(); sequenceValueExtractor = new SequenceValueExtractor( sessionFactory.getDialect(), TEST_SEQUENCE ); }
@Override public void configure(final Type type, final Properties params, final ServiceRegistry serviceRegistry) { // Augment the property set with the global configuration params.setProperty(CONFIG_PREFER_SEQUENCE_PER_ENTITY, Boolean.TRUE.toString()); params.setProperty(INCREMENT_PARAM, "1000"); params.setProperty(FORCE_TBL_PARAM, "true"); super.configure(type, params, serviceRegistry); }
/** * If the parameters do not contain a {@link SequenceGenerator#SEQUENCE} name, we assign one * based on the table name. */ public void configure(Type type, Properties params, Dialect dialect) { if (Strings.isEmpty(params.getProperty(SEQUENCE_PARAM))) { String tableName = params.getProperty(PersistentIdentifierGenerator.TABLE); String pk = params.getProperty(PersistentIdentifierGenerator.PK); if (null != tableName) { String seqName = Strings.replace(sequencePattern, "{table}", tableName); seqName = Strings.replace(seqName, "{pk}", pk); if (seqName.length() > MaxLength) { logger.error("{}'s length >=30, wouldn't be supported in some db!", seqName); } String entityName = params.getProperty(IdentifierGenerator.ENTITY_NAME); if (null != entityName && null != namingStrategy) { String schema = namingStrategy.getSchema(entityName); if (null != schema) seqName = schema + "." + seqName; } params.setProperty(SEQUENCE_PARAM, seqName); } } super.configure(type, params, dialect); }