/** * Use to check if there is a connection present on current thread. * * @return true if finds connection on current thread, false if not. */ public boolean hasConnection() { return null != ConnectionsAccess.getConnection(name); }
/** * Provides connection from current thread. * * @return connection from current thread. */ public Connection connection() { Connection connection = ConnectionsAccess.getConnection(name); if (connection == null) { throw new DBException("there is no connection '" + name + "' on this thread, are you sure you opened it?"); } return connection; }
private void checkExistingConnection(String name) { if (null != ConnectionsAccess.getConnection(name)) { throw new DBException("Cannot open a new connection because existing connection is still on current thread, name: " + name + ", connection instance: " + connection() + ". This might indicate a logical error in your application."); } }
/** * Opens local transaction. */ public void openTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot open transaction, connection '" + name + "' not available"); } c.setAutoCommit(false); LogFilter.log(LOGGER, LogLevel.DEBUG, "Transaction opened"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }
/** * Commits local transaction. */ public void commitTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot commit transaction, connection '" + name + "' not available"); } c.commit(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Transaction committed"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }
/** * Rolls back local transaction. */ public void rollbackTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot rollback transaction, connection '" + name + "' not available"); } c.rollback(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Transaction rolled back"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }
/** * Closes connection and detaches it from current thread. * @param suppressWarning true to not display a warning in case of a problem (connection not there) */ public void close(boolean suppressWarning) { try { Connection connection = ConnectionsAccess.getConnection(name); if(connection == null){ throw new DBException("cannot close connection '" + name + "' because it is not available"); } StatementCache.instance().cleanStatementCache(connection); connection.close(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Closed connection: {}", connection); } catch (Exception e) { if (!suppressWarning) { LOGGER.warn("Could not close connection! MUST INVESTIGATE POTENTIAL CONNECTION LEAK!", e); } } finally { ConnectionsAccess.detach(name); // let's free the thread from connection } }
Connection c = ConnectionsAccess.getConnection(dbName); if(c == null){ throw new DBException("Failed to retrieve metadata from DB, connection: '" + dbName + "' is not available");
/** * Detaches a connection from current thread and returns an instance of it. This method does not close a connection. * Use it for cases of advanced connection management, such as integration with Spring Framework. * * @return instance of a connection detached from current thread by name passed to constructor. */ public Connection detach() { Connection connection = ConnectionsAccess.getConnection(name); try { if (connection == null) { throw new DBException("cannot detach connection '" + name + "' because it is not available"); } ConnectionsAccess.detach(name); // let's free the thread from connection StatementCache.instance().cleanStatementCache(connection); } catch (DBException e) { LogFilter.log(LOGGER, LogLevel.ERROR, "Could not close connection! MUST INVESTIGATE POTENTIAL CONNECTION LEAK!", e); } return connection; }
/** * Use to check if there is a connection present on current thread. * * @return true if finds connection on current thread, false if not. */ public boolean hasConnection() { return null != ConnectionsAccess.getConnection(name); }
/** * Use to check if there is a connection present on current thread. * * @return true if finds connection on current thread, false if not. */ public boolean hasConnection() { return null != ConnectionsAccess.getConnection(name); }
/** * Provides connection from current thread. * * @return connection from current thread. */ public Connection connection() { Connection connection = ConnectionsAccess.getConnection(name); if (connection == null) { throw new DBException("there is no connection '" + name + "' on this thread, are you sure you opened it?"); } return connection; }
/** * Provides connection from current thread. * * @return connection from current thread. */ public Connection connection() { Connection connection = ConnectionsAccess.getConnection(name); if (connection == null) { throw new DBException("there is no connection '" + name + "' on this thread, are you sure you opened it?"); } return connection; }
private void checkExistingConnection(String name) { if (null != ConnectionsAccess.getConnection(name)) { throw new DBException("Cannot open a new connection because existing connection is still on current thread, name: " + name + ", connection instance: " + connection() + ". This might indicate a logical error in your application."); } }
private void checkExistingConnection(String name) { if (null != ConnectionsAccess.getConnection(name)) { throw new DBException("Cannot open a new connection because existing connection is still on current thread, name: " + name + ", connection instance: " + connection() + ". This might indicate a logical error in your application."); } }
/** * Opens local transaction. */ public void openTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot open transaction, connection '" + name + "' not available"); } c.setAutoCommit(false); LogFilter.log(logger, "Transaction opened"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }
/** * Commits local transaction. */ public void commitTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot commit transaction, connection '" + name + "' not available"); } c.commit(); LogFilter.log(logger, "Transaction committed"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }
/** * Opens local transaction. */ public void openTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot open transaction, connection '" + name + "' not available"); } c.setAutoCommit(false); LogFilter.log(LOGGER, LogLevel.DEBUG, "Transaction opened"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }
/** * Commits local transaction. */ public void commitTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot commit transaction, connection '" + name + "' not available"); } c.commit(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Transaction committed"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }
/** * Rolls back local transaction. */ public void rollbackTransaction() { try { Connection c = ConnectionsAccess.getConnection(name); if (c == null) { throw new DBException("Cannot rollback transaction, connection '" + name + "' not available"); } c.rollback(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Transaction rolled back"); } catch (SQLException ex) { throw new DBException(ex.getMessage(), ex); } }