Search in sources :

Example 11 with OptimisticLockException

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

the class DeleteCommandTest method testExecute_throwsOptimisticLockException.

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

Example 12 with OptimisticLockException

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

the class AutoBatchUpdateTest method testTenantId.

@Test
public void testTenantId(Config config) throws Exception {
    SalesmanDao dao = new SalesmanDaoImpl(config);
    Salesman salesman = dao.selectById(1);
    Integer tenantId = salesman.departmentId;
    salesman.departmentId = -1;
    try {
        dao.update(Arrays.asList(salesman));
        fail();
    } catch (OptimisticLockException expected) {
    }
    salesman.departmentId = tenantId;
    dao.update(Arrays.asList(salesman));
}
Also used : Salesman(org.seasar.doma.it.entity.Salesman) SalesmanDao(org.seasar.doma.it.dao.SalesmanDao) SalesmanDaoImpl(org.seasar.doma.it.dao.SalesmanDaoImpl) OptimisticLockException(org.seasar.doma.jdbc.OptimisticLockException) Test(org.junit.jupiter.api.Test)

Example 13 with OptimisticLockException

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

the class AutoDeleteTest method testTenantId.

@Test
public void testTenantId(Config config) throws Exception {
    SalesmanDao dao = new SalesmanDaoImpl(config);
    Salesman salesman = dao.selectById(1);
    Integer tenantId = salesman.departmentId;
    salesman.departmentId = -1;
    try {
        dao.delete(salesman);
        fail();
    } catch (OptimisticLockException expected) {
    }
    salesman.departmentId = tenantId;
    dao.delete(salesman);
}
Also used : Salesman(org.seasar.doma.it.entity.Salesman) SalesmanDao(org.seasar.doma.it.dao.SalesmanDao) SalesmanDaoImpl(org.seasar.doma.it.dao.SalesmanDaoImpl) 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