Search in sources :

Example 21 with ConnectionEvent

use of javax.sql.ConnectionEvent in project j2objc by google.

the class OldConnectionEventTest method testConstructorConnection.

public void testConstructorConnection() {
    Impl_PooledConnection ipc = new Impl_PooledConnection();
    ConnectionEvent ce = new ConnectionEvent(ipc);
    ConnectionEvent ce2 = new ConnectionEvent(ipc, null);
    assertSame(ce2.getSource(), ce.getSource());
}
Also used : ConnectionEvent(javax.sql.ConnectionEvent)

Example 22 with ConnectionEvent

use of javax.sql.ConnectionEvent in project spanner-jdbc by olavloite.

the class CloudSpannerPooledConnection method fireConnectionClosed.

/**
 * Used to fire a connection closed event to all listeners.
 */
void fireConnectionClosed() {
    ConnectionEvent evt = null;
    // Copy the listener list so the listener can remove itself during this
    // method call
    ConnectionEventListener[] local = listeners.toArray(new ConnectionEventListener[listeners.size()]);
    for (ConnectionEventListener listener : local) {
        if (evt == null) {
            evt = createConnectionEvent(null);
        }
        listener.connectionClosed(evt);
    }
}
Also used : ConnectionEvent(javax.sql.ConnectionEvent) ConnectionEventListener(javax.sql.ConnectionEventListener)

Example 23 with ConnectionEvent

use of javax.sql.ConnectionEvent in project druid by alibaba.

the class DruidDataSource method handleConnectionException.

public void handleConnectionException(DruidPooledConnection pooledConnection, Throwable t, String sql) throws SQLException {
    final DruidConnectionHolder holder = pooledConnection.getConnectionHolder();
    if (holder == null) {
        return;
    }
    errorCountUpdater.incrementAndGet(this);
    lastError = t;
    lastErrorTimeMillis = System.currentTimeMillis();
    if (t instanceof SQLException) {
        SQLException sqlEx = (SQLException) t;
        // broadcastConnectionError
        ConnectionEvent event = new ConnectionEvent(pooledConnection, sqlEx);
        for (ConnectionEventListener eventListener : holder.getConnectionEventListeners()) {
            eventListener.connectionErrorOccurred(event);
        }
        // exceptionSorter.isExceptionFatal
        if (exceptionSorter != null && exceptionSorter.isExceptionFatal(sqlEx)) {
            handleFatalError(pooledConnection, sqlEx, sql);
        }
        throw sqlEx;
    } else {
        throw new SQLException("Error", t);
    }
}
Also used : SQLException(java.sql.SQLException) ConnectionEvent(javax.sql.ConnectionEvent) ConnectionEventListener(javax.sql.ConnectionEventListener)

Example 24 with ConnectionEvent

use of javax.sql.ConnectionEvent in project druid by alibaba.

the class DruidPooledConnection method syncClose.

public void syncClose() throws SQLException {
    lock.lock();
    try {
        if (this.disable || CLOSING_UPDATER.get(this) != 0) {
            return;
        }
        DruidConnectionHolder holder = this.holder;
        if (holder == null) {
            if (dupCloseLogEnable) {
                LOG.error("dup close");
            }
            return;
        }
        if (!CLOSING_UPDATER.compareAndSet(this, 0, 1)) {
            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;
    } finally {
        CLOSING_UPDATER.set(this, 0);
        lock.unlock();
    }
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) Filter(com.alibaba.druid.filter.Filter) ConnectionEvent(javax.sql.ConnectionEvent) ConnectionEventListener(javax.sql.ConnectionEventListener)

Example 25 with ConnectionEvent

use of javax.sql.ConnectionEvent in project druid by alibaba.

the class DruidPooledConnection method close.

@Override
public void close() throws SQLException {
    if (this.disable) {
        return;
    }
    DruidConnectionHolder holder = this.holder;
    if (holder == null) {
        if (dupCloseLogEnable) {
            LOG.error("dup close");
        }
        return;
    }
    DruidAbstractDataSource dataSource = holder.getDataSource();
    boolean isSameThread = this.getOwnerThread() == Thread.currentThread();
    if (!isSameThread) {
        dataSource.setAsyncCloseConnectionEnable(true);
    }
    if (dataSource.isAsyncCloseConnectionEnable()) {
        syncClose();
        return;
    }
    if (!CLOSING_UPDATER.compareAndSet(this, 0, 1)) {
        return;
    }
    try {
        for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
            listener.connectionClosed(new ConnectionEvent(this));
        }
        List<Filter> filters = dataSource.getProxyFilters();
        if (filters.size() > 0) {
            FilterChainImpl filterChain = new FilterChainImpl(dataSource);
            filterChain.dataSource_recycle(this);
        } else {
            recycle();
        }
    } finally {
        CLOSING_UPDATER.set(this, 0);
    }
    this.disable = true;
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) Filter(com.alibaba.druid.filter.Filter) ConnectionEvent(javax.sql.ConnectionEvent) ConnectionEventListener(javax.sql.ConnectionEventListener)

Aggregations

ConnectionEvent (javax.sql.ConnectionEvent)27 ConnectionEventListener (javax.sql.ConnectionEventListener)23 SQLException (java.sql.SQLException)10 PooledConnection (javax.sql.PooledConnection)4 XAConnection (javax.sql.XAConnection)4 Connection (java.sql.Connection)3 Iterator (java.util.Iterator)3 XAResource (javax.transaction.xa.XAResource)3 Filter (com.alibaba.druid.filter.Filter)2 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)2 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)2 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)1 PreparedStatement (java.sql.PreparedStatement)1 Savepoint (java.sql.Savepoint)1 Statement (java.sql.Statement)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Xid (javax.transaction.xa.Xid)1 PooledObject (org.apache.tomcat.dbcp.pool2.PooledObject)1 DefaultPooledObject (org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject)1