Search in sources :

Example 21 with Emp

use of example.entity.Emp in project doma by domaframework.

the class SqlFileUpdateQueryTest method testOriginalStates_unchanged.

@Test
public void testOriginalStates_unchanged() {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    emp.setSalary(BigDecimal.ZERO);
    emp.setVersion(100);
    emp.originalStates = new Emp();
    emp.originalStates.setId(emp.getId());
    emp.originalStates.setName(emp.getName());
    emp.originalStates.setSalary(emp.getSalary());
    emp.originalStates.setVersion(emp.getVersion());
    SqlFileUpdateQuery query = new SqlFileUpdateQuery();
    query.setMethod(method);
    query.setSqlFilePath("META-INF/org/seasar/doma/jdbc/query/SqlFileUpdateQueryTest/testOriginalStates.sql");
    query.setConfig(runtimeConfig);
    query.setEntityAndEntityType("emp", emp, _Emp.getSingletonInternal());
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.addParameter("emp", Emp.class, emp);
    query.prepare();
    PreparedSql sql = ((UpdateQuery) query).getSql();
    assertEquals("update aaa set VERSION = ? + 1 where id = ?", sql.getRawSql());
    assertEquals("update aaa set VERSION = 100 + 1 where id = 10", sql.getFormattedSql());
    List<? extends InParameter<?>> parameters = sql.getParameters();
    assertEquals(2, parameters.size());
    assertEquals(100, parameters.get(0).getWrapper().get());
    assertEquals(10, parameters.get(1).getWrapper().get());
    assertFalse(query.isExecutable());
}
Also used : PreparedSql(org.seasar.doma.jdbc.PreparedSql) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) Test(org.junit.jupiter.api.Test)

Example 22 with Emp

use of example.entity.Emp in project doma by domaframework.

the class SqlFileUpdateQueryTest method testPopulate_exclude.

@Test
public void testPopulate_exclude() {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    emp.setSalary(new BigDecimal(200));
    emp.setVersion(100);
    SqlFileUpdateQuery query = new SqlFileUpdateQuery();
    query.setMethod(method);
    query.setSqlFilePath("META-INF/org/seasar/doma/jdbc/query/SqlFileUpdateQueryTest/testPopulate.sql");
    query.setConfig(runtimeConfig);
    query.setEntityAndEntityType("emp", emp, _Emp.getSingletonInternal());
    query.setExcludedPropertyNames("name");
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.addParameter("emp", Emp.class, emp);
    query.prepare();
    PreparedSql sql = query.getSql();
    assertEquals("update aaa set SALARY = ?, VERSION = ? + 1 where id = ?", sql.getRawSql());
    List<InParameter<?>> parameters = sql.getParameters();
    assertEquals(3, parameters.size());
    assertEquals(new BigDecimal(200), parameters.get(0).getWrapper().get());
    assertEquals(100, parameters.get(1).getWrapper().get());
    assertEquals(10, parameters.get(2).getWrapper().get());
    assertEquals(100, parameters.get(1).getWrapper().get());
    assertTrue(query.isExecutable());
}
Also used : InParameter(org.seasar.doma.jdbc.InParameter) PreparedSql(org.seasar.doma.jdbc.PreparedSql) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 23 with Emp

use of example.entity.Emp in project doma by domaframework.

the class SqlFileUpdateQueryTest method testPopulate_include.

@Test
public void testPopulate_include() {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    emp.setSalary(new BigDecimal(200));
    emp.setVersion(100);
    SqlFileUpdateQuery query = new SqlFileUpdateQuery();
    query.setMethod(method);
    query.setSqlFilePath("META-INF/org/seasar/doma/jdbc/query/SqlFileUpdateQueryTest/testPopulate.sql");
    query.setConfig(runtimeConfig);
    query.setEntityAndEntityType("emp", emp, _Emp.getSingletonInternal());
    query.setIncludedPropertyNames("name");
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.addParameter("emp", Emp.class, emp);
    query.prepare();
    PreparedSql sql = query.getSql();
    assertEquals("update aaa set NAME = ?, VERSION = ? + 1 where id = ?", sql.getRawSql());
    List<InParameter<?>> parameters = sql.getParameters();
    assertEquals(3, parameters.size());
    assertEquals("aaa", parameters.get(0).getWrapper().get());
    assertEquals(100, parameters.get(1).getWrapper().get());
    assertEquals(10, parameters.get(2).getWrapper().get());
    assertTrue(query.isExecutable());
}
Also used : InParameter(org.seasar.doma.jdbc.InParameter) PreparedSql(org.seasar.doma.jdbc.PreparedSql) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 24 with Emp

use of example.entity.Emp 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 25 with Emp

use of example.entity.Emp 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)80 example.entity._Emp (example.entity._Emp)73 Test (org.junit.jupiter.api.Test)73 PreparedSql (org.seasar.doma.jdbc.PreparedSql)29 InParameter (org.seasar.doma.jdbc.InParameter)27 BigDecimal (java.math.BigDecimal)25 SqlFileSelectQuery (org.seasar.doma.jdbc.query.SqlFileSelectQuery)13 ColumnMetaData (org.seasar.doma.internal.jdbc.mock.ColumnMetaData)12 MockResultSet (org.seasar.doma.internal.jdbc.mock.MockResultSet)12 MockResultSetMetaData (org.seasar.doma.internal.jdbc.mock.MockResultSetMetaData)12 RowData (org.seasar.doma.internal.jdbc.mock.RowData)11 MockConfig (org.seasar.doma.internal.jdbc.mock.MockConfig)9 BindValue (org.seasar.doma.internal.jdbc.mock.BindValue)8 MockConnection (org.seasar.doma.internal.jdbc.mock.MockConnection)5 MockPreparedStatement (org.seasar.doma.internal.jdbc.mock.MockPreparedStatement)5 Method (java.lang.reflect.Method)4 List (java.util.List)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 TestInfo (org.junit.jupiter.api.TestInfo)4 SqlFileUtil (org.seasar.doma.internal.jdbc.util.SqlFileUtil)4