Search in sources :

Example 11 with FbWireDatabase

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));
}
Also used : FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 12 with FbWireDatabase

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();
        }
    }
}
Also used : FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) FbTransaction(org.firebirdsql.gds.ng.FbTransaction) FbBlob(org.firebirdsql.gds.ng.FbBlob) Test(org.junit.Test)

Example 13 with FbWireDatabase

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;
    }
}
Also used : StatementState(org.firebirdsql.gds.ng.StatementState) SQLNonTransientException(java.sql.SQLNonTransientException) SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) IOException(java.io.IOException) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase)

Example 14 with FbWireDatabase

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);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase)

Example 15 with FbWireDatabase

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();
        }
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) File(java.io.File) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Aggregations

FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)27 Test (org.junit.Test)23 WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)13 FbBlob (org.firebirdsql.gds.ng.FbBlob)11 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)11 FBManager (org.firebirdsql.management.FBManager)9 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 IOException (java.io.IOException)1 SQLNonTransientException (java.sql.SQLNonTransientException)1 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)1 DatatypeCoder (org.firebirdsql.gds.ng.DatatypeCoder)1 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)1 FbStatement (org.firebirdsql.gds.ng.FbStatement)1 StatementState (org.firebirdsql.gds.ng.StatementState)1 FieldValue (org.firebirdsql.gds.ng.fields.FieldValue)1 SimpleStatementListener (org.firebirdsql.gds.ng.wire.SimpleStatementListener)1 Ignore (org.junit.Ignore)1