当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionEventListener类代码示例

本文整理汇总了Java中javax.sql.ConnectionEventListener的典型用法代码示例。如果您正苦于以下问题:Java ConnectionEventListener类的具体用法?Java ConnectionEventListener怎么用?Java ConnectionEventListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionEventListener类属于javax.sql包,在下文中一共展示了ConnectionEventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fireConnectionClosed

import javax.sql.ConnectionEventListener; //导入依赖的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.ConnectionEventListener; //导入依赖的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: callConnectionEventListeners

import javax.sql.ConnectionEventListener; //导入依赖的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

示例4: getNewPoolConnection

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
 * Creates a new connection for the pool. This connection can participate in the transactions.
 * 
 * @return the connection from the database as PooledConnection object.
 */
@Override
public Object getNewPoolConnection() throws PoolException {
  if (m_xads != null) {
    PooledConnection poolConn = null;
    try {
      poolConn = m_xads.getXAConnection(configProps.getUser(), configProps.getPassword());
    } catch (SQLException sqx) {
      throw new PoolException(
          LocalizedStrings.TranxPoolCacheImpl_TRANXPOOLCACHEIMPLGETNEWCONNECTION_EXCEPTION_IN_CREATING_NEW_TRANSACTION_POOLEDCONNECTION
              .toLocalizedString(),
          sqx);
    }
    poolConn.addConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
    return poolConn;
  } else {
    if (logger.isDebugEnabled()) {
      logger.debug(
          "TranxPoolCacheImpl::getNewConnection: ConnectionPoolCache not intialized with XADatasource");
    }
    throw new PoolException(
        LocalizedStrings.TranxPoolCacheImpl_TRANXPOOLCACHEIMPLGETNEWCONNECTION_CONNECTIONPOOLCACHE_NOT_INTIALIZED_WITH_XADATASOURCE
            .toLocalizedString());
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:30,代码来源:TranxPoolCacheImpl.java

示例5: destroyPooledConnection

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
 * This method destroys the connection.
 */
@Override
void destroyPooledConnection(Object connectionObject) {
  try {
    ((PooledConnection) connectionObject)
        .removeConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
    ((PooledConnection) connectionObject).close();
    connectionObject = null;
  } catch (Exception ex) {
    if (logger.isTraceEnabled()) {
      logger.trace(
          "AbstractPoolcache::destroyPooledConnection:Exception in closing the connection.Ignoring it. The exeption is {}",
          ex.getMessage(), ex);
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:ConnectionPoolCacheImpl.java

示例6: getNewPoolConnection

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
 * Creates a new connection for the pool.
 * 
 * @return the connection from the database as Object.
 * @throws PoolException
 */
@Override
public Object getNewPoolConnection() throws PoolException {
  if (m_cpds != null) {
    PooledConnection poolConn = null;
    try {
      poolConn = m_cpds.getPooledConnection(configProps.getUser(), configProps.getPassword());
    } catch (SQLException sqx) {
      throw new PoolException(
          LocalizedStrings.ConnectionPoolCacheImpl_CONNECTIONPOOLCACHEIMPLGENEWCONNECTION_EXCEPTION_IN_CREATING_NEW_POOLEDCONNECTION
              .toLocalizedString(),
          sqx);
    }
    poolConn.addConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
    return poolConn;
  } else {
    if (logger.isDebugEnabled()) {
      logger.debug(
          "ConnectionPoolCacheImpl::geNewConnection: ConnectionPoolCache not intialized with ConnectionPoolDatasource");
    }
    throw new PoolException(
        LocalizedStrings.ConnectionPoolCacheImpl_CONNECTIONPOOLCACHEIMPLGENEWCONNECTION_CONNECTIONPOOLCACHE_NOT_INTIALIZED_WITH_CONNECTIONPOOLDATASOURCE
            .toLocalizedString());
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:31,代码来源:ConnectionPoolCacheImpl.java

示例7: addConnectionEventListener

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
public synchronized void addConnectionEventListener(
                                        ConnectionEventListener listener) {
    if (logWriter_ != null) {
        logWriter_.traceEntry(this, "addConnectionEventListener", listener);
    }

    if (listener == null) {
        // Ignore the listener if it is null. Otherwise, an exception is
        // thrown when a connection event occurs (DERBY-3307).
        return;
    }

    if (eventIterators > 0) {
        // DERBY-3401: Someone is iterating over the ArrayList, and since
        // we were able to synchronize on this, that someone is us. Clone
        // the list of listeners in order to prevent invalidation of the
        // iterator.
        listeners_ = (ArrayList) listeners_.clone();
    }
    listeners_.add(listener);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:22,代码来源:ClientPooledConnection.java

示例8: fireConnectionEventListeners

import javax.sql.ConnectionEventListener; //导入依赖的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: addConnectionEventListener

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
	Add an event listener.
 */
public final synchronized void addConnectionEventListener(ConnectionEventListener listener) 
{
	if (!isActive)
		return;
	if (listener == null)
		return;
       if (eventListener == null) {
           eventListener = new ArrayList();
       } else if (eventIterators > 0) {
           // DERBY-3401: Someone is iterating over the ArrayList, and since
           // we were able to synchronize on this, that someone is us. Clone
           // the list of listeners in order to prevent invalidation of the
           // iterator.
           eventListener = (ArrayList) eventListener.clone();
       }
       eventListener.add(listener);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:21,代码来源:EmbedPooledConnection.java

示例10: fireConnectionEventListeners

import javax.sql.ConnectionEventListener; //导入依赖的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

示例11: destroyPooledConnection

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
 *  
 */
@Override
void destroyPooledConnection(Object connectionObject) {
  try {
    ((PooledConnection) connectionObject)
        .removeConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
    ((PooledConnection) connectionObject).close();
    connectionObject = null;
  }
  catch (Exception ex) {
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.finerEnabled())
        writer
            .finer(
                "AbstractPoolcache::destroyPooledConnection:Exception in closing the connection.Ignoring it. The exeption is "
                    + ex.toString(), ex);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:21,代码来源:TranxPoolCacheImpl.java

示例12: getNewPoolConnection

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
 * Creates a new connection for the pool. This connection can participate in
 * the transactions.
 * 
 * @return the connection from the database as PooledConnection object.
 */
@Override
public Object getNewPoolConnection() throws PoolException {
  if (m_xads != null) {
    PooledConnection poolConn = null;
    try {
      poolConn = m_xads.getXAConnection(configProps.getUser(), configProps
          .getPassword());
    }
    catch (SQLException sqx) {
      throw new PoolException(LocalizedStrings.TranxPoolCacheImpl_TRANXPOOLCACHEIMPLGETNEWCONNECTION_EXCEPTION_IN_CREATING_NEW_TRANSACTION_POOLEDCONNECTION.toLocalizedString(), sqx);
    }
    poolConn
        .addConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
    return poolConn;
  }
  else {
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.fineEnabled()) writer.fine("TranxPoolCacheImpl::getNewConnection: ConnectionPoolCache not intialized with XADatasource");
    throw new PoolException(LocalizedStrings.TranxPoolCacheImpl_TRANXPOOLCACHEIMPLGETNEWCONNECTION_CONNECTIONPOOLCACHE_NOT_INTIALIZED_WITH_XADATASOURCE.toLocalizedString());
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:28,代码来源:TranxPoolCacheImpl.java

示例13: destroyPooledConnection

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
 * This method destroys the connection.
 */
@Override
void destroyPooledConnection(Object connectionObject) {
  try {
    ((PooledConnection) connectionObject)
        .removeConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
    ((PooledConnection) connectionObject).close();
    connectionObject = null;
  }
  catch (Exception ex) {
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.finerEnabled())
        writer
            .finer(
                "AbstractPoolcache::destroyPooledConnection:Exception in closing the connection.Ignoring it. The exeption is "
                    + ex.toString(), ex);
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:21,代码来源:ConnectionPoolCacheImpl.java

示例14: getNewPoolConnection

import javax.sql.ConnectionEventListener; //导入依赖的package包/类
/**
 * Creates a new connection for the pool.
 * 
 * @return the connection from the database as Object.
 * @throws PoolException
 */
@Override
public Object getNewPoolConnection() throws PoolException {
  if (m_cpds != null) {
    PooledConnection poolConn = null;
    try {
      poolConn = m_cpds.getPooledConnection(configProps.getUser(),
          configProps.getPassword());
    }
    catch (SQLException sqx) {
      throw new PoolException(LocalizedStrings.ConnectionPoolCacheImpl_CONNECTIONPOOLCACHEIMPLGENEWCONNECTION_EXCEPTION_IN_CREATING_NEW_POOLEDCONNECTION.toLocalizedString(), sqx);
    }
    poolConn
        .addConnectionEventListener((javax.sql.ConnectionEventListener) connEventListner);
    return poolConn;
  }
  else {
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    if (writer.fineEnabled()) writer.fine("ConnectionPoolCacheImpl::geNewConnection: ConnectionPoolCache not intialized with ConnectionPoolDatasource");
    throw new PoolException(LocalizedStrings.ConnectionPoolCacheImpl_CONNECTIONPOOLCACHEIMPLGENEWCONNECTION_CONNECTIONPOOLCACHE_NOT_INTIALIZED_WITH_CONNECTIONPOOLDATASOURCE.toLocalizedString());
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:28,代码来源:ConnectionPoolCacheImpl.java

示例15: callConnectionEventListeners

import javax.sql.ConnectionEventListener; //导入依赖的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


注:本文中的javax.sql.ConnectionEventListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。