📄 legacydbconnectionfactory.java
字号:
* * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public void clearWarnings() throws SQLException { checkAccess(); try { m_delegate.clearWarnings(); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { checkAccess(); try { return m_delegate.createStatement(resultSetType, resultSetConcurrency); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { checkAccess(); try { return m_delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkAccess(); try { return m_delegate.prepareStatement(sql, resultSetType, resultSetConcurrency); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { checkAccess(); try { return m_delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { checkAccess(); try { return m_delegate.prepareCall(sql, resultSetType, resultSetConcurrency); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { checkAccess(); try { return m_delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public Map getTypeMap() throws SQLException { checkAccess(); try { return m_delegate.getTypeMap(); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } /** * Forwards the request to the encapsulated connection after access to * the connection is granted. * * @throws java.sql.SQLException * May be thrown by the encapsulated connection */ public void setTypeMap(Map map) throws SQLException { checkAccess(); try { m_delegate.setTypeMap(map); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } public String toString() { return m_delegate.toString(); } public int getHoldability() throws SQLException { try { return m_delegate.getHoldability(); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } public void setHoldability(int holdability) throws SQLException { try { m_delegate.setHoldability(holdability); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } public Savepoint setSavepoint() throws SQLException { try { return m_delegate.setSavepoint(); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } public Savepoint setSavepoint(String name) throws SQLException { try { return m_delegate.setSavepoint(name); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } public void releaseSavepoint(Savepoint savepoint) throws SQLException { try { m_delegate.releaseSavepoint(savepoint); } catch (SQLException ex) { m_hadError = true; ThreadCategory.getInstance(getClass()).debug("setting bad flag [id=" + this + "]", ex); throw ex; } } } public LegacyDbConnectionFactory(DbConfiguration dbConfig) throws ClassNotFoundException { m_dbcCache = new LinkedList(); m_dbConfig = dbConfig; Class.forName(m_dbConfig.getDriverClassName()); DriverManager.setLoginTimeout(180); } /** * Return a new database connection to the database configured in the * <tt>opennms-database.xml</tt>. The database connection is not managed * by the factory and must be release by the caller by using the * <code>close</code> method. * * @return a new database connection to the database configured in the * <tt>opennms-database.xml</tt> * * @throws java.sql.SQLException * Thrown if there is an error opening the connection to the * database. */ public Connection getConnection() throws SQLException { // lock the database cache for the open // Category log = ThreadCategory.getInstance(getClass()); boolean isTracing = log.isDebugEnabled(); CachedConnection cdbc = null; synchronized (m_dbcCache) { // look at each reference, removing those // that garbage collection has destroyed // while (cdbc == null && !m_dbcCache.isEmpty()) { cdbc = (CachedConnection) m_dbcCache.removeFirst(); synchronized (cdbc) { if (cdbc.isAvailable() && cdbc.isBad()) { if (isTracing) log.debug("removed bad connection from pool [id=" + cdbc + "]"); continue; } else if (cdbc.isAvailable()) { // mark in use and return // to caller. This will now be a // strongly referenced instance // cdbc.markUsed(); if (isTracing) log.debug("reusing previous connection [id=" + cdbc + "]"); } } if (!m_dbcCache.isEmpty()) { long age = ((CachedConnection) m_dbcCache.getLast()).age(); if (age >= MAX_AGE) { CachedConnection disconnect = (CachedConnection) m_dbcCache.removeLast(); if (isTracing) log.debug("removing expired connection [id=" + disconnect + "]"); try { disconnect.m_delegate.close(); } catch (SQLException e) { if (isTracing) log.debug("An error occured closing delegate", e); } } else if (isTracing) { log.debug("stack bottom is " + age + "ms old"); log.debug("stack size is " + m_dbcCache.size()); } } } } // no need to have connection creation syncrhonized // unable to find one that was not in // use so a new one has been allocated // if (cdbc == null) { cdbc = new CachedConnection(DriverManager.getConnection(getDriverUrl(), getDriverUser(), getDriverPass()), this); cdbc.markUsed(); if (isTracing) log.debug("created new JDBC connection, no previous reference available"); } return cdbc; } private String getDriverUrl() { return m_dbConfig.getDriverUrl(); } private String getDriverUser() { return m_dbConfig.getDriverUser(); } private String getDriverPass() { return m_dbConfig.getDriverPass(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -