Well, I needed use Stored Procedures, so,
Here that my implementation to stored procedures for AppFuse:


1- First of all, I created a class call "GenericSP", this class extends to
org.springframework.jdbc.object.StoredProcedure, I'll that for call to SP.
GenericSP class and have a constructor with 3 params, a Datasoure, the name
of SP and a ArrayList with the params that are receive by SP.
2- Create a class called Param, here I will use for send the parameters.
This class have a construtor with the params necessary for execute  the SP.
They're name: Name or SP, oracleType, type: if is IN or OUT, mapper: String
because we will use Class.forName("com.app.MyClass").newInstance()).
4- Create a class that UserMapper, this class implements
org.springframework.jdbc.core.RowMapper, I will use to map the results, this
class be instance when we get the results from database.
5- Call stored procedures from Dao's, the steps for invoke the SP are:
      -Create a ArrayList and set the parameters necesaries for SP.
         ArrayList<Param> params = new ArrayList<Param>();
         params.add(new Param("ousers", OracleTypes.CURSOR,
                                       Param.OUT,

"com.allegra.app.dao.sp.mapper.UserMapper"));

      -Create an object GenericSP and send the parameters.
           GenericSP sp = new
GenericSP(SessionFactoryUtils.getDataSource(getSessionFactory()),
"users.getUsers", params).

      -Execute the SP.
           Map results = sp.execute(new HashMap()); //here SP be executed
and call the mapper class.

      -Get the results trought the Map.
         for (Iterator it = results.entrySet().iterator(); it.hasNext(); ) {
             ArrayList ar =(ArrayList) ((Map.Entry)it.next()).getValue();
             users=(ArrayList<User>) ar.get(0);
         }


You can download all clases and stored procedure from here:
http://estaticos.allegranet.com.ar/file/SPAppfuse.zip

Well, It's all! We can now call stored procedures from AppFuse 2.

If you have some recomendation or some improve for the code, please, send me
it!

Regards.

Mauri!

Reply via email to