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;
}
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;
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations