Search in sources :

Example 26 with DepartmentDao

use of org.seasar.doma.it.dao.DepartmentDao in project doma by domaframework.

the class SqlFileBatchInsertTest method test.

@Test
public void test(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department = new Department();
    department.setDepartmentId(new Identity<Department>(99));
    department.setDepartmentNo(99);
    department.setDepartmentName("hoge");
    Department department2 = new Department();
    department2.setDepartmentId(new Identity<Department>(98));
    department2.setDepartmentNo(98);
    department2.setDepartmentName("foo");
    int[] result = dao.insertBySqlFile(Arrays.asList(department, department2));
    assertEquals(2, result.length);
    assertEquals(1, result[0]);
    assertEquals(1, result[1]);
    department = dao.selectById(99);
    assertEquals(Integer.valueOf(99), department.getDepartmentId().getValue());
    assertEquals(Integer.valueOf(99), department.getDepartmentNo());
    department = dao.selectById(98);
    assertEquals(Integer.valueOf(98), department.getDepartmentId().getValue());
    assertEquals(Integer.valueOf(98), department.getDepartmentNo());
}
Also used : DepartmentDaoImpl(org.seasar.doma.it.dao.DepartmentDaoImpl) Department(org.seasar.doma.it.entity.Department) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) Test(org.junit.jupiter.api.Test)

Example 27 with DepartmentDao

use of org.seasar.doma.it.dao.DepartmentDao in project doma by domaframework.

the class AutoBatchUpdateTest method testSqlExecutionSkip.

@Test
public void testSqlExecutionSkip(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    int[] result = dao.update(new ArrayList<Department>());
    assertEquals(0, result.length);
}
Also used : DepartmentDaoImpl(org.seasar.doma.it.dao.DepartmentDaoImpl) CompKeyDepartmentDaoImpl(org.seasar.doma.it.dao.CompKeyDepartmentDaoImpl) Department(org.seasar.doma.it.entity.Department) CompKeyDepartment(org.seasar.doma.it.entity.CompKeyDepartment) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) CompKeyDepartmentDao(org.seasar.doma.it.dao.CompKeyDepartmentDao) Test(org.junit.jupiter.api.Test)

Example 28 with DepartmentDao

use of org.seasar.doma.it.dao.DepartmentDao in project doma by domaframework.

the class AutoBatchUpdateTest method testSuppressOptimisticLockException.

@Test
public void testSuppressOptimisticLockException(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department1 = dao.selectById(1);
    department1.setDepartmentName("hoge");
    Department department2 = dao.selectById(2);
    department2.setDepartmentName("foo");
    Department department3 = dao.selectById(1);
    department3.setDepartmentName("bar");
    dao.update(department1);
    dao.update_suppressOptimisticLockException(Arrays.asList(department2, department3));
}
Also used : DepartmentDaoImpl(org.seasar.doma.it.dao.DepartmentDaoImpl) CompKeyDepartmentDaoImpl(org.seasar.doma.it.dao.CompKeyDepartmentDaoImpl) Department(org.seasar.doma.it.entity.Department) CompKeyDepartment(org.seasar.doma.it.entity.CompKeyDepartment) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) CompKeyDepartmentDao(org.seasar.doma.it.dao.CompKeyDepartmentDao) Test(org.junit.jupiter.api.Test)

Example 29 with DepartmentDao

use of org.seasar.doma.it.dao.DepartmentDao in project doma by domaframework.

the class AutoInsertTest method test.

@Test
public void test(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department = new Department();
    department.setDepartmentId(new Identity<Department>(99));
    department.setDepartmentNo(99);
    department.setDepartmentName("hoge");
    department.setLocation(new Location<Department>("foo"));
    int result = dao.insert(department);
    assertEquals(1, result);
    assertEquals(Integer.valueOf(1), department.getVersion());
    department = dao.selectById(Integer.valueOf(99));
    assertEquals(Integer.valueOf(99), department.getDepartmentId().getValue());
    assertEquals(Integer.valueOf(99), department.getDepartmentNo());
    assertEquals("hoge", department.getDepartmentName());
    assertEquals("foo", department.getLocation().getValue());
    assertEquals(Integer.valueOf(1), department.getVersion());
}
Also used : DepartmentDaoImpl(org.seasar.doma.it.dao.DepartmentDaoImpl) CompKeyDepartmentDaoImpl(org.seasar.doma.it.dao.CompKeyDepartmentDaoImpl) Department(org.seasar.doma.it.entity.Department) CompKeyDepartment(org.seasar.doma.it.entity.CompKeyDepartment) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) CompKeyDepartmentDao(org.seasar.doma.it.dao.CompKeyDepartmentDao) Test(org.junit.jupiter.api.Test)

Example 30 with DepartmentDao

use of org.seasar.doma.it.dao.DepartmentDao in project doma by domaframework.

the class AutoInsertTest method testIdNotAssigned.

@Test
public void testIdNotAssigned(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department = new Department();
    department.setDepartmentNo(99);
    department.setDepartmentName("hoge");
    try {
        dao.insert(department);
        fail();
    } catch (JdbcException expected) {
        assertEquals(Message.DOMA2020, expected.getMessageResource());
    }
}
Also used : DepartmentDaoImpl(org.seasar.doma.it.dao.DepartmentDaoImpl) CompKeyDepartmentDaoImpl(org.seasar.doma.it.dao.CompKeyDepartmentDaoImpl) Department(org.seasar.doma.it.entity.Department) CompKeyDepartment(org.seasar.doma.it.entity.CompKeyDepartment) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) CompKeyDepartmentDao(org.seasar.doma.it.dao.CompKeyDepartmentDao) JdbcException(org.seasar.doma.jdbc.JdbcException) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)31 DepartmentDao (org.seasar.doma.it.dao.DepartmentDao)31 DepartmentDaoImpl (org.seasar.doma.it.dao.DepartmentDaoImpl)31 Department (org.seasar.doma.it.entity.Department)31 CompKeyDepartmentDao (org.seasar.doma.it.dao.CompKeyDepartmentDao)17 CompKeyDepartmentDaoImpl (org.seasar.doma.it.dao.CompKeyDepartmentDaoImpl)17 CompKeyDepartment (org.seasar.doma.it.entity.CompKeyDepartment)17 Employee (org.seasar.doma.it.entity.Employee)4 OptimisticLockException (org.seasar.doma.jdbc.OptimisticLockException)3 ArrayList (java.util.ArrayList)2 Run (org.seasar.doma.it.Run)2 FunctionDao (org.seasar.doma.it.dao.FunctionDao)2 FunctionDaoImpl (org.seasar.doma.it.dao.FunctionDaoImpl)2 ProcedureDao (org.seasar.doma.it.dao.ProcedureDao)2 ProcedureDaoImpl (org.seasar.doma.it.dao.ProcedureDaoImpl)2 JdbcException (org.seasar.doma.jdbc.JdbcException)2 BatchOptimisticLockException (org.seasar.doma.jdbc.BatchOptimisticLockException)1 UniqueConstraintException (org.seasar.doma.jdbc.UniqueConstraintException)1