Search in sources :

Example 6 with MockConfig

use of org.seasar.doma.internal.jdbc.mock.MockConfig in project doma by domaframework.

the class NativeSqlSelectTest method expression_concat_mssql2008.

@Test
void expression_concat_mssql2008() {
    NativeSql nativeSql = new NativeSql(new MockConfig() {

        @Override
        public Dialect getDialect() {
            return new Mssql2008Dialect();
        }
    });
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).select(concat(e.name, "a"));
    Sql<?> sql = stmt.asSql();
    assertEquals("select (t0_.NAME + 'a') from EMP t0_", sql.getFormattedSql());
}
Also used : Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 7 with MockConfig

use of org.seasar.doma.internal.jdbc.mock.MockConfig in project doma by domaframework.

the class NativeSqlSelectTest method forUpdate_oracle_nowait.

@Test
void forUpdate_oracle_nowait() {
    NativeSql nativeSql = new NativeSql(new MockConfig() {

        @Override
        public Dialect getDialect() {
            return new OracleDialect();
        }
    });
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).forUpdate(ForUpdateOption.noWait()).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ for update nowait", sql.getFormattedSql());
}
Also used : OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 8 with MockConfig

use of org.seasar.doma.internal.jdbc.mock.MockConfig in project doma by domaframework.

the class NativeSqlSelectTest method forUpdate_oracle_wait_withColumn.

@Test
void forUpdate_oracle_wait_withColumn() {
    NativeSql nativeSql = new NativeSql(new MockConfig() {

        @Override
        public Dialect getDialect() {
            return new OracleDialect();
        }
    });
    Emp_ e = new Emp_();
    Dept_ d = new Dept_();
    Buildable<?> stmt = nativeSql.from(e).innerJoin(d, on -> on.eq(e.id, d.id)).forUpdate(ForUpdateOption.wait(5, e.id, d.id)).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ inner join CATA.DEPT t1_ on (t0_.ID = t1_.ID) for update of t0_.ID, t1_.ID wait 5", sql.getFormattedSql());
}
Also used : OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) NoIdEmp_(org.seasar.doma.jdbc.criteria.entity.NoIdEmp_) Dept_(org.seasar.doma.jdbc.criteria.entity.Dept_) Dialect(org.seasar.doma.jdbc.dialect.Dialect) Db2Dialect(org.seasar.doma.jdbc.dialect.Db2Dialect) OracleDialect(org.seasar.doma.jdbc.dialect.OracleDialect) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 9 with MockConfig

use of org.seasar.doma.internal.jdbc.mock.MockConfig 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)

Example 10 with MockConfig

use of org.seasar.doma.internal.jdbc.mock.MockConfig in project doma by domaframework.

the class BuiltinTableIdGeneratorTest method test.

@Test
public void test() {
    MockConfig config = new MockConfig();
    config.setDialect(new PostgresDialect());
    MockConnection connection = new MockConnection();
    MockConnection connection2 = new MockConnection();
    MockResultSet resultSet2 = connection2.preparedStatement.resultSet;
    resultSet2.rows.add(new RowData(11L));
    final LinkedList<MockConnection> connections = new LinkedList<>();
    connections.add(connection);
    connections.add(connection2);
    config.dataSource = new MockDataSource() {

        @Override
        public Connection getConnection() {
            return connections.pop();
        }
    };
    BuiltinTableIdGenerator idGenerator = new BuiltinTableIdGenerator();
    idGenerator.setQualifiedTableName("aaa");
    idGenerator.setPkColumnName("PK");
    idGenerator.setPkColumnValue("EMP_ID");
    idGenerator.setValueColumnName("VALUE");
    idGenerator.setInitialValue(1);
    idGenerator.setAllocationSize(1);
    idGenerator.initialize();
    IdGenerationConfig idGenerationConfig = new IdGenerationConfig(config, _IdGeneratedEmp.getSingletonInternal());
    Long value = idGenerator.generatePreInsert(idGenerationConfig);
    assertEquals(new Long(10), value);
    assertEquals("update aaa set VALUE = VALUE + ? where PK = ?", connection.preparedStatement.sql);
    assertEquals(2, connection.preparedStatement.bindValues.size());
    assertEquals("select VALUE from aaa where PK = ?", connection2.preparedStatement.sql);
    assertEquals(1, connection2.preparedStatement.bindValues.size());
}
Also used : Connection(java.sql.Connection) MockConnection(org.seasar.doma.internal.jdbc.mock.MockConnection) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) MockConnection(org.seasar.doma.internal.jdbc.mock.MockConnection) LinkedList(java.util.LinkedList) RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockDataSource(org.seasar.doma.internal.jdbc.mock.MockDataSource) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) PostgresDialect(org.seasar.doma.jdbc.dialect.PostgresDialect) Test(org.junit.jupiter.api.Test)

Aggregations

MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)144 Test (org.junit.jupiter.api.Test)140 NodePreparedSqlBuilder (org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder)64 SqlParser (org.seasar.doma.internal.jdbc.sql.SqlParser)64 PreparedSql (org.seasar.doma.jdbc.PreparedSql)59 SqlNode (org.seasar.doma.jdbc.SqlNode)59 PostgresDialect (org.seasar.doma.jdbc.dialect.PostgresDialect)12 Emp_ (org.seasar.doma.jdbc.criteria.entity.Emp_)11 ArrayList (java.util.ArrayList)9 LinkedHashMap (java.util.LinkedHashMap)9 NoIdEmp_ (org.seasar.doma.jdbc.criteria.entity.NoIdEmp_)9 Mssql2008Dialect (org.seasar.doma.jdbc.dialect.Mssql2008Dialect)9 MssqlDialect (org.seasar.doma.jdbc.dialect.MssqlDialect)9 BigDecimal (java.math.BigDecimal)8 Db2Dialect (org.seasar.doma.jdbc.dialect.Db2Dialect)8 Dialect (org.seasar.doma.jdbc.dialect.Dialect)8 OracleDialect (org.seasar.doma.jdbc.dialect.OracleDialect)8 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)6 RowData (org.seasar.doma.internal.jdbc.mock.RowData)6 Emp (example.entity.Emp)5