Search in sources :

Example 1 with IdGeneratedEmp

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());
    }
}
Also used : RowData(org.seasar.doma.internal.jdbc.mock.RowData) example.entity._IdGeneratedEmp(example.entity._IdGeneratedEmp) IdGeneratedEmp(example.entity.IdGeneratedEmp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Test(org.junit.jupiter.api.Test)

Aggregations

IdGeneratedEmp (example.entity.IdGeneratedEmp)1 example.entity._IdGeneratedEmp (example.entity._IdGeneratedEmp)1 Test (org.junit.jupiter.api.Test)1 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)1 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)1 RowData (org.seasar.doma.internal.jdbc.mock.RowData)1 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)1