javax.sql.ConnectionEvent类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中javax.sql.ConnectionEvent类的一些代码示例,展示了ConnectionEvent类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConnectionEvent类的具体详情如下:
包路径:javax.sql.ConnectionEvent
类名称:ConnectionEvent

ConnectionEvent介绍

[英]Sent when specific events happen on a PooledConnection object. These events are a facility to report when an application closes the pooled connection or when an error occurs in the pooled connection.
[中]在PooledConnection对象上发生特定事件时发送。这些事件是应用程序关闭池连接或池连接中发生错误时报告的工具。

代码示例

代码示例来源:origin: com.h2database/h2

/**
 * INTERNAL
 */
void closedHandle() {
  debugCode("closedHandle();");
  ConnectionEvent event = new ConnectionEvent(this);
  // go backward so that a listener can remove itself
  // (otherwise we need to clone the list)
  for (int i = listeners.size() - 1; i >= 0; i--) {
    ConnectionEventListener listener = listeners.get(i);
    listener.connectionClosed(event);
  }
  handleConn = null;
}

代码示例来源:origin: org.postgresql/postgresql

public void connectionClosed(ConnectionEvent event) {
 ((PooledConnection) event.getSource()).removeConnectionEventListener(this);
 synchronized (lock) {
  if (available == null) {
   return; // DataSource has been closed
  }
  boolean removed = used.remove(event.getSource());
  if (removed) {
   available.push((PooledConnection) event.getSource());
   // There's now a new connection available
   lock.notify();
  } else {
   // a connection error occurred
  }
 }
}

代码示例来源:origin: org.apache.commons/commons-dbcp2

/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
  final PooledConnection pc = (PooledConnection) event.getSource();
  if (null != event.getSQLException()) {
    System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
  }
  pc.removeConnectionEventListener(this);
  final PooledConnectionAndInfo pci = pcMap.get(pc);
  if (pci == null) {
    throw new IllegalStateException(NO_KEY_MESSAGE);
  }
  try {
    pool.invalidateObject(pci);
  } catch (final Exception e) {
    System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
    e.printStackTrace();
  }
}

代码示例来源:origin: alibaba/druid

public void handleConnectionException(DruidPooledConnection pooledConnection, Throwable t, String sql) throws SQLException {
  final DruidConnectionHolder holder = pooledConnection.getConnectionHolder();
  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);
  }
}

代码示例来源:origin: org.javasimon/javasimon-jdbc41

@Override
public void connectionClosed(ConnectionEvent event) {
  originalListener.connectionClosed(new ConnectionEvent(SimonPooledConnection.this, event.getSQLException()));
}

代码示例来源:origin: org.javasimon/javasimon-jdbc41

@Override
  public void connectionErrorOccurred(ConnectionEvent event) {
    originalListener.connectionErrorOccurred(new ConnectionEvent(SimonPooledConnection.this, event.getSQLException()));
  }
}

代码示例来源:origin: org.apache.commons/commons-dbcp2

@Override
public void connectionClosed(final ConnectionEvent event) {
  final PooledConnection pc = (PooledConnection) event.getSource();
  pc.removeConnectionEventListener(this);
  try {
    pc.close();
  } catch (final SQLException e) {
    System.err.println("Failed to close XAConnection");
    e.printStackTrace();
  }
}

代码示例来源:origin: ha-jdbc/ha-jdbc

private ConnectionEvent getEvent(ConnectionEvent event)
  {
    Object source = event.getSource();
    C connection = this.proxyFactory.get(this.database);
    
    if (Proxy.isProxyClass(source.getClass()) && Proxy.getInvocationHandler(source) instanceof AbstractPooledConnectionInvocationHandler)
    {
      return new ConnectionEvent(connection, event.getSQLException());
    }
    
    return event.getSource().equals(connection) ? event : null;
  }
}

代码示例来源:origin: apache/geode

/**
 * Implementation of call back function from ConnectionEventListener interface. This callback will
 * be invoked on connection close event.
 *
 */
@Override
public void connectionClosed(ConnectionEvent event) {
 if (isActive) {
  try {
   PooledConnection conn = (PooledConnection) event.getSource();
   provider.returnConnection(conn);
  } catch (Exception ex) {
   String exception = "GemFireConnPooledDataSource::connectionclosed:Exception =" + ex;
   if (logger.isDebugEnabled()) {
    logger.debug(exception, ex);
   }
  }
 }
}

