ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric T. Blue" <ericblu...@gmail.com>
Subject Re: Is it possible
Date Thu, 18 May 2006 20:04:56 GMT
I do this programatically for a number of my unit tests.  It's a little
"hacky", but it works.


    int iterations = 1000;

    Logger statementLogger = Logger.getLogger("java.sql.PreparedStatement");

    WriterAppender appender = null;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
        appender = new WriterAppender(new PatternLayout(), stream);
    } catch(Exception e) {
        fail("Appender exception: " + e);


    String targetStatement = "SELECT * from my_table";

    for (int i = 0; i < iterations; i++) {

        // Put DAO or SQLMap query here

        // Check to make sure that only the first get hits the database.
        // All subsequent calls should hit the cache.

        if ( (i > 0) && (stream.toString().contains(targetStatement)) ) {
            fail("Cache was not used and select statement detected on
iteration "
                    + i + ": " + stream.toString());




On 5/18/06, Chen, Tim <Tim.Chen@nielsenmedia.com> wrote:
>  Actually I turned on JDBC logging (I think it explains how in the IBatis
> log) using log4j and from that you can infer which goes out as queries and
> which doesn't (which goes to cache). Don't know if there's another solution
> but it's really easy to do.
>  ------------------------------
> *From:* Zacks, Michael [mailto:Michael_Zacks@ziffdavis.com]
> *Sent:* Thursday, May 18, 2006 3:31 PM
> *To:* user-java@ibatis.apache.org
> *Subject:* Is it possible
>  To determine whether query results were returned from the cache or from a
> trip to the database?  I'm running Ibatis against SqlServer.  My problem is
> that I have a query that was meant to be cached, but instead was being run
> every time against the database - much to the detriment of our application.
> I think I know what the problem is (I suspect it is an accidental 'select *
> from'), but I would like to be able to verify when database results came
> from the cache or not.
> Thanks in advance.
> This e-mail message and any attachments to it are for the sole use of the
> intended recipients and may contain confidential and privileged information.
> This e-mail message and any attachments are the property of Ziff Davis Media
> Inc. or its affiliates. Any unauthorized review, use, disclosure, or
> distribution of this e-mail message or its attachments is prohibited. If you
> are not an intended recipient, please notify the sender by reply e-mail and
> destroy all copies of the original message and any attachments. Thank you.

View raw message