ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zacks, Michael" <Michael_Za...@ziffdavis.com>
Subject RE: Is it possible
Date Thu, 18 May 2006 23:15:15 GMT
Thanks for your response (and thanks to others who responded).  I ended
up using this code to test the fix.  
Small note, you have a space at the end of 'java.sql.PreparedStatement '
in your getLogger call
This prevented the code from working for me until I spotted it.
 
 

	-----Original Message-----
	From: Eric T. Blue [mailto:ericblue76@gmail.com] 
	Sent: Thursday, May 18, 2006 12:05 PM
	To: user-java@ibatis.apache.org
	Subject: Re: Is it possible
	
	

	I do this programatically for a number of my unit tests.  It's a
little "hacky", but it works.
	
	<snip>
	
	    int iterations = 1000;
	   
	    Logger statementLogger =
Logger.getLogger("java.sql.PreparedStatement ");
	    statementLogger.setLevel(Level.DEBUG);
	    
	    WriterAppender appender = null;
	    ByteArrayOutputStream stream = new ByteArrayOutputStream();
	    try {
	        appender = new WriterAppender(new PatternLayout(),
stream); 
	    } catch(Exception e) {
	        fail("Appender exception: " + e);
	    }
	    
	    statementLogger.addAppender(appender);
	    
	    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());            
	        }
	        
	        stream.reset();
	                
	    }
	
	</snip>
	
	
	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.



Mime
View raw message