Search in sources :

Example 1 with MockConfig

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

the class CommentContextTest method getMessage_empty.

@Test
void getMessage_empty() {
    CommentContext context = new CommentContext("class", "method", new MockConfig(), null, null);
    assertFalse(context.getMessage().isPresent());
}
Also used : MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 2 with MockConfig

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

the class CommentContextTest method getMessage.

@Test
void getMessage() {
    CommentContext context = new CommentContext("class", "method", new MockConfig(), null, "hello");
    assertEquals("hello", context.getMessage().get());
}
Also used : MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 3 with MockConfig

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

the class StandardPagingTransformerTest method testOffsetLimit_forNode.

@Test
public void testOffsetLimit_forNode() {
    String expected = "select * from ( select temp_.*, row_number() over( order by temp_.name1, temp_.name2, temp_.id ) as doma_rownumber_ from ( select emp.id from emp ) as temp_ ) as temp2_ where doma_rownumber_ > 5 and doma_rownumber_ <= 15";
    StandardPagingTransformer transformer = new StandardPagingTransformer(5, 10);
    SqlParser parser = new SqlParser("select emp.id from emp order by /*%for e: values*/emp.name/*#e*/, /*%end*/emp.id");
    SqlNode sqlNode = transformer.transform(parser.parse());
    ExpressionEvaluator evaluator = new ExpressionEvaluator();
    evaluator.add("values", new Value(List.class, Arrays.asList(1, 2)));
    NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(new MockConfig(), SqlKind.SELECT, "dummyPath", evaluator, SqlLogType.FORMATTED);
    PreparedSql sql = sqlBuilder.build(sqlNode, Function.identity());
    assertEquals(expected, sql.getRawSql());
}
Also used : SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) Value(org.seasar.doma.internal.expr.Value) List(java.util.List) NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) ExpressionEvaluator(org.seasar.doma.internal.expr.ExpressionEvaluator) Test(org.junit.jupiter.api.Test)

Example 4 with MockConfig

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

the class StandardPagingTransformerTest method testOffsetLimit.

@Test
public void testOffsetLimit() {
    String expected = "select * from ( select temp_.*, row_number() over( order by temp_.id ) as doma_rownumber_ from ( select emp.id from emp ) as temp_ ) as temp2_ where doma_rownumber_ > 5 and doma_rownumber_ <= 15";
    StandardPagingTransformer transformer = new StandardPagingTransformer(5, 10);
    SqlParser parser = new SqlParser("select emp.id from emp order by emp.id");
    SqlNode sqlNode = transformer.transform(parser.parse());
    NodePreparedSqlBuilder sqlBuilder = new NodePreparedSqlBuilder(new MockConfig(), SqlKind.SELECT, "dummyPath");
    PreparedSql sql = sqlBuilder.build(sqlNode, Function.identity());
    assertEquals(expected, sql.getRawSql());
}
Also used : SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 5 with MockConfig

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

the class NativeSqlSelectTest method forUpdate_mssql_nowait.

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

        @Override
        public Dialect getDialect() {
            return new MssqlDialect();
        }
    });
    Emp_ e = new Emp_();
    Buildable<?> stmt = nativeSql.from(e).where(c -> c.eq(e.id, 1)).forUpdate(ForUpdateOption.noWait()).select(e.id);
    Sql<?> sql = stmt.asSql();
    assertEquals("select t0_.ID from EMP t0_ with (updlock, rowlock, nowait) where t0_.ID = 1", sql.getFormattedSql());
}
Also used : MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) 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)

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