View Javadoc

1   /*
2    * $Id: ExtendedQueryRunner.java 20320 2010-11-24 15:03:31Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.jdbc;
12  
13  import java.sql.Connection;
14  import java.sql.PreparedStatement;
15  import java.sql.SQLException;
16  
17  import javax.sql.DataSource;
18  
19  import org.apache.commons.dbutils.QueryRunner;
20  
21  /**
22   * An extended version of the Query runner that supports query timeouts
23   * 
24   * @since 2.2.6
25   */
26  public class ExtendedQueryRunner extends QueryRunner
27  {
28      private int queryTimeout;
29  
30      public ExtendedQueryRunner(DataSource ds, int queryTimeout)
31      {
32      	super (ds);
33          this.queryTimeout = queryTimeout;
34      }
35  
36      @Override
37      protected PreparedStatement prepareStatement(Connection conn, String sql) throws SQLException
38      {
39          PreparedStatement statement = super.prepareStatement(conn, sql);
40          if (this.queryTimeout >= 0)
41          {
42              statement.setQueryTimeout(this.queryTimeout);
43          }
44          return statement;
45      }
46  
47      public int getQueryTimeout()
48      {
49          return this.queryTimeout;
50      }
51  }