use of org.seasar.doma.wrapper.StringWrapper in project doma by domaframework.
the class BasicResultListHandlerTest method testHandle_NonSingleColumnException.
@Test
public void testHandle_NonSingleColumnException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("x"));
metaData.columns.add(new ColumnMetaData("y"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("aaa", "bbb"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setResultEnsured(true);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BasicResultListHandler<String> handler = new BasicResultListHandler<>(StringWrapper::new);
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonSingleColumnException expected) {
}
}
use of org.seasar.doma.wrapper.StringWrapper in project doma by domaframework.
the class BasicSingleResultHandlerTest method testHandle_NonUniqueResultException.
@Test
public void testHandle_NonUniqueResultException() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("x"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("aaa"));
resultSet.rows.add(new RowData("bbb"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BasicSingleResultHandler<String> handler = new BasicSingleResultHandler<>(StringWrapper::new);
try {
handler.handle(resultSet, query, (i, next) -> {
});
fail();
} catch (NonUniqueResultException ignore) {
}
}
use of org.seasar.doma.wrapper.StringWrapper in project doma by domaframework.
the class PreparedSqlBuilderTest method testAppend.
@Test
public void testAppend() {
PreparedSqlBuilder builder = new PreparedSqlBuilder(config, SqlKind.SELECT, SqlLogType.FORMATTED);
builder.appendSql("select * from aaa where name = ");
Wrapper<String> stringWrapper = new StringWrapper("hoge");
builder.appendParameter(new BasicInParameter<>(() -> stringWrapper));
builder.appendSql(" and salary = ");
Wrapper<BigDecimal> bigDecimalWrapper = new BigDecimalWrapper(new BigDecimal(100));
builder.appendParameter(new BasicInParameter<>(() -> bigDecimalWrapper));
PreparedSql sql = builder.build(Function.identity());
assertEquals("select * from aaa where name = ? and salary = ?", sql.toString());
}
use of org.seasar.doma.wrapper.StringWrapper in project doma by domaframework.
the class BuiltinTableIdGenerator method initialize.
@Override
public void initialize() {
if (qualifiedTableName == null) {
throw new JdbcException(Message.DOMA2033, "qualifiedTableName");
}
if (pkColumnName == null) {
throw new JdbcException(Message.DOMA2033, "pkColumnName");
}
if (pkColumnValue == null) {
throw new JdbcException(Message.DOMA2033, "pkColumnValue");
}
if (valueColumnName == null) {
throw new JdbcException(Message.DOMA2033, "valueColumnName");
}
LongWrapper allocationSizeWrapper = new LongWrapper();
allocationSizeWrapper.set(allocationSize);
StringWrapper pkColumnValueWrapper = new StringWrapper();
pkColumnValueWrapper.set(pkColumnValue);
updateSql = new PreparedSql(SqlKind.UPDATE, createUpdateRawSql(), createUpdateFormattedSql(), null, Arrays.asList(new BasicInParameter<>(() -> allocationSizeWrapper), new BasicInParameter<>(() -> pkColumnValueWrapper)), SqlLogType.FORMATTED);
selectSql = new PreparedSql(SqlKind.SELECT, createSelectRawSql(), createSelectFormattedSql(), null, Collections.singletonList(new BasicInParameter<>(() -> pkColumnValueWrapper)), SqlLogType.FORMATTED);
}
use of org.seasar.doma.wrapper.StringWrapper in project doma by domaframework.
the class BasicResultListHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
MockResultSetMetaData metaData = new MockResultSetMetaData();
metaData.columns.add(new ColumnMetaData("x"));
MockResultSet resultSet = new MockResultSet(metaData);
resultSet.rows.add(new RowData("aaa"));
resultSet.rows.add(new RowData("bbb"));
SqlFileSelectQuery query = new SqlFileSelectQuery();
query.setConfig(runtimeConfig);
query.setSqlFilePath(SqlFileUtil.buildPath(getClass().getName(), method.getName()));
query.setCallerClassName("aaa");
query.setCallerMethodName("bbb");
query.setMethod(method);
query.setSqlLogType(SqlLogType.FORMATTED);
query.prepare();
BasicResultListHandler<String> handler = new BasicResultListHandler<>(StringWrapper::new);
List<String> results = handler.handle(resultSet, query, (i, next) -> {
}).get();
assertEquals(2, results.size());
assertEquals("aaa", results.get(0));
assertEquals("bbb", results.get(1));
}
Aggregations