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());
}
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();
}
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());
}
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());
}
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) {
}
}
Aggregations