use of org.hibernate.id.enhanced.TableGenerator in project hibernate-orm by hibernate.
the class Db2GenerationTest method testNewGeneratorTableCreationOnDb2.
@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);
}
}
use of org.hibernate.id.enhanced.TableGenerator in project hibernate-orm by hibernate.
the class HiLoTableTest method testNormalBoundary.
@Test
public void testNormalBoundary() {
EntityPersister persister = sessionFactory().getEntityPersister(Entity.class.getName());
assertClassAssignability(TableGenerator.class, persister.getIdentifierGenerator().getClass());
TableGenerator generator = (TableGenerator) persister.getIdentifierGenerator();
assertClassAssignability(HiLoOptimizer.class, generator.getOptimizer().getClass());
HiLoOptimizer optimizer = (HiLoOptimizer) generator.getOptimizer();
int increment = optimizer.getIncrementSize();
Entity[] entities = new Entity[increment + 1];
Session s = openSession();
s.beginTransaction();
for (int i = 0; i < increment; i++) {
entities[i] = new Entity("" + (i + 1));
s.save(entities[i]);
// initialization
assertEquals(1, generator.getTableAccessCount());
// initialization
assertEquals(1, ((BasicHolder) optimizer.getLastSourceValue()).getActualLongValue());
assertEquals(i + 1, ((BasicHolder) optimizer.getLastValue()).getActualLongValue());
assertEquals(increment + 1, ((BasicHolder) optimizer.getHiValue()).getActualLongValue());
}
// now force a "clock over"
entities[increment] = new Entity("" + increment);
s.save(entities[increment]);
// initialization
assertEquals(2, generator.getTableAccessCount());
// initialization
assertEquals(2, ((BasicHolder) optimizer.getLastSourceValue()).getActualLongValue());
assertEquals(increment + 1, ((BasicHolder) optimizer.getLastValue()).getActualLongValue());
assertEquals((increment * 2) + 1, ((BasicHolder) optimizer.getHiValue()).getActualLongValue());
s.getTransaction().commit();
s.beginTransaction();
for (int i = 0; i < entities.length; i++) {
assertEquals(i + 1, entities[i].getId().intValue());
s.delete(entities[i]);
}
s.getTransaction().commit();
s.close();
}
use of org.hibernate.id.enhanced.TableGenerator in project hibernate-orm by hibernate.
the class BasicTableTest method testNormalBoundary.
@Test
public void testNormalBoundary() {
EntityPersister persister = sessionFactory().getEntityPersister(Entity.class.getName());
assertClassAssignability(TableGenerator.class, persister.getIdentifierGenerator().getClass());
TableGenerator generator = (TableGenerator) persister.getIdentifierGenerator();
int count = 5;
Entity[] entities = new Entity[count];
Session s = openSession();
s.beginTransaction();
for (int i = 0; i < count; i++) {
entities[i] = new Entity("" + (i + 1));
s.save(entities[i]);
long expectedId = i + 1;
assertEquals(expectedId, entities[i].getId().longValue());
assertEquals(expectedId, generator.getTableAccessCount());
assertEquals(expectedId, ((BasicHolder) generator.getOptimizer().getLastSourceValue()).getActualLongValue());
}
s.getTransaction().commit();
s.beginTransaction();
for (int i = 0; i < count; i++) {
assertEquals(i + 1, entities[i].getId().intValue());
s.delete(entities[i]);
}
s.getTransaction().commit();
s.close();
}
use of org.hibernate.id.enhanced.TableGenerator in project hibernate-orm by hibernate.
the class PooledTableTest method testNormalBoundary.
@Test
public void testNormalBoundary() {
EntityPersister persister = sessionFactory().getEntityPersister(Entity.class.getName());
assertClassAssignability(TableGenerator.class, persister.getIdentifierGenerator().getClass());
TableGenerator generator = (TableGenerator) persister.getIdentifierGenerator();
assertClassAssignability(PooledOptimizer.class, generator.getOptimizer().getClass());
PooledOptimizer optimizer = (PooledOptimizer) generator.getOptimizer();
int increment = optimizer.getIncrementSize();
Entity[] entities = new Entity[increment + 2];
Session s = openSession();
s.beginTransaction();
for (int i = 0; i <= increment; i++) {
entities[i] = new Entity("" + (i + 1));
s.save(entities[i]);
// initialization calls seq twice
assertEquals(2, generator.getTableAccessCount());
// initialization calls seq twice
assertEquals(increment + 1, ((BasicHolder) optimizer.getLastSourceValue()).getActualLongValue());
assertEquals(i + 1, ((BasicHolder) optimizer.getLastValue()).getActualLongValue());
assertEquals(increment + 1, ((BasicHolder) optimizer.getLastSourceValue()).getActualLongValue());
}
// now force a "clock over"
entities[increment + 1] = new Entity("" + increment);
s.save(entities[increment + 1]);
// initialization (2) + clock over
assertEquals(3, generator.getTableAccessCount());
// initialization (2) + clock over
assertEquals((increment * 2) + 1, ((BasicHolder) optimizer.getLastSourceValue()).getActualLongValue());
assertEquals(increment + 2, ((BasicHolder) optimizer.getLastValue()).getActualLongValue());
s.getTransaction().commit();
s.beginTransaction();
for (int i = 0; i < entities.length; i++) {
assertEquals(i + 1, entities[i].getId().intValue());
s.delete(entities[i]);
}
s.getTransaction().commit();
s.close();
}
use of org.hibernate.id.enhanced.TableGenerator in project hibernate-orm by hibernate.
the class NewGeneratorMappingsTest method testMinimalTableEntity.
@Test
public void testMinimalTableEntity() {
final EntityPersister persister = sessionFactory().getEntityPersister(MinimalTableEntity.class.getName());
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue(TableGenerator.class.isInstance(generator));
TableGenerator tabGenerator = (TableGenerator) generator;
assertEquals(MinimalTableEntity.TBL_NAME, tabGenerator.getTableName());
assertEquals(TableGenerator.DEF_SEGMENT_COLUMN, tabGenerator.getSegmentColumnName());
assertEquals("MINIMAL_TBL", tabGenerator.getSegmentValue());
assertEquals(TableGenerator.DEF_VALUE_COLUMN, tabGenerator.getValueColumnName());
// 0 is the annotation default, but its expected to be treated as 1
assertEquals(1, tabGenerator.getInitialValue());
// 50 is the annotation default
assertEquals(50, tabGenerator.getIncrementSize());
assertTrue(PooledOptimizer.class.isInstance(tabGenerator.getOptimizer()));
}
Aggregations