Пример #1
0
  public synchronized void syncClose() throws SQLException {
    if (this.disable) {
      return;
    }

    DruidConnectionHolder holder = this.holder;
    if (holder == null) {
      if (dupCloseLogEnable) {
        LOG.error("dup close");
      }
      return;
    }

    for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
      listener.connectionClosed(new ConnectionEvent(this));
    }

    DruidAbstractDataSource dataSource = holder.getDataSource();
    List<Filter> filters = dataSource.getProxyFilters();
    if (filters.size() > 0) {
      FilterChainImpl filterChain = new FilterChainImpl(dataSource);
      filterChain.dataSource_recycle(this);
    } else {
      recycle();
    }

    this.disable = true;
  }
Пример #2
0
  protected void transactionRecord(String sql) throws SQLException {
    if (transactionInfo == null && (!conn.getAutoCommit())) {
      DruidAbstractDataSource dataSource = holder.getDataSource();
      dataSource.incrementStartTransactionCount();
      transactionInfo = new TransactionInfo(dataSource.createTransactionId());
    }

    if (transactionInfo != null) {
      transactionInfo.getSqlList().add(sql);
    }
  }
Пример #3
0
  private void handleEndTransaction(DruidAbstractDataSource dataSource, Savepoint savepoint) {
    if (transactionInfo != null && savepoint == null) {
      transactionInfo.setEndTimeMillis();

      long transactionMillis =
          transactionInfo.getEndTimeMillis() - transactionInfo.getStartTimeMillis();
      dataSource.getTransactionHistogram().record(transactionMillis);

      dataSource.logTransaction(transactionInfo);

      transactionInfo = null;
    }
  }
Пример #4
0
  @Override
  public void commit() throws SQLException {
    checkState();

    DruidAbstractDataSource dataSource = holder.getDataSource();
    dataSource.incrementCommitCount();

    try {
      conn.commit();
    } catch (SQLException ex) {
      handleException(ex);
    } finally {
      handleEndTransaction(dataSource, null);
    }
  }
Пример #5
0
  public SQLException handleException(Throwable t) throws SQLException {
    final DruidConnectionHolder holder = this.holder;

    //
    if (holder != null) {
      DruidAbstractDataSource dataSource = holder.getDataSource();
      dataSource.handleConnectionException(this, t);
    }

    if (t instanceof SQLException) {
      throw (SQLException) t;
    }

    throw new SQLException("Error", t);
  }
Пример #6
0
  @Override
  public void rollback(Savepoint savepoint) throws SQLException {
    if (holder == null) {
      return;
    }

    DruidAbstractDataSource dataSource = holder.getDataSource();
    dataSource.incrementRollbackCount();

    try {
      conn.rollback(savepoint);
    } catch (SQLException ex) {
      handleException(ex);
    } finally {
      handleEndTransaction(dataSource, savepoint);
    }
  }
Пример #7
0
  public DruidConnectionHolder(DruidAbstractDataSource dataSource, Connection conn)
      throws SQLException {

    this.dataSource = dataSource;
    this.conn = conn;
    this.connectTimeMillis = System.currentTimeMillis();
    this.lastActiveTimeMillis = connectTimeMillis;

    this.underlyingAutoCommit = conn.getAutoCommit();

    {
      boolean initUnderlyHoldability = !holdabilityUnsupported;
      if (JdbcConstants.SYBASE.equals(dataSource.getDbType()) //
          || JdbcConstants.DB2.equals(dataSource.getDbType()) //
      ) {
        initUnderlyHoldability = false;
      }
      if (initUnderlyHoldability) {
        try {
          this.underlyingHoldability = conn.getHoldability();
        } catch (UnsupportedOperationException e) {
          holdabilityUnsupported = true;
          LOG.warn("getHoldability unsupported", e);
        } catch (SQLFeatureNotSupportedException e) {
          holdabilityUnsupported = true;
          LOG.warn("getHoldability unsupported", e);
        } catch (SQLException e) {
          // bug fixed for hive jdbc-driver
          if ("Method not supported".equals(e.getMessage())) {
            holdabilityUnsupported = true;
          }
          LOG.warn("getHoldability error", e);
        }
      }
    }

    this.underlyingReadOnly = conn.isReadOnly();
    try {
      this.underlyingTransactionIsolation = conn.getTransactionIsolation();
    } catch (SQLException e) {
      // compartible for alibaba corba
      if (!"com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException"
          .equals(e.getClass().getName())) {
        throw e;
      }
    }

    this.defaultHoldability = underlyingHoldability;
    this.defaultTransactionIsolation = underlyingTransactionIsolation;
    this.defaultAutoCommit = underlyingAutoCommit;
    this.defaultReadOnly = underlyingReadOnly;
  }
Пример #8
0
  public void recycle() throws SQLException {
    if (this.disable) {
      return;
    }

    DruidConnectionHolder holder = this.holder;
    if (holder == null) {
      if (dupCloseLogEnable) {
        LOG.error("dup close");
      }
      return;
    }

    if (!this.abandoned) {
      DruidAbstractDataSource dataSource = holder.getDataSource();
      dataSource.recycle(this);
    }

    this.holder = null;
    conn = null;
    transactionInfo = null;
    closed = true;
  }
Пример #9
0
 public boolean isPoolPreparedStatements() {
   return dataSource.isPoolPreparedStatements();
 }