use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.
the class TestV10OutputBlob method testBlobStorage.
/**
* Tests storage of a blob (what goes in is what comes out).
*/
@Test
public void testBlobStorage() throws Exception {
final int testId = 1;
final byte[] baseContent = generateBaseContent();
// Use sufficiently large value so that multiple segments are used
final int requiredSize = 4 * Short.MAX_VALUE;
final byte[] testBytes = generateBlobContent(baseContent, requiredSize);
try (FbWireDatabase db = createDatabaseConnection()) {
writeBlob(testId, testBytes, db, null);
}
assertTrue("Unexpected blob content", validateBlob(testId, baseContent, requiredSize));
}
use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.
the class TestV10OutputBlob method testIsEof_afterCancel.
/**
* Test if blob is eof after cancel.
*/
@Test
public void testIsEof_afterCancel() throws Exception {
try (FbWireDatabase db = createDatabaseConnection()) {
final FbTransaction transaction = getTransaction(db);
try {
FbBlob blob = db.createBlobForOutput(transaction, null);
assumeTrue("Output blob before open should be eof", blob.isEof());
blob.open();
blob.cancel();
assertTrue("Output blob after cancel should be eof", blob.isEof());
} finally {
transaction.commit();
}
}
}
use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.
the class V11Statement method prepare.
@Override
public void prepare(final String statementText) throws SQLException {
try {
synchronized (getSynchronizationObject()) {
checkTransactionActive(getTransaction());
final StatementState currentState = getState();
if (!isPrepareAllowed(currentState)) {
throw new SQLNonTransientException(String.format("Current statement state (%s) does not allow call to prepare", currentState));
}
resetAll();
int expectedResponseCount = 0;
try {
if (currentState == StatementState.NEW) {
sendAllocate();
expectedResponseCount++;
} else {
checkStatementValid();
}
sendPrepare(statementText);
expectedResponseCount++;
getXdrOut().flush();
} catch (IOException ex) {
switchState(StatementState.ERROR);
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
final FbWireDatabase db = getDatabase();
try {
if (currentState == StatementState.NEW) {
expectedResponseCount--;
processAllocateResponse(db.readGenericResponse(getStatementWarningCallback()));
}
expectedResponseCount--;
processPrepareResponse(db.readGenericResponse(getStatementWarningCallback()));
} finally {
db.consumePackets(expectedResponseCount, getStatementWarningCallback());
}
} catch (IOException ex) {
switchState(StatementState.ERROR);
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
}
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.
the class TestV10Database method checkCancelOperationNotSupported.
private void checkCancelOperationNotSupported(int kind) throws Exception {
FBManager fbManager = createFBManager();
defaultDatabaseSetUp(fbManager);
try (WireDatabaseConnection gdsConnection = createConnection()) {
gdsConnection.socketConnect();
try (FbWireDatabase db = gdsConnection.identify()) {
assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
db.attach();
assertTrue("expected database attached", db.isAttached());
expectedException.expect(allOf(isA(SQLFeatureNotSupportedException.class), message(startsWith("Cancel Operation isn't supported in this version of the wire protocol"))));
db.cancelOperation(kind);
}
} finally {
defaultDatabaseTearDown(fbManager);
}
}
use of org.firebirdsql.gds.ng.wire.FbWireDatabase in project jaybird by FirebirdSQL.
the class TestV10Database method testBasicCreateAndDrop.
/**
* Tests creating and subsequently dropping a database
*/
@Test
public void testBasicCreateAndDrop() throws Exception {
IConnectionProperties connectionProperties = getConnectionInfo();
connectionProperties.getExtraDatabaseParameters().addArgument(ISCConstants.isc_dpb_sql_dialect, 3);
File dbFile = new File(connectionProperties.getAttachObjectName());
try (WireDatabaseConnection gdsConnection = new WireDatabaseConnection(connectionProperties, EncodingFactory.getPlatformDefault(), getProtocolCollection())) {
gdsConnection.socketConnect();
FbWireDatabase db = gdsConnection.identify();
assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
db.createDatabase();
assertTrue("Database should be attached after create", db.isAttached());
assertTrue("Connection should be connected after create", gdsConnection.isConnected());
assertTrue("Expected database file to exist (NOTE: only works on localhost)", dbFile.exists() || !FBTestProperties.DB_SERVER_URL.equalsIgnoreCase("localhost"));
db.dropDatabase();
assertFalse(gdsConnection.isConnected());
assertFalse(dbFile.exists());
} finally {
if (dbFile.exists()) {
dbFile.delete();
}
}
}
Aggregations