當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnectionEvent類代碼示例

本文整理匯總了Java中javax.sql.ConnectionEvent的典型用法代碼示例。如果您正苦於以下問題:Java ConnectionEvent類的具體用法?Java ConnectionEvent怎麽用?Java ConnectionEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ConnectionEvent類屬於javax.sql包,在下文中一共展示了ConnectionEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: fireConnectionClosed

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:19,代碼來源:CloudSpannerPooledConnection.java

示例2: fireConnectionFatalError

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Used to fire a connection error event to all listeners.
 */
void fireConnectionFatalError(SQLException e)
{
	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(e);
		}
		listener.connectionErrorOccurred(evt);
	}
}
 
開發者ID:olavloite,項目名稱:spanner-jdbc,代碼行數:19,代碼來源:CloudSpannerPooledConnection.java

示例3: connectionErrorOccurred

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 *
 * A fatal error has occurred and the connection cannot be used anymore.
 * A close event from such a connection should be ignored. The connection should not be reused.
 * A new connection will be created to replace the invalid connection, when the next client
 * calls getConnection().
 */
public synchronized void connectionErrorOccurred(ConnectionEvent event) {

    PooledConnection connection = (PooledConnection) event.getSource();

    connection.removeConnectionEventListener(this);
    this.connectionsInUse.remove(connection);
    this.sessionConnectionWrappers.remove(connection);
    logInfo(
        "Fatal exception occurred on pooled connection. Connection is removed from pool: ");
    logInfo(event.getSQLException());
    closePhysically(connection, "closing invalid, removed connection.");

    //notify threads waiting for connections or for the pool to close.
    //one waiting thread can now create a new connection since the pool has space for a new connection.
    //if a thread waits for the pool to close this could be the last unclosed connection in the pool.
    this.notifyAll();
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:25,代碼來源:ManagedPoolDataSource.java

示例4: callConnectionEventListeners

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Notifies all registered ConnectionEventListeners of ConnectionEvents.
 * Instantiates a new ConnectionEvent which wraps sqlException and invokes
 * either connectionClose or connectionErrorOccurred on listener as
 * appropriate.
 * 
 * @param eventType
 *            value indicating whether connectionClosed or
 *            connectionErrorOccurred called
 * @param sqlException
 *            the exception being thrown
 */
protected synchronized void callConnectionEventListeners(int eventType, SQLException sqlException) {

    if (this.connectionEventListeners == null) {

        return;
    }

    Iterator<Map.Entry<ConnectionEventListener, ConnectionEventListener>> iterator = this.connectionEventListeners.entrySet().iterator();

    ConnectionEvent connectionevent = new ConnectionEvent(this, sqlException);

    while (iterator.hasNext()) {

        ConnectionEventListener connectioneventlistener = iterator.next().getValue();

        if (eventType == CONNECTION_CLOSED_EVENT) {
            connectioneventlistener.connectionClosed(connectionevent);
        } else if (eventType == CONNECTION_ERROR_EVENT) {
            connectioneventlistener.connectionErrorOccurred(connectionevent);
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:35,代碼來源:MysqlPooledConnection.java

示例5: connectionClosed

import javax.sql.ConnectionEvent; //導入依賴的package包/類
public synchronized void connectionClosed(ConnectionEvent event) {

        PooledConnection connection = (PooledConnection) event.getSource();

        this.connectionsInUse.remove(connection);
        this.sessionConnectionWrappers.remove(connection);

        if (!this.isPoolClosed) {
            enqueue(connection);
            logInfo("Connection returned to pool.");
        } else {
            closePhysically(connection, "closing returned connection.");
            logInfo(
                "Connection returned to pool was closed because pool is closed.");
            this.notifyAll();    //notifies evt. threads waiting for connection or for the pool to close.
        }
    }
 
開發者ID:s-store,項目名稱:s-store,代碼行數:18,代碼來源:ManagedPoolDataSource.java

示例6: connectionClosed

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Implementation of call back function from ConnectionEventListener interface. This callback will
 * be invoked on connection close event.
 * 
 * @param event Connection event object
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    try {
      XAConnection conn = (XAConnection) event.getSource();
      XAResource xar = (XAResource) xaResourcesMap.get(conn);
      xaResourcesMap.remove(conn);
      Transaction txn = transManager.getTransaction();
      if (txn != null && xar != null)
        txn.delistResource(xar, XAResource.TMSUCCESS);
      provider.returnConnection(conn);
    } catch (Exception e) {
      String exception =
          "GemFireTransactionDataSource::connectionClosed: Exception occured due to " + e;
      if (logger.isDebugEnabled()) {
        logger.debug(exception, e);
      }
    }
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:26,代碼來源:GemFireTransactionDataSource.java

示例7: connectionErrorOccurred

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Implementation of call back function from ConnectionEventListener interface. This callback will
 * be invoked on connection error event.
 * 
 * @param event
 */
public void connectionErrorOccurred(ConnectionEvent event) {
  if (isActive) {
    try {
      PooledConnection conn = (PooledConnection) event.getSource();
      provider.returnAndExpireConnection(conn);
    } catch (Exception ex) {
      String exception =
          "GemFireConnPooledDataSource::connectionErrorOccured:error in returning and expiring connection due to "
              + ex;
      if (logger.isDebugEnabled()) {
        logger.debug(exception, ex);
      }
    }
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:22,代碼來源:GemFireConnPooledDataSource.java

示例8: fireConnectionEventListeners

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Fire all the {@code ConnectionEventListener}s registered. Callers must
 * synchronize on {@code this} to prevent others from modifying the list of
 * listeners.
 *
 * @param exception the exception that caused the event, or {@code null} if
 * it is a close event
 */
private void fireConnectionEventListeners(SqlException exception) {
    if (!listeners_.isEmpty()) {
        final ConnectionEvent event = (exception == null) ?
            new ConnectionEvent(this) :
            new ConnectionEvent(this, exception.getSQLException(
                physicalConnection_ != null ? physicalConnection_
                    .agent_ : null /* GemStoneAddition */));
        eventIterators++;
        try {
            for (Iterator it = listeners_.iterator(); it.hasNext(); ) {
                final ConnectionEventListener listener =
                    (ConnectionEventListener) it.next();
                if (exception == null) {
                    listener.connectionClosed(event);
                } else {
                    listener.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:32,代碼來源:ClientPooledConnection.java

示例9: fireConnectionEventListeners

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Fire all the {@code ConnectionEventListener}s registered. Callers must
 * synchronize on {@code this} to prevent others from modifying the list of
 * listeners.
 *
 * @param exception the exception that caused the event, or {@code null} if
 * it is a close event
 */
private void fireConnectionEventListeners(SQLException exception) {
    if (eventListener != null && !eventListener.isEmpty()) {
        ConnectionEvent event = new ConnectionEvent(this, exception);
        eventIterators++;
        try {
            for (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:28,代碼來源:EmbedPooledConnection.java

示例10: callConnectionEventListeners

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Notifies all registered ConnectionEventListeners of ConnectionEvents.
 * Instantiates a new ConnectionEvent which wraps sqlException and invokes
 * either connectionClose or connectionErrorOccurred on listener as
 * appropriate.
 * 
 * @param eventType
 *            value indicating whether connectionClosed or
 *            connectionErrorOccurred called
 * @param sqlException
 *            the exception being thrown
 */
protected synchronized void callConnectionEventListeners(int eventType,
		SQLException sqlException) {

	if (this.connectionEventListeners == null) {

		return;
	}

	Iterator<Map.Entry<ConnectionEventListener, ConnectionEventListener>> iterator = this.connectionEventListeners.entrySet().iterator();
	
	ConnectionEvent connectionevent = new ConnectionEvent(this,
			sqlException);

	while (iterator.hasNext()) {

		ConnectionEventListener connectioneventlistener = iterator.next().getValue();

		if (eventType == CONNECTION_CLOSED_EVENT) {
			connectioneventlistener.connectionClosed(connectionevent);
		} else if (eventType == CONNECTION_ERROR_EVENT) {
			connectioneventlistener
					.connectionErrorOccurred(connectionevent);
		}
	}
}
 
開發者ID:hinsenchan,項目名稱:fil_project_mgmt_app_v2,代碼行數:38,代碼來源:MysqlPooledConnection.java

示例11: notifyListener

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * Notify listeners, if there is any, about the connection status.
 * If e is null, the connection is properly closed.
 * @param e
 */
protected synchronized void notifyListener(SQLException e){
	if(listeners != null && !listeners.isEmpty()){
		Iterator<ConnectionEventListener> iter = listeners.iterator();
		while(iter.hasNext()){
			ConnectionEventListener listener = iter.next();
			if(e == null){
				//no exception
				listener.connectionClosed(new ConnectionEvent(this));
			}else{
				//exception occurred
				listener.connectionErrorOccurred(new ConnectionEvent(this, e));	
			}
		}
	}	
}
 
開發者ID:kenweezy,項目名稱:teiid,代碼行數:21,代碼來源:XAConnectionImpl.java

示例12: connectionClosed

import javax.sql.ConnectionEvent; //導入依賴的package包/類
@Override
public synchronized void connectionClosed(ConnectionEvent event)
{
	PooledCassandraConnection connection = (PooledCassandraConnection) event.getSource();
	usedConnections.remove(connection);
	int freeConnectionsCount = freeConnections.size();
	if (freeConnectionsCount < MIN_POOL_SIZE)
	{
		freeConnections.add(connection);
	}
	else
	{
		try
		{
			connection.close();
		}
		catch (SQLException e)
		{
			logger.error(e.getMessage());
		}
	}
}
 
開發者ID:adejanovski,項目名稱:cassandra-jdbc-wrapper,代碼行數:23,代碼來源:PooledCassandraDataSource.java

示例13: connectionErrorOccurred

import javax.sql.ConnectionEvent; //導入依賴的package包/類
@Override
public synchronized void connectionErrorOccurred(ConnectionEvent event)
{
	PooledCassandraConnection connection = (PooledCassandraConnection) event.getSource();
	try
	{
		if (!connection.getConnection().isValid(CONNECTION_IS_VALID_TIMEOUT)) {
			connection.getConnection().close();
		}
	}
	catch (SQLException e)
	{
		logger.error(e.getMessage());
	}
	usedConnections.remove(connection);
}
 
開發者ID:adejanovski,項目名稱:cassandra-jdbc-wrapper,代碼行數:17,代碼來源:PooledCassandraDataSource.java

示例14: testConstructorConnection

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * @tests {@link javax.sql.ConnectionEvent#ConnectionEvent(PooledConnection)}
 *
 */
@TestTargetNew(
    level = TestLevel.SUFFICIENT,
    notes = "functional test missing but not feasible: no implementation available.",
    method = "ConnectionEvent",
    args = {javax.sql.PooledConnection.class}
)
public void testConstructorConnection() {
    try {
        new ConnectionEvent(null);
        fail("illegal argument exception expected");
    } catch (IllegalArgumentException e) {
    }

    Impl_PooledConnection ipc = new Impl_PooledConnection();
    ConnectionEvent ce = new ConnectionEvent(ipc);
    assertSame(ipc, ce.getSource());
    assertNull(ce.getSQLException());

    //cross test
    ConnectionEvent ce2 = new ConnectionEvent(ipc,null);
    assertSame(ce2.getSource(),ce.getSource());
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:27,代碼來源:ConnectionEventTest.java

示例15: testGetSQLException

import javax.sql.ConnectionEvent; //導入依賴的package包/類
/**
 * @tests {@link javax.sql.ConnectionEvent#getSQLException()}
 */
@TestTargetNew(
    level = TestLevel.SUFFICIENT,
    notes = "functional test missing but not feasible: no implementation available.",
    method = "getSQLException",
    args = {}
)
public void testGetSQLException() {

    Impl_PooledConnection ipc = new Impl_PooledConnection();
    ConnectionEvent ce = new ConnectionEvent(ipc);

    ConnectionEvent ce2 = new ConnectionEvent(ipc, null);
    assertNull(ce.getSQLException());
    assertEquals(ce2.getSQLException(), ce.getSQLException());

    SQLException e = new SQLException();
    ConnectionEvent ce3 = new ConnectionEvent(ipc, e);
    assertNotNull(ce3.getSQLException());
    assertNotSame(ce3.getSQLException(), ce2.getSQLException());

}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:25,代碼來源:ConnectionEventTest.java


注:本文中的javax.sql.ConnectionEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。