use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testImplicitTableGenerator.
@Test
public void testImplicitTableGenerator() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ImplicitTableGeneratorEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ImplicitTableGeneratorEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final TableGenerator tableGenerator = assertTyping(TableGenerator.class, generator);
assertThat(tableGenerator.getTableName(), is("my_id_table"));
// all the JPA defaults since they were not defined
assertThat(tableGenerator.getInitialValue(), is(1));
assertThat(tableGenerator.getIncrementSize(), is(50));
}
use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testExplicitTableGeneratorImplicitName.
@Test
public void testExplicitTableGeneratorImplicitName() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ExplicitTableGeneratorImplicitNameEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ExplicitTableGeneratorImplicitNameEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final TableGenerator tableGenerator = assertTyping(TableGenerator.class, generator);
assertThat(tableGenerator.getTableName(), is("my_id_table"));
// - note : currently initialValue=1 in mapping is shows up here as 2
assertThat(tableGenerator.getInitialValue(), is(1));
assertThat(tableGenerator.getIncrementSize(), is(25));
}
use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testExplicitSequenceGeneratorImplicitNamePreferGeneratorName.
@Test
public void testExplicitSequenceGeneratorImplicitNamePreferGeneratorName() {
// this should be the default behavior
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ExplicitSequenceGeneratorImplicitNameEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ExplicitSequenceGeneratorImplicitNameEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(SequenceStyleGenerator.class, generator);
// all the JPA defaults since they were not defined
assertThat(sequenceStyleGenerator.getDatabaseStructure().getName(), is("my_db_sequence"));
assertThat(sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is(100));
assertThat(sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is(500));
final Sequence sequence = bootModel.getDatabase().getDefaultNamespace().locateSequence(Identifier.toIdentifier("my_db_sequence"));
assertThat(sequence, notNullValue());
final String[] sqlCreateStrings = new H2Dialect().getSequenceExporter().getSqlCreateStrings(sequence, bootModel);
assertThat(sqlCreateStrings.length, is(1));
final String cmd = sqlCreateStrings[0].toLowerCase();
assertTrue(cmd.startsWith("create sequence my_db_sequence start with 100 increment by 500"));
}
use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testExplicitTableGenerator.
@Test
public void testExplicitTableGenerator() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ExplicitTableGeneratorEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ExplicitTableGeneratorEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final TableGenerator tableGenerator = assertTyping(TableGenerator.class, generator);
assertThat(tableGenerator.getTableName(), is("my_real_id_table"));
// all the JPA defaults since they were not defined
// - note : currently initialValue=1 in mapping is shows up here
// as 2
// assertThat( tableGenerator.getInitialValue(), is( 1 ) );
assertThat(tableGenerator.getIncrementSize(), is(25));
}
use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testImplicitSequenceGeneratorGeneratorName.
@Test
public void testImplicitSequenceGeneratorGeneratorName() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ImplicitSequenceGeneratorEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ImplicitSequenceGeneratorEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(SequenceStyleGenerator.class, generator);
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == true (the default) indicates that the generator-name
// should be used as the default instead.
assertThat(sequenceStyleGenerator.getDatabaseStructure().getName(), is("my_db_sequence"));
// the JPA defaults since they were not defined
assertThat(sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is(1));
assertThat(sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is(50));
}
Aggregations