Search in sources :

Example 1 with Reference

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

the class ScalarInOutParameterTest method testGetDomainClass_optional.

@Test
public void testGetDomainClass_optional() {
    DomainType<String, PhoneNumber> domainType = DomainTypeFactory.getDomainType(PhoneNumber.class, new ClassHelper() {
    });
    Scalar<String, Optional<PhoneNumber>> scalar = domainType.createOptionalScalar();
    Reference<Optional<PhoneNumber>> ref = new Reference<>();
    ScalarInOutParameter<String, Optional<PhoneNumber>> parameter = new ScalarInOutParameter<>(scalar, ref);
    Optional<Class<?>> optional = parameter.getDomainClass();
    assertEquals(PhoneNumber.class, optional.get());
}
Also used : ClassHelper(org.seasar.doma.jdbc.ClassHelper) Optional(java.util.Optional) Reference(org.seasar.doma.jdbc.Reference) PhoneNumber(example.domain.PhoneNumber) Test(org.junit.jupiter.api.Test)

Example 2 with Reference

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

the class AutoProcedureTest method testIn_InOut_Out.

@Test
public void testIn_InOut_Out(Config config) throws Exception {
    ProcedureDao dao = new ProcedureDaoImpl(config);
    Integer param1 = 10;
    Reference<Integer> param2 = new Reference<>(20);
    Reference<Integer> param3 = new Reference<>();
    dao.proc_dto_param(param1, param2, param3);
    assertEquals(Integer.valueOf(10), param1);
    assertEquals(Integer.valueOf(30), param2.get());
    assertEquals(Integer.valueOf(10), param3.get());
}
Also used : ProcedureDao(org.seasar.doma.it.dao.ProcedureDao) ProcedureDaoImpl(org.seasar.doma.it.dao.ProcedureDaoImpl) Reference(org.seasar.doma.jdbc.Reference) Test(org.junit.jupiter.api.Test)

Example 3 with Reference

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

the class FunctionCommandTest method testExecute.

@Test
public void testExecute() {
    List<Object> outParameters = runtimeConfig.dataSource.connection.callableStatement.outParameters;
    outParameters.add(10);
    outParameters.add(null);
    outParameters.add(20);
    outParameters.add(30);
    IntegerWrapper aaa = new IntegerWrapper(40);
    IntegerWrapper bbb = new IntegerWrapper(50);
    IntegerWrapper ccc = new IntegerWrapper(60);
    AutoFunctionQuery<Integer> query = new AutoFunctionQuery<>();
    query.setConfig(runtimeConfig);
    query.setCatalogName("xxx");
    query.setSchemaName("yyy");
    query.setFunctionName("aaa");
    query.setResultParameter(new BasicSingleResultParameter<>(IntegerWrapper::new));
    query.addParameter(new BasicInParameter<>(() -> aaa));
    query.addParameter(new BasicOutParameter<>(() -> bbb, new Reference<>()));
    query.addParameter(new BasicInOutParameter<>(() -> ccc, new Reference<>()));
    query.setCallerClassName("aaa");
    query.setCallerMethodName("bbb");
    query.setSqlLogType(SqlLogType.FORMATTED);
    query.prepare();
    Integer result = new FunctionCommand<>(query).execute();
    query.complete();
    assertNotNull(result);
    assertEquals(new Integer(10), result);
    assertEquals(new Integer(40), aaa.get());
    assertEquals(new Integer(20), bbb.get());
    assertEquals(new Integer(30), ccc.get());
    String sql = runtimeConfig.dataSource.connection.callableStatement.sql;
    assertEquals("{? = call xxx.yyy.aaa(?, ?, ?)}", sql);
}
Also used : AutoFunctionQuery(org.seasar.doma.jdbc.query.AutoFunctionQuery) Reference(org.seasar.doma.jdbc.Reference) IntegerWrapper(org.seasar.doma.wrapper.IntegerWrapper) Test(org.junit.jupiter.api.Test)

Example 4 with Reference

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

the class ScalarInOutParameterTest method testGetDomainClass.

@Test
public void testGetDomainClass() {
    DomainType<String, PhoneNumber> domainType = DomainTypeFactory.getDomainType(PhoneNumber.class, new ClassHelper() {
    });
    Scalar<String, PhoneNumber> scalar = domainType.createScalar();
    Reference<PhoneNumber> ref = new Reference<>();
    ScalarInOutParameter<String, PhoneNumber> parameter = new ScalarInOutParameter<>(scalar, ref);
    Optional<Class<?>> optional = parameter.getDomainClass();
    assertEquals(PhoneNumber.class, optional.get());
}
Also used : ClassHelper(org.seasar.doma.jdbc.ClassHelper) Reference(org.seasar.doma.jdbc.Reference) PhoneNumber(example.domain.PhoneNumber) Test(org.junit.jupiter.api.Test)

Example 5 with Reference

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

the class AutoProcedureTest method testResultSet_Out.

@Test
public void testResultSet_Out(Config config) throws Exception {
    ProcedureDao dao = new ProcedureDaoImpl(config);
    List<Employee> employees = new ArrayList<>();
    Reference<Integer> count = new Reference<>();
    dao.proc_resultset_out(employees, 1, count);
    assertEquals(13, employees.size());
    assertEquals(Integer.valueOf(14), count.get());
}
Also used : ProcedureDao(org.seasar.doma.it.dao.ProcedureDao) Employee(org.seasar.doma.it.entity.Employee) ProcedureDaoImpl(org.seasar.doma.it.dao.ProcedureDaoImpl) Reference(org.seasar.doma.jdbc.Reference) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 Reference (org.seasar.doma.jdbc.Reference)8 ProcedureDao (org.seasar.doma.it.dao.ProcedureDao)4 ProcedureDaoImpl (org.seasar.doma.it.dao.ProcedureDaoImpl)4 ArrayList (java.util.ArrayList)3 PhoneNumber (example.domain.PhoneNumber)2 Employee (org.seasar.doma.it.entity.Employee)2 ClassHelper (org.seasar.doma.jdbc.ClassHelper)2 BigDecimal (java.math.BigDecimal)1 Time (java.sql.Time)1 Optional (java.util.Optional)1 BindValue (org.seasar.doma.internal.jdbc.mock.BindValue)1 MockCallableStatement (org.seasar.doma.internal.jdbc.mock.MockCallableStatement)1 RegisterOutParameter (org.seasar.doma.internal.jdbc.mock.RegisterOutParameter)1 Department (org.seasar.doma.it.entity.Department)1 SqlParameter (org.seasar.doma.jdbc.SqlParameter)1 AutoFunctionQuery (org.seasar.doma.jdbc.query.AutoFunctionQuery)1 IntegerWrapper (org.seasar.doma.wrapper.IntegerWrapper)1