views:

401

answers:

1

We use iBatis + Spring intensively. Everything we get from the DB is fetched via stored procedures. At times when troubleshooting an issue we want to know the exact parameters that were sent to the SP and SP name that was executed. Currently we do this by debugging the code (which is a pain). We would like to add some sort of logging to iBatis so it prints out name of the SP + parameter values. We use log4j and following is our iBatis structure.

Mapping:

<procedure id="getReportData" parameterMap="getReportDataCall">
   {call get_rpt (?,?,?,?)}
</procedure>

  <parameterMap id="getReportDataCall" class="map">
    <parameter property="type" jdbcType="String" javaType="java.lang.String" mode="IN"/>
    <parameter property="month" jdbcType="Int" javaType="java.lang.Integer" mode="IN"/>
    <parameter property="Result0" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="result1"/>
    <parameter property="Result1" jdbcType="ORACLECURSOR" javaType="java.sql.ResultSet" mode="OUT" resultMap="result2"/>
  </parameterMap>

  <resultMap id="select-first-result-hq" class="VO">
    <result property="column1" column="columna"/>
    <result property="column2" column="columnb"/>
  </resultMap

Calling iBatis from DAO

HashMap parm = new HashMap ();
parm.put("type", type_val);
parm.put("month", month_val);
getSqlMapClientTemplate().queryForList("mymappingName.getReportData", parm);

As you see the parameters are just in a HashMap. I could make a class+method of my own which takes in the HashMap and procedure name as parameters and just prints out all the key/value pairs of the hashmap and the procedure name to the log. However, if I do this...I will have to add that call to all my DAO's before I call the SP.

Is there any simpler solution to this? that would avoid me touching all my code again?

A: 

I've used iBatis and Spring pretty extensively too and generally just up the logging level to DEBUG for the java.sql.* classes. I generally do something like this in log4j.properties:

log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

This logs both the sql and values that are passed to the parameter placeholders.

digitalsanctum
hmm dont i need to add log.debug("....") for this to work?
Omnipresent
No. Debug statements already exist in the java.sql.* classes. You just have to configure Log4J or whatever you use for logging to use DEBUG for those classes.
digitalsanctum