Search in sources :

Example 6 with OptimisticLockException

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

the class AutoBatchDeleteTest method testOptimisticLockException.

@Test
public void testOptimisticLockException(Config config) throws Exception {
    EmployeeDao dao = new EmployeeDaoImpl(config);
    Employee employee1 = dao.selectById(1);
    employee1.setEmployeeName("hoge");
    Employee employee2 = dao.selectById(2);
    employee2.setEmployeeName("foo");
    Employee employee3 = dao.selectById(1);
    employee2.setEmployeeName("bar");
    dao.delete(employee1);
    try {
        dao.delete(Arrays.asList(employee2, employee3));
        fail();
    } catch (OptimisticLockException expected) {
    }
}
Also used : EmployeeDao(org.seasar.doma.it.dao.EmployeeDao) CompKeyEmployeeDao(org.seasar.doma.it.dao.CompKeyEmployeeDao) CompKeyEmployee(org.seasar.doma.it.entity.CompKeyEmployee) Employee(org.seasar.doma.it.entity.Employee) OptimisticLockException(org.seasar.doma.jdbc.OptimisticLockException) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) CompKeyEmployeeDaoImpl(org.seasar.doma.it.dao.CompKeyEmployeeDaoImpl) Test(org.junit.jupiter.api.Test)

Example 7 with OptimisticLockException

use of org.seasar.doma.jdbc.OptimisticLockException 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 8 with OptimisticLockException

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

the class UpdateCommandTest method testExecute_throwsOptimisticLockException.

@Test
public void testExecute_throwsOptimisticLockException() throws Exception {
    Emp emp = new Emp();
    emp.setId(10);
    emp.setName("aaa");
    emp.setVersion(100);
    runtimeConfig.dataSource.connection.preparedStatement.updatedRows = 0;
    AutoUpdateQuery<Emp> query = new AutoUpdateQuery<>(_Emp.getSingletonInternal());
    query.setMethod(getClass().getDeclaredMethod(method.getName()));
    query.setConfig(runtimeConfig);
    query.setEntity(emp);
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    UpdateCommand command = new UpdateCommand(query);
    try {
        command.execute();
        fail();
    } catch (OptimisticLockException expected) {
    }
}
Also used : Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) OptimisticLockException(org.seasar.doma.jdbc.OptimisticLockException) AutoUpdateQuery(org.seasar.doma.jdbc.query.AutoUpdateQuery) Test(org.junit.jupiter.api.Test)

Example 9 with OptimisticLockException

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

the class AutoUpdateTest 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.update(department1);
    try {
        dao.update(department2);
        fail();
    } catch (OptimisticLockException expected) {
    }
}
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) OptimisticLockException(org.seasar.doma.jdbc.OptimisticLockException) DepartmentDao(org.seasar.doma.it.dao.DepartmentDao) CompKeyDepartmentDao(org.seasar.doma.it.dao.CompKeyDepartmentDao) Test(org.junit.jupiter.api.Test)

Example 10 with OptimisticLockException

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

the class BatchUpdateCommandTest method testExecute_throwsOptimisticLockException.

@Test
public void testExecute_throwsOptimisticLockException() {
    Emp emp = new Emp();
    emp.setId(1);
    emp.setName("hoge");
    emp.setVersion(10);
    runtimeConfig.dataSource.connection.preparedStatement.updatedRows = 0;
    AutoBatchUpdateQuery<Emp> query = new AutoBatchUpdateQuery<>(_Emp.getSingletonInternal());
    query.setMethod(method);
    query.setConfig(runtimeConfig);
    query.setEntities(Collections.singletonList(emp));
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    BatchUpdateCommand command = new BatchUpdateCommand(query);
    try {
        command.execute();
        fail();
    } catch (OptimisticLockException expected) {
    }
}
Also used : AutoBatchUpdateQuery(org.seasar.doma.jdbc.query.AutoBatchUpdateQuery) Emp(example.entity.Emp) example.entity._Emp(example.entity._Emp) OptimisticLockException(org.seasar.doma.jdbc.OptimisticLockException) Test(org.junit.jupiter.api.Test)

Aggregations

OptimisticLockException (org.seasar.doma.jdbc.OptimisticLockException)13 Test (org.junit.jupiter.api.Test)12 SalesmanDao (org.seasar.doma.it.dao.SalesmanDao)4 SalesmanDaoImpl (org.seasar.doma.it.dao.SalesmanDaoImpl)4 Salesman (org.seasar.doma.it.entity.Salesman)4 Emp (example.entity.Emp)3 example.entity._Emp (example.entity._Emp)3 DepartmentDao (org.seasar.doma.it.dao.DepartmentDao)3 DepartmentDaoImpl (org.seasar.doma.it.dao.DepartmentDaoImpl)3 Department (org.seasar.doma.it.entity.Department)3 CompKeyDepartmentDao (org.seasar.doma.it.dao.CompKeyDepartmentDao)2 CompKeyDepartmentDaoImpl (org.seasar.doma.it.dao.CompKeyDepartmentDaoImpl)2 CompKeyEmployeeDao (org.seasar.doma.it.dao.CompKeyEmployeeDao)2 CompKeyEmployeeDaoImpl (org.seasar.doma.it.dao.CompKeyEmployeeDaoImpl)2 EmployeeDao (org.seasar.doma.it.dao.EmployeeDao)2 EmployeeDaoImpl (org.seasar.doma.it.dao.EmployeeDaoImpl)2 CompKeyDepartment (org.seasar.doma.it.entity.CompKeyDepartment)2 CompKeyEmployee (org.seasar.doma.it.entity.CompKeyEmployee)2 Employee (org.seasar.doma.it.entity.Employee)2 SQLException (java.sql.SQLException)1