use of example.entity.IdGeneratedEmp in project doma by domaframework.
the class BuiltinIdentityIdGeneratorTest method test_identityReservationSql.
@Test
public void test_identityReservationSql() {
MockConfig config = new MockConfig();
config.setDialect(new PostgresDialect());
MockResultSet resultSet = config.dataSource.connection.preparedStatement.resultSet;
resultSet.rows.add(new RowData(11L));
resultSet.rows.add(new RowData(12L));
resultSet.rows.add(new RowData(13L));
EntityType<IdGeneratedEmp> entityType = _IdGeneratedEmp.getSingletonInternal();
BuiltinIdentityIdGenerator identityIdGenerator = new BuiltinIdentityIdGenerator();
IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, entityType, new ReservedIdProvider(config, entityType, 3));
Long value = identityIdGenerator.generatePreInsert(idGenerationConfig);
assertEquals(new Long(11), value);
assertEquals("select nextval(pg_catalog.pg_get_serial_sequence('\"CATA\".\"EMP\"', 'id')) from generate_series(1, 3)", config.dataSource.connection.preparedStatement.sql);
value = identityIdGenerator.generatePreInsert(idGenerationConfig);
assertEquals(new Long(12), value);
value = identityIdGenerator.generatePreInsert(idGenerationConfig);
assertEquals(new Long(13), value);
try {
identityIdGenerator.generatePreInsert(idGenerationConfig);
fail();
} catch (IllegalStateException e) {
System.out.println(e.getMessage());
}
}
Aggregations