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; }
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); } }
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; } }
@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); } }
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); }
@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); } }
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; }
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; }
public boolean isPoolPreparedStatements() { return dataSource.isPoolPreparedStatements(); }