JdbcStatementWrapper.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package org.apache.kyuubi.engine.jdbc.session;
  2. import org.apache.commons.dbcp2.DelegatingConnection;
  3. import org.apache.commons.dbcp2.DelegatingStatement;
  4. import org.slf4j.Logger;
  5. import org.slf4j.LoggerFactory;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. /**
  9. * JDBC JdbcStatementWrapper 包装类
  10. * <pre>
  11. *
  12. * Created by zhenqin.
  13. * User: zhenqin
  14. * Date: 2026/2/11
  15. * Time: 12:42
  16. * Vendor: yiidata.com
  17. *
  18. * </pre>
  19. *
  20. * @author zhenqin
  21. */
  22. public class JdbcStatementWrapper extends DelegatingStatement {
  23. final Logger log = LoggerFactory.getLogger(SimpleDataSource.class);
  24. /**
  25. * 内置,主要返回连接使用
  26. */
  27. final DelegatingConnection<?> copyConnection;
  28. public JdbcStatementWrapper(DelegatingConnection<?> connection, Statement statement) {
  29. super(connection, statement);
  30. this.copyConnection = connection;
  31. }
  32. /**
  33. * 获取内部的连接,不检查
  34. * @return
  35. */
  36. public DelegatingConnection getInternalConnection() {
  37. return getConnectionInternal() == null ? copyConnection : getConnectionInternal();
  38. }
  39. @Override
  40. public void setQueryTimeout(final int seconds) throws SQLException {
  41. if(seconds <= 0) {
  42. log.warn("invalid query timeout value: " + seconds);
  43. return;
  44. }
  45. super.setQueryTimeout(seconds);
  46. }
  47. }