Search in sources :

Example 1 with IterationCallback

use of org.seasar.doma.jdbc.IterationCallback in project doma by domaframework.

the class EntityIterationHandlerTest method testHandle.

@Test
public void testHandle() throws Exception {
    MockResultSetMetaData metaData = new MockResultSetMetaData();
    metaData.columns.add(new ColumnMetaData("id"));
    metaData.columns.add(new ColumnMetaData("name"));
    MockResultSet resultSet = new MockResultSet(metaData);
    resultSet.rows.add(new RowData(1, "aaa"));
    resultSet.rows.add(new RowData(2, "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();
    EntityIterationHandler<Emp, Integer> handler = new EntityIterationHandler<>(_Emp.getSingletonInternal(), new IterationCallback<Emp, Integer>() {

        private int count;

        @Override
        public Integer iterate(Emp target, IterationContext iterationContext) {
            count++;
            return count;
        }
    });
    Integer result = handler.handle(resultSet, query, (i, next) -> {
    }).get();
    assertEquals(new Integer(2), result);
}
Also used : 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) Emp(example.entity.Emp) IterationCallback(org.seasar.doma.jdbc.IterationCallback) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) IterationContext(org.seasar.doma.jdbc.IterationContext) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) SqlLogType(org.seasar.doma.jdbc.SqlLogType) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) example.entity._Emp(example.entity._Emp) 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) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) RowData(org.seasar.doma.internal.jdbc.mock.RowData) IterationContext(org.seasar.doma.jdbc.IterationContext) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Example 2 with IterationCallback

use of org.seasar.doma.jdbc.IterationCallback in project doma by domaframework.

the class EntityIterationHandlerTest method testHandle_exits.

@Test
public void testHandle_exits() throws Exception {
    MockResultSetMetaData metaData = new MockResultSetMetaData();
    metaData.columns.add(new ColumnMetaData("id"));
    metaData.columns.add(new ColumnMetaData("name"));
    MockResultSet resultSet = new MockResultSet(metaData);
    resultSet.rows.add(new RowData(1, "aaa"));
    resultSet.rows.add(new RowData(2, "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();
    EntityIterationHandler<Emp, Integer> handler = new EntityIterationHandler<>(_Emp.getSingletonInternal(), new IterationCallback<Emp, Integer>() {

        private int count;

        @Override
        public Integer iterate(Emp target, IterationContext iterationContext) {
            iterationContext.exit();
            count++;
            return count;
        }
    });
    Integer result = handler.handle(resultSet, query, (i, next) -> {
    }).get();
    assertEquals(new Integer(1), result);
}
Also used : 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) Emp(example.entity.Emp) IterationCallback(org.seasar.doma.jdbc.IterationCallback) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) IterationContext(org.seasar.doma.jdbc.IterationContext) TestInfo(org.junit.jupiter.api.TestInfo) Test(org.junit.jupiter.api.Test) SqlLogType(org.seasar.doma.jdbc.SqlLogType) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) example.entity._Emp(example.entity._Emp) 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) SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) MockResultSetMetaData(org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) MockResultSet(org.seasar.doma.internal.jdbc.mock.MockResultSet) RowData(org.seasar.doma.internal.jdbc.mock.RowData) IterationContext(org.seasar.doma.jdbc.IterationContext) ColumnMetaData(org.seasar.doma.internal.jdbc.mock.ColumnMetaData) Test(org.junit.jupiter.api.Test)

Aggregations

Emp (example.entity.Emp)2 example.entity._Emp (example.entity._Emp)2 Method (java.lang.reflect.Method)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 TestInfo (org.junit.jupiter.api.TestInfo)2 ColumnMetaData (org.seasar.doma.internal.jdbc.mock.ColumnMetaData)2 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)2 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)2 MockResultSetMetaData (org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData)2 RowData (org.seasar.doma.internal.jdbc.mock.RowData)2 SqlFileUtil (org.seasar.doma.internal.jdbc.util.SqlFileUtil)2 IterationCallback (org.seasar.doma.jdbc.IterationCallback)2 IterationContext (org.seasar.doma.jdbc.IterationContext)2 SqlLogType (org.seasar.doma.jdbc.SqlLogType)2 SqlFileSelectQuery (org.seasar.doma.jdbc.query.SqlFileSelectQuery)2