Search in sources :

Example 1 with DbFutureConcurrentProxy

use of org.adbcj.support.DbFutureConcurrentProxy in project adbcj by mheath.

the class JdbcConnectionManager method connect.

public DbFuture<Connection> connect() throws DbException {
    if (isClosed()) {
        throw new DbException("This connection manager is closed");
    }
    final DbFutureConcurrentProxy<Connection> future = new DbFutureConcurrentProxy<Connection>();
    Future<Connection> executorFuture = executorService.submit(new Callable<Connection>() {

        public Connection call() throws Exception {
            try {
                java.sql.Connection jdbcConnection = DriverManager.getConnection(jdbcUrl, properties);
                JdbcConnection connection = new JdbcConnection(JdbcConnectionManager.this, jdbcConnection);
                synchronized (lock) {
                    if (isClosed()) {
                        connection.close(true);
                        future.setException(new DbException("Connection manager closed"));
                    } else {
                        connections.add(connection);
                        future.setValue(connection);
                    }
                }
                return connection;
            } catch (SQLException e) {
                future.setException(new DbException(e));
                e.printStackTrace();
                throw e;
            } finally {
                future.setDone();
            }
        }
    });
    future.setFuture(executorFuture);
    return future;
}
Also used : DbFutureConcurrentProxy(org.adbcj.support.DbFutureConcurrentProxy) SQLException(java.sql.SQLException) Connection(org.adbcj.Connection) DbException(org.adbcj.DbException) SQLException(java.sql.SQLException) DbException(org.adbcj.DbException)

Aggregations

SQLException (java.sql.SQLException)1 Connection (org.adbcj.Connection)1 DbException (org.adbcj.DbException)1 DbFutureConcurrentProxy (org.adbcj.support.DbFutureConcurrentProxy)1