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());
}
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());
}
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());
}
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);
}
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) {
}
}
Aggregations