Search in sources :

Example 21 with Employee

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

the class CriteriaDao method selectAll.

default List<Employee> selectAll() {
    Employee_ e = new Employee_();
    Department_ d = new Department_();
    Entityql entityql = new Entityql(Config.get(this));
    return entityql.from(e).innerJoin(d, on -> on.eq(e.departmentId, d.departmentId)).associate(e, d, (employee, department) -> {
        employee.setDepartment(department);
        department.getEmployeeList().add(employee);
    }).fetch();
}
Also used : Entityql(org.seasar.doma.jdbc.criteria.Entityql) Employee(org.seasar.doma.it.entity.Employee) List(java.util.List) Entityql(org.seasar.doma.jdbc.criteria.Entityql) Dao(org.seasar.doma.Dao) Optional(java.util.Optional) Config(org.seasar.doma.jdbc.Config) Employee_(org.seasar.doma.it.entity.Employee_) Department_(org.seasar.doma.it.entity.Department_) Employee_(org.seasar.doma.it.entity.Employee_) Department_(org.seasar.doma.it.entity.Department_)

Example 22 with Employee

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

the class SqlFileSelectTest method testSuffixSearch.

@Test
public void testSuffixSearch(Config config) throws Exception {
    EmployeeDao dao = new EmployeeDaoImpl(config);
    List<Employee> employees = dao.selectByNameSuffix("S");
    assertEquals(3, employees.size());
}
Also used : EmployeeDao(org.seasar.doma.it.dao.EmployeeDao) Employee(org.seasar.doma.it.entity.Employee) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) Test(org.junit.jupiter.api.Test)

Example 23 with Employee

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

the class SqlFileSelectPagingTest method testLimitOffset_limitIsZero.

@Test
public void testLimitOffset_limitIsZero(Config config) throws Exception {
    EmployeeDao dao = new EmployeeDaoImpl(config);
    List<Employee> employees = dao.selectAll(SelectOptions.get().limit(0).offset(10));
    assertEquals(4, employees.size());
    assertEquals(Integer.valueOf(11), employees.get(0).getEmployeeId());
    assertEquals(Integer.valueOf(12), employees.get(1).getEmployeeId());
    assertEquals(Integer.valueOf(13), employees.get(2).getEmployeeId());
    assertEquals(Integer.valueOf(14), employees.get(3).getEmployeeId());
}
Also used : EmployeeDao(org.seasar.doma.it.dao.EmployeeDao) Employee(org.seasar.doma.it.entity.Employee) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) Test(org.junit.jupiter.api.Test)

Example 24 with Employee

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

the class SqlFileSelectPagingTest method testLimitOffset_offsetIsZero.

@Test
public void testLimitOffset_offsetIsZero(Config config) throws Exception {
    EmployeeDao dao = new EmployeeDaoImpl(config);
    List<Employee> employees = dao.selectAll(SelectOptions.get().limit(5).offset(0));
    assertEquals(5, employees.size());
    assertEquals(Integer.valueOf(1), employees.get(0).getEmployeeId());
    assertEquals(Integer.valueOf(2), employees.get(1).getEmployeeId());
    assertEquals(Integer.valueOf(3), employees.get(2).getEmployeeId());
    assertEquals(Integer.valueOf(4), employees.get(3).getEmployeeId());
    assertEquals(Integer.valueOf(5), employees.get(4).getEmployeeId());
}
Also used : EmployeeDao(org.seasar.doma.it.dao.EmployeeDao) Employee(org.seasar.doma.it.entity.Employee) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) Test(org.junit.jupiter.api.Test)

Example 25 with Employee

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

the class SqlFileSelectStreamTest method testStreamAll_resultStream.

@Test
public void testStreamAll_resultStream(Config config) throws Exception {
    EmployeeDao dao = new EmployeeDaoImpl(config);
    Long count = null;
    try (Stream<Employee> stream = dao.streamAll()) {
        count = stream.filter(e -> e.getEmployeeName() != null).filter(e -> e.getEmployeeName().startsWith("S")).count();
    }
    assertEquals(Long.valueOf(2), count);
}
Also used : Employee(org.seasar.doma.it.entity.Employee) IntegrationTestEnvironment(org.seasar.doma.it.IntegrationTestEnvironment) SelectOptions(org.seasar.doma.jdbc.SelectOptions) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) BigDecimal(java.math.BigDecimal) Stream(java.util.stream.Stream) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) EmployeeDao(org.seasar.doma.it.dao.EmployeeDao) Config(org.seasar.doma.jdbc.Config) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EmployeeDao(org.seasar.doma.it.dao.EmployeeDao) Employee(org.seasar.doma.it.entity.Employee) EmployeeDaoImpl(org.seasar.doma.it.dao.EmployeeDaoImpl) 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