use of org.adbcj.DbException in project adbcj by mheath.
the class MinaConnectionManagerFactory method createConnectionManager.
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 schema = uri.getPath().substring(1);
return new MinaConnectionManager(host, port, username, password, schema, properties);
} catch (URISyntaxException e) {
throw new DbException(e);
}
}
use of org.adbcj.DbException in project adbcj by mheath.
the class NettyConnectionManagerFactory method createConnectionManager.
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 schema = uri.getPath().substring(1);
return new NettyConnectionManager(host, port, username, password, schema, properties);
} catch (URISyntaxException e) {
throw new DbException(e);
}
}
use of org.adbcj.DbException in project adbcj by mheath.
the class ConnectSpecialCaseTest method testConnectBadCredentials.
@Parameters({ "url", "user", "password" })
@Test(timeOut = 60000)
public void testConnectBadCredentials(String url, String user, String password) throws InterruptedException {
final boolean[] callbacks = { false };
final CountDownLatch latch = new CountDownLatch(1);
ConnectionManager connectionManager = ConnectionManagerProvider.createConnectionManager(url, user, "__BADPASSWORD__");
try {
DbFuture<Connection> connectFuture = connectionManager.connect().addListener(new DbListener<Connection>() {
public void onCompletion(DbFuture<Connection> future) throws Exception {
callbacks[0] = true;
latch.countDown();
}
});
try {
connectFuture.get();
fail("Connect should have failed because of bad credentials");
} catch (DbException e) {
assertTrue(connectFuture.isDone(), "Connect future should be marked done even though it failed");
assertTrue(!connectFuture.isCancelled(), "Connect future should not be marked as cancelled");
}
assertTrue(latch.await(1, TimeUnit.SECONDS), "Callback was not invoked in time");
assertTrue(callbacks[0], "Connect future callback was not invoked with connect failure");
} finally {
connectionManager.close(true);
}
}
use of org.adbcj.DbException in project adbcj by mheath.
the class TransactionTest method testCommitRollbackWithNoTransaction.
public void testCommitRollbackWithNoTransaction() throws Exception {
Connection connection = connectionManager.connect().get();
try {
// Test commit with no transaction
try {
connection.commit();
Assert.fail("Not in transaction, commit should have failed");
} catch (DbException e) {
// Pass
}
// Test rollback with no transaction
try {
connection.rollback();
Assert.fail("Not in transaction, rollback should have failed");
} catch (DbException e) {
// Pass
}
connection.beginTransaction();
connection.rollback().get();
connection.beginTransaction();
connection.commit().get();
connection.beginTransaction();
} finally {
connection.close(true);
}
}
use of org.adbcj.DbException in project adbcj by mheath.
the class TransactionTest method testBeginTransaction.
public void testBeginTransaction() throws Exception {
Connection connection = connectionManager.connect().get();
try {
Assert.assertTrue(!connection.isInTransaction(), "Connections should not start with transaction started");
connection.beginTransaction();
Assert.assertTrue(connection.isInTransaction(), "Connection should be in transaction");
try {
connection.beginTransaction();
Assert.fail("Should have thrown exception because connection is already in transaction");
} catch (DbException e) {
// Pass
}
} finally {
connection.close(true);
}
}
Aggregations