Search in sources :

Example 1 with StringWrapper

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) {
    }
}
Also used : StringWrapper(org.seasar.doma.wrapper.StringWrapper) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) NonSingleColumnException(org.seasar.doma.jdbc.NonSingleColumnException) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 2 with StringWrapper

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) {
    }
}
Also used : NonUniqueResultException(org.seasar.doma.jdbc.NonUniqueResultException) StringWrapper(org.seasar.doma.wrapper.StringWrapper) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 3 with StringWrapper

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());
}
Also used : StringWrapper(org.seasar.doma.wrapper.StringWrapper) PreparedSql(org.seasar.doma.jdbc.PreparedSql) BigDecimalWrapper(org.seasar.doma.wrapper.BigDecimalWrapper) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 4 with StringWrapper

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);
}
Also used : StringWrapper(org.seasar.doma.wrapper.StringWrapper) PreparedSql(org.seasar.doma.jdbc.PreparedSql) LongWrapper(org.seasar.doma.wrapper.LongWrapper) JdbcException(org.seasar.doma.jdbc.JdbcException)

Example 5 with StringWrapper

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));
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) SqlFileUtil(org.seasar.doma.internal.jdbc.util.SqlFileUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) StringWrapper(org.seasar.doma.wrapper.StringWrapper) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) List(java.util.List) SqlLogType(org.seasar.doma.jdbc.SqlLogType) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Method(java.lang.reflect.Method) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) NonSingleColumnException(org.seasar.doma.jdbc.NonSingleColumnException) StringWrapper(org.seasar.doma.wrapper.StringWrapper) RowData(org.seasar.doma.internal.jdbc.mock.RowData) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Aggregations

StringWrapper (org.seasar.doma.wrapper.StringWrapper)7 Test (org.junit.jupiter.api.Test)6 ColumnMetaData (org.seasar.doma.internal.jdbc.mock.ColumnMetaData)5 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)5 MockResultSetMetaData (org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData)5 RowData (org.seasar.doma.internal.jdbc.mock.RowData)5 SqlFileSelectQuery (org.seasar.doma.jdbc.query.SqlFileSelectQuery)5 NonSingleColumnException (org.seasar.doma.jdbc.NonSingleColumnException)4 Method (java.lang.reflect.Method)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.fail (org.junit.jupiter.api.Assertions.fail)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TestInfo (org.junit.jupiter.api.TestInfo)2 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)2 SqlFileUtil (org.seasar.doma.internal.jdbc.util.SqlFileUtil)2 NonUniqueResultException (org.seasar.doma.jdbc.NonUniqueResultException)2 PreparedSql (org.seasar.doma.jdbc.PreparedSql)2 SqlLogType (org.seasar.doma.jdbc.SqlLogType)2 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1