Search in sources :

Example 11 with MockConfig

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

the class NativeSqlUpdateTest method aliasInUpdateClause.

@Test
void aliasInUpdateClause() {
    MockConfig config = new MockConfig();
    config.dialect = new MssqlDialect();
    NativeSql nativeSql = new NativeSql(config);
    Emp_ e = new Emp_();
    Statement<Integer> stmt = nativeSql.update(e).set(c -> {
        c.value(e.name, "bbb");
        c.value(e.salary, new BigDecimal("1000"));
    }).where(c -> c.eq(e.id, 1));
    Sql<?> sql = stmt.asSql();
    assertEquals("update t0_ set NAME = 'bbb', SALARY = 1000 from EMP t0_ where t0_.ID = 1", sql.getFormattedSql());
}
Also used : Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Statement(org.seasar.doma.jdbc.criteria.statement.Statement) Sql(org.seasar.doma.jdbc.Sql) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MssqlDialect(org.seasar.doma.jdbc.dialect.MssqlDialect) Emp_(org.seasar.doma.jdbc.criteria.entity.Emp_) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 12 with MockConfig

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

the class ScriptReaderTest method setUp.

@BeforeEach
public void setUp() {
    MockConfig config = new MockConfig();
    config.dialect = new Mssql2008Dialect();
    query = new SqlFileScriptQuery() {

        @Override
        public void prepare() {
        }
    };
    query.setConfig(config);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setBlockDelimiter(config.dialect.getScriptBlockDelimiter());
    query.prepare();
}
Also used : Mssql2008Dialect(org.seasar.doma.jdbc.dialect.Mssql2008Dialect) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) SqlFileScriptQuery(org.seasar.doma.jdbc.query.SqlFileScriptQuery) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with MockConfig

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

the class Db2ForUpdateTransformerTest method testForUpdateNormal.

@Test
public void testForUpdateNormal() {
    String expected = "select * from emp order by emp.id for update with rs";
    Db2ForUpdateTransformer transformer = new Db2ForUpdateTransformer(SelectForUpdateType.NORMAL, 0);
    SqlParser parser = new SqlParser("select * 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 : PreparedSql(org.seasar.doma.jdbc.PreparedSql) SqlParser(org.seasar.doma.internal.jdbc.sql.SqlParser) NodePreparedSqlBuilder(org.seasar.doma.internal.jdbc.sql.NodePreparedSqlBuilder) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) SqlNode(org.seasar.doma.jdbc.SqlNode) Test(org.junit.jupiter.api.Test)

Example 14 with MockConfig

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

the class EntityProviderTest method testGetEntity.

@Test
public void testGetEntity() throws Exception {
    MockResultSetMetaData metaData = new MockResultSetMetaData();
    metaData.columns.add(new ColumnMetaData("id"));
    metaData.columns.add(new ColumnMetaData("name"));
    metaData.columns.add(new ColumnMetaData("salary"));
    metaData.columns.add(new ColumnMetaData("version"));
    MockResultSet resultSet = new MockResultSet(metaData);
    resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100));
    resultSet.next();
    _Emp entityType = _Emp.getSingletonInternal();
    EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
    Emp emp = provider.get(resultSet);
    assertEquals(1, emp.getId());
    assertEquals("aaa", emp.getName());
    assertEquals(new BigDecimal(10), emp.getSalary());
    assertEquals(100, emp.getVersion());
}
Also used : RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) example.entity._Emp(example.entity._Emp) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 15 with MockConfig

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

the class EntityProviderTest method testGetEntity_UnknownColumnException.

@Test
public void testGetEntity_UnknownColumnException() throws Exception {
    MockResultSetMetaData metaData = new MockResultSetMetaData();
    metaData.columns.add(new ColumnMetaData("id"));
    metaData.columns.add(new ColumnMetaData("name"));
    metaData.columns.add(new ColumnMetaData("salary"));
    metaData.columns.add(new ColumnMetaData("version"));
    metaData.columns.add(new ColumnMetaData("unknown"));
    MockResultSet resultSet = new MockResultSet(metaData);
    resultSet.rows.add(new RowData(1, "aaa", new BigDecimal(10), 100, "bbb"));
    resultSet.next();
    _Emp entityType = _Emp.getSingletonInternal();
    EntityProvider<Emp> provider = new EntityProvider<>(entityType, new MySelectQuery(new MockConfig()), false);
    try {
        provider.get(resultSet);
        fail();
    } catch (UnknownColumnException expected) {
    }
}
Also used : UnknownColumnException(org.seasar.doma.jdbc.UnknownColumnException) RowData(org.seasar.doma.internal.jdbc.mock.RowData) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) example.entity._Emp(example.entity._Emp) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) BigDecimal(java.math.BigDecimal) 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