Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After a lot of digging through ibatis classes in multiple packages , the following approach worked for me. (couldn't find any documentation regarding this approach nor any content in the only book available for ibatis - ibatis in action)</p> <p>Step 1: Add a custom ResultObjectFactory. Classdoc of ResultObjectFactory interface explains what it is and how it behaves.</p> <pre><code>public class TemporalDataResultObjectFactory implements ResultObjectFactory { /* * (non-Javadoc) * * @see * com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory#createInstance * (java.lang.String, java.lang.Class) */ @Override public Object createInstance(String statementId, @SuppressWarnings("rawtypes") Class clazz) throws InstantiationException, IllegalAccessException { if (!statementId.startsWith("_td_")) { return null; } TemporalData&lt;Object&gt; temporalResult = new TemporalData&lt;Object&gt;(); Object dataObject = clazz.newInstance(); temporalResult.setData(dataObject); return temporalResult; } /* * (non-Javadoc) * * @see * com.ibatis.sqlmap.engine.mapping.result.ResultObjectFactory#setProperty * (java.lang.String, java.lang.String) */ @Override public void setProperty(String arg0, String arg1) { // TODO Auto-generated method stub } } </code></pre> <p>Step 2: Add the above ResultObjectFactory to sql-map-config</p> <pre><code>&lt;resultObjectFactory type="TemporalDataResultObjectFactory" /&gt; </code></pre> <p>Step 3: Prefix all your ibatis statement Ids whose result is temporal data with '<em>td</em>'.</p> <p>example:</p> <pre><code>&lt;select id="_td_getTemporalEmployees" resultMap="temporalEmployee"&gt; SELECT name, age, opCode, updateTime FROM employee WHERE updateTime BETWEEN #startTime# AND #endTime# &lt;/select&gt; </code></pre> <p>Step 4: Define the result map with the actual class (eg: if you want the result to be TemporalData, then set the class to 'Employee'), but with properties as per the temporalData class.</p> <p>example:</p> <pre><code>&lt;resultMap class="Employee" id="temporalEmployee"&gt; &lt;result property="data.name" column="name" javaType="String"/&gt; &lt;result property="data.age" column="age" javaType="long"/&gt; &lt;result property="data.bidPrice" column="bid_price" javaType="int"/&gt; &lt;result property="data.dob" column="dob" javaType="java.util.Date"/&gt; &lt;result property="opCode" column="opCode" javaType="String"/&gt; &lt;result property="updateTime" column="updateTime" javaType="java.util.Date"/&gt; &lt;/resultMap&gt; </code></pre> <p>Step 5: Make sure that all properties in resultMap defined above has javaType appropriately set (Otherwise, ibatis throws exceptions during validations complaining about unavailable setters)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload