To call stored procedures, you must annotate DAO methods with the @Procedure
annotation:
@Dao
public interface EmployeeDao {
@Procedure
void execute(@In Integer id, @InOut Reference<BigDecimal> salary);
...
}
The return type must be void
.
The annotated method name is recognized as the procedure name by default. To override it, you can specify the value to the @Procedure
's name
element:
@Procedure(name = "calculateSalary")
void execute(@In Integer id, @InOut Reference<BigDecimal> salary);
The order of stored procedure's parameters must correspond with the order of DAO method parameters.
All parameters must be annotated with one of following annotations:
- @In
- @InOut
- @Out
- @ResultSet
To indicate IN parameters, annotate corresponding DAO method parameters with the @In
annotation. The type of the DAO method parameter must be one of the following:
../basic
../domain
- java.util.Optional whose element type is either
../basic
or../domain
- java.util.OptionalInt
- java.util.OptionalLong
- java.util.OptionalDouble
Suppose you have the following definition:
@Procedure
void execute(@In Integer id);
You can invoke the method as follows:
EmployeeDao dao = new EmployeeDaoImpl();
dao.execute(1);
To indicate INOUT parameters, annotate corresponding DAO method parameters with the @InOut
annotation. The type of the DAO method parameter must be org.seasar.doma.jdbc.Reference
and its type parameter must be one of the following:
../basic
../domain
- java.util.Optional whose element type is either
../basic
or../domain
- java.util.OptionalInt
- java.util.OptionalLong
- java.util.OptionalDouble
Suppose you have the following definition:
@Procedure
void execute(@InOut Reference<BigDecimal> salary);
You can invoke the method as follows:
EmployeeDao dao = new EmployeeDaoImpl();
BigDecimal in = new BigDecimal(100);
Reference<BigDecimal> ref = new Reference<BigDecimal>(in);
dao.execute(ref);
BigDecimal out = ref.get();
To indicate OUT parameters, annotate corresponding DAO method parameters with the @Out
annotation. The type of the DAO method parameter must be org.seasar.doma.jdbc.Reference
and its type parameter must be one of the following:
../basic
../domain
- java.util.Optional whose element type is either
../basic
or../domain
- java.util.OptionalInt
- java.util.OptionalLong
- java.util.OptionalDouble
Suppose you have the following definition:
@Procedure
void execute(@Out Reference<BigDecimal> salary);
You can invoke the method as follows:
EmployeeDao dao = new EmployeeDaoImpl();
Reference<BigDecimal> ref = new Reference<BigDecimal>();
dao.execute(ref);
BigDecimal out = ref.get();
To indicate cursors or result sets, annotate corresponding DAO method parameters with the @ResultSet
annotation.
The DAO method parameter type must be java.util.List
and its element type must be one of the following:
../basic
../domain
../entity
- java.util.Map<String, Object>
- java.util.Optional whose element type is either
../basic
or../domain
- java.util.OptionalInt
- java.util.OptionalLong
- java.util.OptionalDouble
Suppose you have the following definition:
@Procedure
void execute(@ResultSet List<Employee> employees);
You can invoke the method as follows:
EmployeeDao dao = new EmployeeDaoImpl();
List<Employee> employees = new ArrayList<Employee>();
dao.execute(employees);
for (Employee e : employees) {
...
}