ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sundar Sankar" <fatboys...@gmail.com>
Subject Re: Caching not working
Date Wed, 17 Sep 2008 00:11:28 GMT
Thanks! Will try it out and let you know.

On Tue, Sep 16, 2008 at 2:41 PM, George Marvin <georgemarvin0@gmail.com>wrote:

> Hi Sundar,
> I have a much better solution. I was able to successfully subclass
> oracle.sql.ARRAY and just add the equals() and hashcode() methods. Here is a
> sample of how it looks:
>
>
> package mil.af.dcapes.ddms.vocs;
>
> /**
>  * VOCSArray is a sub-class of oracle.sql.ARRAY. It is used to hold
> parameters
>  * and that are used to construct a lookup key in OSCache. VOCSArray was
> constructed
>  * to implement an equals() method and hashcode() method that are used by
> OSCache to
>  * do key lookups of results stored in OSCache.
>  */
>
> import java.sql.Connection;
> import java.sql.SQLException;
>
> import oracle.sql.ARRAY;
> import oracle.sql.ArrayDescriptor;
>
> public class VOCSArray extends ARRAY {
>
>     /**
>      *
>      */
>     private static final long serialVersionUID = -4640581956617812831L;
>
>     public VOCSArray(ArrayDescriptor arraydescriptor, Connection
> connection, Object obj)
>     throws SQLException {
>         super(arraydescriptor,connection,obj);
>
>     }
>
>        // Comparison and hashing
>
>     /**
>      * Compares the specified VOCSArray with this VOCSArray for equality.
> Returns
>      * <tt>true</tt> if and only if the specified object is also an
> VOCSArray, both
>      * VOCSArrays have the same size, and the oracle.sql.ARRAYs they hold
> are <p>
>      *
>      * This implementation first checks if the specified object is this
>      * VOCSArray. If so, it returns <tt>true</tt>; if not, it checks if the
>      * specified object is a VOCSArray. If not, it returns <tt>false</tt>;
> if so,
>      * it checks if the lengths of both VOCSArrays are the same, if not it
> returns
>      * <tt>false</tt>, if the lengths are the same it checks to see if the
> oracle.sql.ARRAYs
>      * they extend are equal, if not it returns <tt>false</tt> else it
> returns <tt>>true</tt>.
>      *
>      * @param o the object to be compared for equality with this list.
>      *
>      * @return <tt>true</tt> if the specified object is equal to this list.
>      */
>     public boolean equals(VOCSArray o) {
>     if (o == this)
>         return true;
>     if (!(o instanceof VOCSArray))
>         return false;
>     try {
>         if (this.length() != o.length())
>             return false;
>         if (!(this.getArray().equals(o.getArray()))) {
>             return false;
>         }
>     } catch (SQLException e) {
>         // TODO Auto-generated catch block
>         e.printStackTrace();
>     }
>     return true;
>     }
>
>     /**
>      * Returns the hash code value for this list. <p>
>      *
>      * This implementation uses exactly the code that is used to define the
>      * list hash function in the documentation for the
> <tt>List.hashCode</tt>
>      * method.
>      *
>      * @return the hash code value for this list.
>      */
>     public int hashCode() {
>     int hashCode=0;
>     try {
>         hashCode = 1;
>         for (int i=1; i < length(); i++) {
>             hashCode = hashCode*i;
>         }
>     } catch (SQLException e) {
>         // TODO Auto-generated catch block
>         e.printStackTrace();
>     }
>     return hashCode;
>     }
>
>
>
>
>
> }
>
> Then you can specify it as an ARRAY in your SQLMap.xml file as a param and
> pass it. The Oracle stored procedure will interpret it correctly and return
> a resultset. Since the Array is used for its equals() and hashcode() methods
> by OSCache it will work. This is works just fine!
> Hope this helps
>
>
> On Wed, Sep 10, 2008 at 2:04 PM, Sundar Sankar <fatboysuns@gmail.com>wrote:
>
>> Hey george,
>>                  If I remember right, Some one told me that Stored
>> procedure out param caching was not supported By ibatis itself. Can you send
>> the code snippet and let the group know what change u did to what class. As
>> far I know OJDBC14 is not an open source. If you overrided the methods, how
>> did u manage to do it? If it is a change somewhere in the Ibatis Jar, we
>> could include it hopefully.
>>
>> Thanks for the response. I totally appreciate it. It would solve a lot of
>> issues in our project if that could be achieved. I am currently using too
>> many static variables and am using primitive way of coding.
>>
>>
>> -Sundar
>>
>> On Wed, Sep 10, 2008 at 9:54 AM, <georgemarvin0@gmail.com> wrote:
>>
>>>
>>> Sundar Sankar wrote:
>>> >
>>> > Hi,
>>> >        I tried to cache the data returned by my stored proc and I am
>>> > seeing
>>> > that the data fetched from the procedure is not cached at all. Am I
>>> doing
>>> > wrong here. I tried to use OSCache and Memory. Both dont seem to work
>>> at
>>> > all
>>> > for me.
>>> >
>>> > My configurations are
>>> >
>>> > <cacheModel id="oscache" type="OSCACHE">
>>> >             <flushInterval hours="24"/>
>>> >         </cacheModel>
>>> >         <cacheModel id="memory-cache" type="MEMORY">
>>> >             <flushInterval hours="24"/>
>>> >         </cacheModel>
>>> >
>>> > <procedure id="something"
>>> >         parameterMap="someParam" cacheModel="oscache">
>>> >         {? = call someProc}
>>> >     </procedure>
>>> >
>>> > My oscache.properties is fairly simple and has
>>> >
>>> > cache.memory=true
>>> > #cache.capacity=1000
>>> > #cache.algorithm=com.opensymphony.oscache.base.algorithm.UnlimitedCache
>>> > cache.use.host.domain.in.key=true
>>> > cache.path=c:\\Sundar\\cache
>>> >
>>> > ###################################################
>>> >
>>> > My debug statements are
>>> >
>>> > 2008-06-17 16:49:53,148 DEBUG
>>> [com.ibatis.sqlmap.engine.cache.CacheModel]
>>> > Cache 'oscache': *cache miss*
>>> > 2008-06-17 16:49:53,148 DEBUG [java.sql.Connection] {conn-100019}
>>> > Preparing
>>> > Call: {? = call someProc}
>>> > 2008-06-17 16:49:53,179 DEBUG [java.sql.PreparedStatement]
>>> {pstm-100020}
>>> > Executing Statement: {? = call someProc}
>>> > 2008-06-17 16:49:53,179 DEBUG [java.sql.PreparedStatement]
>>> {pstm-100020}
>>> > Parameters: []
>>> > 2008-06-17 16:49:53,179 DEBUG [java.sql.PreparedStatement]
>>> {pstm-100020}
>>> > Types: []
>>> > 2008-06-17 16:49:53,195 DEBUG
>>> > [com.ibatis.sqlmap.engine.cache.CacheModel] *Cache
>>> > 'oscache': stored object '[]'*
>>> >
>>> >
>>> > Dont know what I am doing wrong. I tried changing the congiguration to
>>> > point
>>> > to the memory-cache config I have. Still yeilds the same results. Any
>>> help
>>> > on this is greatly appreciated.
>>> >
>>> > Regards
>>> > Sundar Sankarnarayanan
>>> >
>>> >
>>> Quoted from:
>>> http://www.nabble.com/Caching-not-working-tp17957249p17957249.html
>>>
>>>
>>> I ran into the same problem. It was because we were passing in
>>> oracle.sql.ARRAYs to our stored procedure. The problem was cause because
>>> oracle.sql.ARRAY does not have a hashcode() and an equals() method. I added
>>> these two methods and the OsCache with IBATIS works fine. The problem is I
>>> really don't want to modify oracle.sql.ARRAY
>>>
>>
>>
>

Mime
View raw message