/** * Gets a connection which may be pooled by the app server or middleware implementation of * DataSource. * * @throws java.sql.SQLException Occurs when the physical database connection cannot be * established. */ public PooledConnection getPooledConnection() throws SQLException { return new PGPooledConnection(getConnection(), defaultAutoCommit); }
/** * Creates the appropriate ConnectionPool to use for this DataSource. * * @return appropriate ConnectionPool to use for this DataSource */ protected PGConnectionPoolDataSource createConnectionPool() { return new PGConnectionPoolDataSource(); }
@Override protected DataSource createDataSource() { final PGSimpleDataSource datasource = new PGSimpleDataSource(); datasource.setServerName(hostname); datasource.setPortNumber(port); datasource.setUser(username); datasource.setPassword(password); datasource.setDatabaseName(database); datasource.setApplicationName("Hermes Unit Tests"); return datasource; }
private Object loadSimpleDataSource(Reference ref) { PGSimpleDataSource ds = new PGSimpleDataSource(); return loadBaseDataSource(ds, ref); }
private Object loadConnectionPool(Reference ref) { PGConnectionPoolDataSource cp = new PGConnectionPoolDataSource(); return loadBaseDataSource(cp, ref); }
/** * Gets a connection which may be pooled by the app server or middleware * implementation of DataSource. * * @throws java.sql.SQLException * Occurs when the physical database connection cannot be established. */ public PooledConnection getPooledConnection() throws SQLException { return new PGPooledConnection(getConnection(), defaultAutoCommit); }
/** * Gets a connection from the connection pool. * * @return A pooled connection. * @throws SQLException Occurs when no pooled connection is available, and a new physical * connection cannot be created. */ public Connection getConnection() throws SQLException { if (!initialized) { initialize(); } return getPooledConnection(); }
/** * Fires a connection error event, but only if we think the exception is fatal. * * @param e the SQLException to consider */ private void fireConnectionError(SQLException e) { if (!isFatalState(e.getSQLState())) { return; } fireConnectionFatalError(e); }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { readBaseObject(in); defaultAutoCommit = in.readBoolean(); } }
private void writeObject(ObjectOutputStream out) throws IOException { writeBaseObject(out); out.writeBoolean(defaultAutoCommit); }
/** * 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); } }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { readBaseObject(in); }
private void writeObject(ObjectOutputStream out) throws IOException { writeBaseObject(out); }
/** * Closes the physical database connection represented by this PooledConnection. If any client has * a connection based on this PooledConnection, it is forcibly closed as well. */ @Override public void close() throws SQLException { if (last != null) { last.close(); if (!con.isClosed()) { if (!con.getAutoCommit()) { try { con.rollback(); } catch (SQLException ignored) { } } } } try { con.close(); } finally { con = null; } }
private Object loadSimpleDataSource(Reference ref) { PGSimpleDataSource ds = new PGSimpleDataSource(); return loadBaseDataSource(ds, ref); }
private Object loadConnectionPool(Reference ref) { PGConnectionPoolDataSource cp = new PGConnectionPoolDataSource(); return loadBaseDataSource(cp, ref); }
/** * Creates the appropriate ConnectionPool to use for this DataSource. */ protected PGConnectionPoolDataSource createConnectionPool() { return new PGConnectionPoolDataSource(); }
/** * Gets a connection which may be pooled by the app server or middleware implementation of * DataSource. * * @throws java.sql.SQLException Occurs when the physical database connection cannot be * established. */ public PooledConnection getPooledConnection(String user, String password) throws SQLException { return new PGPooledConnection(getConnection(user, password), defaultAutoCommit); }
/** * Gets a connection which may be pooled by the app server or middleware * implementation of DataSource. * * @throws java.sql.SQLException * Occurs when the physical database connection cannot be established. */ public PooledConnection getPooledConnection(String user, String password) throws SQLException { return new PGPooledConnection(getConnection(user, password), defaultAutoCommit); }
/** * 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); } }