Search in sources :

Example 1 with SelectBuilder

use of org.seasar.doma.jdbc.builder.SelectBuilder in project doma by domaframework.

the class SelectBuilderTest method testGetMapSingleResult_null.

@Test
public void testGetMapSingleResult_null(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, 99);
    Map<String, Object> employee = builder.getMapSingleResult(MapKeyNamingType.CAMEL_CASE);
    assertNull(employee);
}
Also used : SelectBuilder(org.seasar.doma.jdbc.builder.SelectBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with SelectBuilder

use of org.seasar.doma.jdbc.builder.SelectBuilder in project doma by domaframework.

the class SelectBuilderTest method testGetOptionalScalarSingleResult.

@Test
public void testGetOptionalScalarSingleResult(Config config) throws Exception {
    SelectBuilder builder = SelectBuilder.newInstance(config);
    builder.sql("select EMPLOYEE_NAME from EMPLOYEE");
    builder.sql("where");
    builder.sql("EMPLOYEE_ID = ").param(int.class, 1);
    Optional<String> name = builder.getOptionalScalarSingleResult(String.class);
    assertEquals("SMITH", name.get());
}
Also used : SelectBuilder(org.seasar.doma.jdbc.builder.SelectBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with SelectBuilder

use of org.seasar.doma.jdbc.builder.SelectBuilder in project doma by domaframework.

the class SelectBuilderTest method testStreamMap.

@Test
public void testStreamMap(Config config) throws Exception {
    SelectBuilder builder = SelectBuilder.newInstance(config);
    builder.sql("select EMPLOYEE_ID, EMPLOYEE_NAME, HIREDATE from EMPLOYEE");
    Optional<Map<String, Object>> result = builder.streamMap(MapKeyNamingType.CAMEL_CASE, stream -> stream.findFirst());
    assertEquals("SMITH", result.get().get("employeeName"));
}
Also used : SelectBuilder(org.seasar.doma.jdbc.builder.SelectBuilder) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 4 with SelectBuilder

use of org.seasar.doma.jdbc.builder.SelectBuilder 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 5 with SelectBuilder

use of org.seasar.doma.jdbc.builder.SelectBuilder in project doma by domaframework.

the class SelectBuilderTest method testStreamScalar.

@Test
public void testStreamScalar(Config config) throws Exception {
    SelectBuilder builder = SelectBuilder.newInstance(config);
    builder.sql("select EMPLOYEE_NAME from EMPLOYEE");
    builder.sql("where");
    builder.sql("EMPLOYEE_ID = ").param(int.class, 1);
    Optional<String> name = builder.streamScalar(String.class, stream -> stream.findFirst());
    assertEquals("SMITH", name.get());
}
Also used : SelectBuilder(org.seasar.doma.jdbc.builder.SelectBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

SelectBuilder (org.seasar.doma.jdbc.builder.SelectBuilder)28 Test (org.junit.jupiter.api.Test)25 Employee (org.seasar.doma.it.entity.Employee)7 Map (java.util.Map)4 Optional (java.util.Optional)4 Config (org.seasar.doma.jdbc.Config)2