Search in sources :

Example 76 with Emp

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

the class SelectBuilderTest method testGetResultList_Entity.

@Test
public void testGetResultList_Entity() {
    SelectBuilder builder = SelectBuilder.newInstance(new MockConfig());
    builder.sql("select * from Emp");
    builder.sql("where");
    builder.sql("aaa = ").param(String.class, "aaa");
    builder.sql("and");
    builder.sql("bbb = ").param(int.class, 100);
    List<Emp> list = builder.getEntityResultList(Emp.class);
    assertNotNull(list);
}
Also used : Emp(example.entity.Emp) MockConfig(org.seasar.doma.internal.jdbc.mock.MockConfig) Test(org.junit.jupiter.api.Test)

Example 77 with Emp

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

the class BatchDeleteCommandTest method testExecute.

@Test
public void testExecute() throws Exception {
    Emp emp1 = new Emp();
    emp1.setId(1);
    emp1.setName("hoge");
    emp1.setVersion(10);
    Emp emp2 = new Emp();
    emp2.setId(2);
    emp2.setName("foo");
    emp2.setVersion(20);
    AutoBatchDeleteQuery<Emp> query = new AutoBatchDeleteQuery<>(_Emp.getSingletonInternal());
    query.setMethod(getClass().getDeclaredMethod(method.getName()));
    query.setConfig(runtimeConfig);
    query.setEntities(Arrays.asList(emp1, emp2));
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    int[] rows = new BatchDeleteCommand(query).execute();
    query.complete();
    assertEquals(2, rows.length);
    String sql = runtimeConfig.dataSource.connection.preparedStatement.sql;
    assertEquals("delete from EMP where ID = ? and VERSION = ?", sql);
}
Also used : AutoBatchDeleteQuery(org.seasar.doma.jdbc.query.AutoBatchDeleteQuery) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) Test(org.junit.jupiter.api.Test)

Example 78 with Emp

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

the class EmpDaoImpl method delete.

@Override
public int delete(Emp entity) {
    AutoDeleteQuery<Emp> query = __support.getQueryImplementors().createAutoDeleteQuery(method5, _Emp.getSingletonInternal());
    query.setConfig(__support.getConfig());
    query.setEntity(entity);
    query.setCallerClassName("example.dao.EmpDao");
    query.setCallerMethodName("delete");
    query.prepare();
    DeleteCommand command = __support.getCommandImplementors().createDeleteCommand(method5, query);
    return command.execute();
}
Also used : DeleteCommand(org.seasar.doma.jdbc.command.DeleteCommand) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp)

Example 79 with Emp

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

the class EmpDaoImpl method selectById.

@Override
public Emp selectById(Integer id, SelectOptions option) {
    SqlFileSelectQuery query = __support.getQueryImplementors().createSqlFileSelectQuery(method0);
    query.setConfig(__support.getConfig());
    query.setSqlFilePath(SqlFileUtil.buildPath("example.dao.EmpDao", "selectById"));
    query.addParameter("id", Integer.class, id);
    query.setOptions(option);
    query.setCallerClassName("example.dao.EmpDao");
    query.setCallerMethodName("selectById");
    query.prepare();
    SelectCommand<Emp> command = __support.getCommandImplementors().createSelectCommand(method0, query, new EntitySingleResultHandler<Emp>(_Emp.getSingletonInternal()));
    return command.execute();
}
Also used : SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp)

Example 80 with Emp

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

the class EmpDaoImpl method selectByNameAndSalary.

@Override
public List<Emp> selectByNameAndSalary(String name, BigDecimal salary, SelectOptions option) {
    SqlFileSelectQuery query = __support.getQueryImplementors().createSqlFileSelectQuery(method1);
    query.setConfig(__support.getConfig());
    query.setSqlFilePath(SqlFileUtil.buildPath("example.dao.EmpDao", "selectByNameAndSalary"));
    query.addParameter("name", String.class, name);
    query.addParameter("salary", BigDecimal.class, salary);
    query.setOptions(option);
    query.setCallerClassName("example.dao.EmpDao");
    query.setCallerMethodName("selectByNameAndSalary");
    query.prepare();
    SelectCommand<List<Emp>> command = __support.getCommandImplementors().createSelectCommand(method1, query, new EntityResultListHandler<Emp>(_Emp.getSingletonInternal()));
    return command.execute();
}
Also used : SqlFileSelectQuery(org.seasar.doma.jdbc.query.SqlFileSelectQuery) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) List(java.util.List)

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