Search in sources :

Example 16 with Department

use of org.seasar.doma.it.entity.Department in project doma by domaframework.

the class AutoBatchInsertTest 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");
    Department department2 = new Department();
    department2.setDepartmentNo(98);
    department2.setDepartmentName("hoge");
    try {
        dao.insert(Arrays.asList(department, department2));
        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)

Example 17 with Department

use of org.seasar.doma.it.entity.Department in project doma by domaframework.

the class SqlFileUpdateTest method testOptimisticLockException.

@Test
public void testOptimisticLockException(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department1 = dao.selectById(1);
    department1.setDepartmentName("hoge");
    Department department2 = dao.selectById(1);
    department2.setDepartmentName("foo");
    dao.updateBySqlFile(department1);
    try {
        dao.updateBySqlFile(department2);
        fail();
    } catch (OptimisticLockException expected) {
    }
}
Also used : DepartmentDaoImpl(org.seasar.doma.it.dao.DepartmentDaoImpl) Department(org.seasar.doma.it.entity.Department) OptimisticLockException(org.seasar.doma.jdbc.OptimisticLockException) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) Test(org.junit.jupiter.api.Test)

Example 18 with Department

use of org.seasar.doma.it.entity.Department in project doma by domaframework.

the class SqlFileUpdateTest method testPopulates.

@Test
public void testPopulates(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department = new Department();
    department.setDepartmentId(new Identity<Department>(1));
    department.setDepartmentNo(1);
    department.setDepartmentName("hoge");
    department.setVersion(1);
    int result = dao.updateBySqlFileWithPopulate(department);
    assertEquals(1, result);
    department = dao.selectById(1);
    assertEquals(Integer.valueOf(1), department.getDepartmentId().getValue());
    assertEquals("hoge", department.getDepartmentName());
    assertEquals(Integer.valueOf(2), department.getVersion());
}
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 19 with Department

use of org.seasar.doma.it.entity.Department in project doma by domaframework.

the class SqlFileUpdateTest method test.

@Test
public void test(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department = new Department();
    department.setDepartmentId(new Identity<Department>(1));
    department.setDepartmentNo(1);
    department.setDepartmentName("hoge");
    department.setVersion(1);
    int result = dao.updateBySqlFile(department);
    assertEquals(1, result);
    department = dao.selectById(1);
    assertEquals(Integer.valueOf(1), department.getDepartmentId().getValue());
    assertEquals("hoge", department.getDepartmentName());
    assertEquals(Integer.valueOf(2), department.getVersion());
}
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 20 with Department

use of org.seasar.doma.it.entity.Department in project doma by domaframework.

the class SqlFileUpdateTest method test_nonEntity.

@Test
public void test_nonEntity(Config config) throws Exception {
    DepartmentDao dao = new DepartmentDaoImpl(config);
    Department department = new Department();
    department.setDepartmentId(new Identity<Department>(1));
    department.setDepartmentNo(1);
    department.setDepartmentName("hoge");
    department.setVersion(1);
    int result = dao.updateBySqlFile_nonEntity(new Identity<Department>(1), 1, "hoge", null, 1);
    assertEquals(1, result);
    department = dao.selectById(1);
    assertEquals(Integer.valueOf(1), department.getDepartmentId().getValue());
    assertEquals("hoge", department.getDepartmentName());
    assertEquals(Integer.valueOf(2), department.getVersion());
}
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)

Aggregations

Test (org.junit.jupiter.api.Test)33 Department (org.seasar.doma.it.entity.Department)33 DepartmentDao (org.seasar.doma.it.dao.DepartmentDao)31 DepartmentDaoImpl (org.seasar.doma.it.dao.DepartmentDaoImpl)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)6 ArrayList (java.util.ArrayList)4 ProcedureDao (org.seasar.doma.it.dao.ProcedureDao)4 ProcedureDaoImpl (org.seasar.doma.it.dao.ProcedureDaoImpl)4 OptimisticLockException (org.seasar.doma.jdbc.OptimisticLockException)3 Run (org.seasar.doma.it.Run)2 FunctionDao (org.seasar.doma.it.dao.FunctionDao)2 FunctionDaoImpl (org.seasar.doma.it.dao.FunctionDaoImpl)2 JdbcException (org.seasar.doma.jdbc.JdbcException)2 BatchOptimisticLockException (org.seasar.doma.jdbc.BatchOptimisticLockException)1 Reference (org.seasar.doma.jdbc.Reference)1 UniqueConstraintException (org.seasar.doma.jdbc.UniqueConstraintException)1