Search in sources :

Example 6 with DbException

use of org.adbcj.DbException in project adbcj by mheath.

the class ProtocolHandler method doError.

/**
	 * When an error packet is received, a PgException is created and thrown.  The exception is then handled by
	 * {@link #handleException(AbstractConnection, Throwable)}}
	 *
	 * @param connection  the session under which the exception occurred
	 * @param errorResponseMessage  the message containing the exception
	 */
private void doError(AbstractConnection connection, ErrorResponseMessage errorResponseMessage) {
    // When receiving an error packet, throw exception and let exceptionCaught notify future
    String message = errorResponseMessage.getFields().get(ErrorField.MESSAGE);
    DbException exception;
    if (message == null) {
        exception = new PgException(connection, errorResponseMessage.getFields());
    } else {
        exception = new PgException(connection, message, errorResponseMessage.getFields());
    }
    throw exception;
}
Also used : DbException(org.adbcj.DbException)

Example 7 with DbException

use of org.adbcj.DbException 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)

Example 8 with DbException

use of org.adbcj.DbException in project adbcj by mheath.

the class JdbcConnectionManagerFactory method createConnectionManager.

public ConnectionManager createConnectionManager(String url, String username, String password, Properties properties) throws DbException {
    try {
        URI uri = new URI(url);
        // Throw away the 'adbcj' protocol part of the URL
        uri = new URI(uri.getSchemeSpecificPart());
        String jdbcUrl = uri.toString();
        return new JdbcConnectionManager(jdbcUrl, username, password, properties);
    } catch (URISyntaxException e) {
        throw new DbException(e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DbException(org.adbcj.DbException)

Example 9 with DbException

use of org.adbcj.DbException in project adbcj by mheath.

the class AbstractMySqlConnection method doClose.

public void doClose() {
    connectionManager.removeConnection(this);
    // TODO Make a DbSessionClosedException and use here
    DbException closedException = new DbException("Connection closed");
    if (!getConnectFuture().isDone()) {
        getConnectFuture().setException(closedException);
    }
    errorPendingRequests(closedException);
    synchronized (this) {
        if (closeRequest != null) {
            closeRequest.complete(null);
        }
    }
}
Also used : DbException(org.adbcj.DbException)

Example 10 with DbException

use of org.adbcj.DbException in project adbcj by mheath.

the class MySqlConnectionManagerFactory method createConnectionManager.

@Override
public ConnectionManager createConnectionManager(String url, String username, String password, Properties properties) throws DbException {
    try {
        /*
			 * Parse URL
			 */
        URI uri = new URI(url);
        // Throw away the 'adbcj' protocol part of the URL
        uri = new URI(uri.getSchemeSpecificPart());
        String host = uri.getHost();
        int port = uri.getPort();
        if (port < 0) {
            port = DEFAULT_PORT;
        }
        String path = uri.getPath().trim();
        if (path.length() == 0 || "/".equals(path)) {
            throw new DbException("You must specific a database in the URL path");
        }
        String schema = path.substring(1);
        return new MysqlConnectionManager(host, port, username, password, schema, properties);
    } catch (URISyntaxException e) {
        throw new DbException(e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DbException(org.adbcj.DbException)

Aggregations

DbException (org.adbcj.DbException)16 Connection (org.adbcj.Connection)7 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 SQLException (java.sql.SQLException)2 ResultSet (org.adbcj.ResultSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ConnectionManager (org.adbcj.ConnectionManager)1 DbFuture (org.adbcj.DbFuture)1 DbListener (org.adbcj.DbListener)1 DbFutureConcurrentProxy (org.adbcj.support.DbFutureConcurrentProxy)1 DefaultDbFuture (org.adbcj.support.DefaultDbFuture)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1