use of org.firebirdsql.jdbc.FBSQLException in project jaybird by FirebirdSQL.
the class FBXADataSource method initialize.
private void initialize() throws SQLException {
synchronized (lock) {
if (internalDs != null) {
return;
}
try {
GDSType gdsType = GDSType.getType(getType());
if (gdsType == null) {
gdsType = GDSFactory.getDefaultGDSType();
}
FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(gdsType, getConnectionProperties());
mcf.setDefaultConnectionManager(new XAConnectionManager());
internalDs = (FBDataSource) mcf.createConnectionFactory();
internalDs.setLogWriter(getLogWriter());
} catch (ResourceException e) {
throw new FBSQLException(e);
}
}
}
use of org.firebirdsql.jdbc.FBSQLException in project jaybird by FirebirdSQL.
the class PooledConnectionHandler method invoke.
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Methods from object
if (method.equals(TO_STRING)) {
return "Proxy for " + connection;
}
if (method.equals(EQUALS)) {
// nulled after closing
return proxy == args[0];
}
if (method.equals(HASH_CODE)) {
// nulled after closing
return System.identityHashCode(proxy);
}
// Other methods from object
if (method.getDeclaringClass().equals(Object.class)) {
try {
return method.invoke(connection, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
}
}
// Methods from Connection
if (method.equals(CONNECTION_IS_CLOSED)) {
return isClosed();
}
if (isClosed() && !method.equals(CONNECTION_CLOSE)) {
String message = forcedClose ? FORCIBLY_CLOSED_MESSAGE : CLOSED_MESSAGE;
throw new FBSQLException(message, SQLStateConstants.SQL_STATE_CONNECTION_CLOSED);
}
try {
// Life cycle methods
if (method.equals(CONNECTION_CLOSE)) {
if (!isClosed()) {
handleClose(true);
}
return null;
}
if (method.getDeclaringClass().equals(Connection.class) && STATEMENT_CREATION_METHOD_NAMES.contains(method.getName())) {
Statement pstmt = (Statement) method.invoke(connection, args);
StatementHandler stmtHandler = new StatementHandler(this, pstmt);
openStatements.add(stmtHandler);
return stmtHandler.getProxy();
}
// All other methods
return method.invoke(connection, args);
} catch (InvocationTargetException ite) {
Throwable inner = ite.getTargetException();
if (inner instanceof SQLException) {
owner.fireConnectionError((SQLException) inner);
}
throw inner;
} catch (SQLException se) {
owner.fireConnectionError(se);
throw se;
}
}
use of org.firebirdsql.jdbc.FBSQLException in project jaybird by FirebirdSQL.
the class TestPooledConnectionHandlerMock method testException_Notify.
/**
* Calling a Connection method on an open proxy should notify the owner of
* the occurrence of an exception.
*
* @throws SQLException
*/
@Test
public void testException_Notify() throws SQLException {
final FirebirdConnection physicalConnection = context.mock(FirebirdConnection.class);
final FBPooledConnection pooled = context.mock(FBPooledConnection.class);
final PooledConnectionHandler handler = new PooledConnectionHandler(physicalConnection, pooled);
final Sequence exceptionSequence = context.sequence("exceptionSequence");
context.checking(new Expectations() {
{
SQLException sqle = new FBSQLException("Mock Exception");
oneOf(physicalConnection).clearWarnings();
will(throwException(sqle));
inSequence(exceptionSequence);
oneOf(pooled).fireConnectionError(sqle);
inSequence(exceptionSequence);
}
});
Connection proxy = handler.getProxy();
expectedException.expect(SQLException.class);
proxy.clearWarnings();
}
use of org.firebirdsql.jdbc.FBSQLException in project jaybird by FirebirdSQL.
the class TestFBPooledConnectionMock method testFatalExceptionFiresConnectionErrorOccurred.
/**
* A fatal SQLException thrown during getConnection should fire a
* connectionErrorOccurred event.
*
* @throws SQLException
*/
@Test
public void testFatalExceptionFiresConnectionErrorOccurred() throws SQLException {
final Connection physical = context.mock(Connection.class);
final FBPooledConnection pooled = new FBPooledConnection(physical);
final ConnectionEventListener cel = context.mock(ConnectionEventListener.class);
pooled.addConnectionEventListener(cel);
context.checking(new Expectations() {
{
oneOf(physical).setAutoCommit(true);
will(throwException(new FBSQLException("Mock Exception", SQLStateConstants.SQL_STATE_CONNECTION_FAILURE)));
oneOf(cel).connectionErrorOccurred(with(new ConnectionEventMatcher(pooled, aNonNull(SQLException.class))));
}
});
expectedException.expect(SQLException.class);
expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_CONNECTION_FAILURE));
pooled.getConnection();
}
use of org.firebirdsql.jdbc.FBSQLException in project jaybird by FirebirdSQL.
the class TestStatementHandlerMock method testException_notify.
/**
* Calling a Statement method on an open proxy should notify the owner of
* the occurrence of an exception.
*
* @throws SQLException
*/
@Test
public void testException_notify() throws SQLException {
final PooledConnectionHandler conHandler = context.mock(PooledConnectionHandler.class);
final Statement statement = context.mock(Statement.class);
final StatementHandler handler = new StatementHandler(conHandler, statement);
final Sequence exceptionSequence = context.sequence("exceptionSequence");
context.checking(new Expectations() {
{
SQLException ex = new FBSQLException("Mock Exception");
oneOf(statement).getFetchSize();
will(throwException(ex));
inSequence(exceptionSequence);
oneOf(conHandler).statementErrorOccurred(handler, ex);
inSequence(exceptionSequence);
}
});
Statement proxy = handler.getProxy();
expectedException.expect(SQLException.class);
proxy.getFetchSize();
}
Aggregations