代码示例来源:origin: org.postgresql/postgresql

protected ConnectionEvent createConnectionEvent(SQLException e) {
 return new ConnectionEvent(this, e);
}

代码示例来源:origin: org.tranql/tranql-connector

public void connectionErrorOccurred(ConnectionEvent event) {
    Exception e = event.getSQLException();
    unfilteredConnectionError(e);
  }
});

代码示例来源:origin: org.apache.tomcat/tomcat-dbcp

/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
  final PooledConnection pc = (PooledConnection) event.getSource();
  if (null != event.getSQLException()) {
    System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
  }
  pc.removeConnectionEventListener(this);
  final PooledConnectionAndInfo pci = pcMap.get(pc);
  if (pci == null) {
    throw new IllegalStateException(NO_KEY_MESSAGE);
  }
  try {
    pool.invalidateObject(pci);
  } catch (final Exception e) {
    System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
    e.printStackTrace();
  }
}

代码示例来源:origin: NLPchina/elasticsearch-sql

ConnectionEvent event = new ConnectionEvent(pooledConnection, sqlEx);
for (ConnectionEventListener eventListener : holder.getConnectionEventListeners()) {
  eventListener.connectionErrorOccurred(event);

代码示例来源:origin: org.bytesoft/bytejta-supports

public void connectionClosed(ConnectionEvent event) {
  Iterator<ConnectionEventListener> itr = this.connectionEventListeners.iterator();
  while (itr.hasNext()) {
    ConnectionEventListener listener = itr.next();
    SQLException sqlException = event.getSQLException();
    ConnectionEvent connectionEvent = new ConnectionEvent(this, sqlException);
    try {
      listener.connectionClosed(connectionEvent);
    } catch (RuntimeException error) {
      logger.warn("Error occurred!", error);
    }
  } // end-while (itr.hasNext())
}

代码示例来源:origin: liuyangming/ByteJTA

public void connectionErrorOccurred(ConnectionEvent event) {
  Iterator<ConnectionEventListener> itr = this.connectionEventListeners.iterator();
  while (itr.hasNext()) {
    ConnectionEventListener listener = itr.next();
    SQLException sqlException = event.getSQLException();
    ConnectionEvent connectionEvent = new ConnectionEvent(this, sqlException);
    try {
      listener.connectionErrorOccurred(connectionEvent);
    } catch (RuntimeException error) {
      logger.warn("Error occurred!", error);
    }
  } // end-while (itr.hasNext())
}

代码示例来源:origin: com.bbossgroups/bboss-persistent

@Override
public void connectionClosed(ConnectionEvent event) {
  PooledConnection pc = (PooledConnection) event.getSource();
  pc.removeConnectionEventListener(this);
  try {
    pc.close();
  } catch (SQLException e) {
    System.err.println("Failed to close XAConnection");
    e.printStackTrace();
  }
}

代码示例来源:origin: apache/geode

/**
 * Implementation of call back function from ConnectionEventListener interface. This callback will
 * be invoked on connection error event.
 *
 */
@Override
public void connectionErrorOccurred(ConnectionEvent event) {
 if (isActive) {
  try {
   PooledConnection conn = (PooledConnection) event.getSource();
   provider.returnAndExpireConnection(conn);
  } catch (Exception ex) {
   String exception =
     "GemFireConnPooledDataSource::connectionErrorOccurred:error in returning and expiring connection due to "
       + ex;
   if (logger.isDebugEnabled()) {
    logger.debug(exception, ex);
   }
  }
 }
}

代码示例来源:origin: postgresql/postgresql

protected ConnectionEvent createConnectionEvent(SQLException sqle)
{
  return new ConnectionEvent(this, sqle);
}

代码示例来源:origin: org.tranql/tranql-connector

public void connectionErrorOccurred(ConnectionEvent event) {
    Exception e = event.getSQLException();
    unfilteredConnectionError(e);
  }
});

代码示例来源:origin: alibaba/druid

public void syncClose() throws SQLException {
  lock.lock();
  try {
    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;
  } finally {
    lock.unlock();
  }
}

相关文章

微信公众号

最新文章

更多