Search in sources :

Example 16 with Employee

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

the class SelectBuilderTest method testGetEntityResultList.

@Test
public void testGetEntityResultList(Config config) throws Exception {
    SelectBuilder builder = SelectBuilder.newInstance(config);
    builder.sql("select EMPLOYEE_ID, EMPLOYEE_NAME, HIREDATE from EMPLOYEE");
    List<Employee> employees = builder.getEntityResultList(Employee.class);
    assertEquals(14, employees.size());
    assertEquals("SMITH", employees.get(0).getEmployeeName());
}
Also used : Employee(org.seasar.doma.it.entity.Employee) SelectBuilder(org.seasar.doma.jdbc.builder.SelectBuilder) Test(org.junit.jupiter.api.Test)

Example 17 with Employee

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

the class SelectBuilderTest method testGetOptionalEntitySingleResult.

@Test
public void testGetOptionalEntitySingleResult(Config config) throws Exception {
    SelectBuilder builder = SelectBuilder.newInstance(config);
    builder.sql("select EMPLOYEE_ID, EMPLOYEE_NAME, HIREDATE from EMPLOYEE");
    builder.sql("where");
    builder.sql("EMPLOYEE_ID = ").param(int.class, 1);
    Optional<Employee> employee = builder.getOptionalEntitySingleResult(Employee.class);
    assertNotNull(employee);
    assertEquals("SMITH", employee.get().getEmployeeName());
}
Also used : Employee(org.seasar.doma.it.entity.Employee) SelectBuilder(org.seasar.doma.jdbc.builder.SelectBuilder) Test(org.junit.jupiter.api.Test)

Example 18 with Employee

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

the class SelectBuilderTest method testStreamEntity.

@Test
public void testStreamEntity(Config config) throws Exception {
    SelectBuilder builder = SelectBuilder.newInstance(config);
    builder.sql("select EMPLOYEE_ID, EMPLOYEE_NAME, HIREDATE from EMPLOYEE");
    Optional<Employee> employee = builder.streamEntity(Employee.class, stream -> stream.findFirst());
    assertEquals("SMITH", employee.get().getEmployeeName());
}
Also used : Employee(org.seasar.doma.it.entity.Employee) SelectBuilder(org.seasar.doma.jdbc.builder.SelectBuilder) Test(org.junit.jupiter.api.Test)

Example 19 with Employee

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

the class AutoBatchDeleteTest method test.

@Test
public void test(Config config) throws Exception {
    EmployeeDao dao = new EmployeeDaoImpl(config);
    Employee employee = new Employee();
    employee.setEmployeeId(1);
    employee.setVersion(1);
    Employee employee2 = new Employee();
    employee2.setEmployeeId(2);
    employee2.setVersion(1);
    int[] result = dao.delete(Arrays.asList(employee, employee2));
    assertEquals(2, result.length);
    assertEquals(1, result[0]);
    assertEquals(1, result[1]);
    employee = dao.selectById(1);
    assertNull(employee);
    employee = dao.selectById(2);
    assertNull(employee);
}
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) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) CompKeyEmployeeDaoImpl(org.seasar.doma.it.dao.CompKeyEmployeeDaoImpl) Test(org.junit.jupiter.api.Test)

Example 20 with Employee

use of org.seasar.doma.it.entity.Employee 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)

Aggregations

Employee (org.seasar.doma.it.entity.Employee)63 Test (org.junit.jupiter.api.Test)61 EmployeeDao (org.seasar.doma.it.dao.EmployeeDao)40 EmployeeDaoImpl (org.seasar.doma.it.dao.EmployeeDaoImpl)40 Run (org.seasar.doma.it.Run)11 ArrayList (java.util.ArrayList)8 CompKeyEmployeeDao (org.seasar.doma.it.dao.CompKeyEmployeeDao)8 CompKeyEmployeeDaoImpl (org.seasar.doma.it.dao.CompKeyEmployeeDaoImpl)8 ProcedureDao (org.seasar.doma.it.dao.ProcedureDao)8 ProcedureDaoImpl (org.seasar.doma.it.dao.ProcedureDaoImpl)8 CompKeyEmployee (org.seasar.doma.it.entity.CompKeyEmployee)8 SelectBuilder (org.seasar.doma.jdbc.builder.SelectBuilder)7 Department (org.seasar.doma.it.entity.Department)6 SelectOptions (org.seasar.doma.jdbc.SelectOptions)5 DepartmentDao (org.seasar.doma.it.dao.DepartmentDao)4 DepartmentDaoImpl (org.seasar.doma.it.dao.DepartmentDaoImpl)4 FunctionDao (org.seasar.doma.it.dao.FunctionDao)4 FunctionDaoImpl (org.seasar.doma.it.dao.FunctionDaoImpl)4 Config (org.seasar.doma.jdbc.Config)3 BigDecimal (java.math.BigDecimal)2