Java Reference
In-Depth Information
try {
sqlMapClient.startTransaction();
sqlMapClient.queryForObject("Account.insertAndReturn", a);
sqlMapClient.commitTransaction();
} finally {
sqlMapClient.endTransaction();
}
Transactions are covered in more detail in chapter 7, so if you have more ques-
tions about them, that is the best place to go.
5.5.2
IN, OUT, and INOUT parameters
So far, the only parameters that we have seen are input only—you pass them into
i BATIS , and (with the exception of the <selectKey> element) what you pass in
remains unchanged. With stored procedures, you are given three types of param-
eters: IN , OUT , and INOUT .
IN parameters are very simple to use with i BATIS and stored procedures. They
are passed into the procedure just as you would pass a parameter into any other
mapped statement. Here is a simple stored procedure that accepts two IN parame-
ters and returns a value:
CREATE OR REPLACE FUNCTION max_in_example
(a float4, b float4)
RETURNS float4 AS
$BODY$
BEGIN
if (a > b) then
return a;
else
return b;
end if;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
Here is the parameter map, mapped statement, and Java code to use this procedure:
<parameterMap id="pm_in_example" class="java.util.Map">
<parameter property="a" />
<parameter property="b" />
</parameterMap>
<procedure id="in_example" parameterMap="pm_in_example"
resultClass="int" >
{ call max_in_example(?, ?) }
</procedure>
// Call a max function
Search WWH ::




Custom Search