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