Search in sources :

Example 6 with XdrOutputStream

use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.

the class V10Database method executeImmediate.

@Override
public final void executeImmediate(String statementText, FbTransaction transaction) throws SQLException {
    // TODO also implement op_exec_immediate2
    try {
        if (isAttached()) {
            if (transaction == null) {
                throw FbExceptionBuilder.forException(JaybirdErrorCodes.jb_executeImmediateRequiresTransactionAttached).toFlatSQLException();
            }
            checkTransactionActive(transaction);
        } else if (transaction != null) {
            throw FbExceptionBuilder.forException(JaybirdErrorCodes.jb_executeImmediateRequiresNoTransactionDetached).toFlatSQLException();
        }
        synchronized (getSynchronizationObject()) {
            try {
                final XdrOutputStream xdrOut = getXdrOut();
                xdrOut.writeInt(op_exec_immediate);
                xdrOut.writeInt(transaction != null ? transaction.getHandle() : 0);
                xdrOut.writeInt(getHandle());
                xdrOut.writeInt(getConnectionDialect());
                xdrOut.writeString(statementText, getEncoding());
                // information request items
                xdrOut.writeBuffer(null);
                xdrOut.writeInt(0);
                getXdrOut().flush();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
            try {
                if (!isAttached()) {
                    processAttachOrCreateResponse(readGenericResponse(null));
                }
                readGenericResponse(null);
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
            }
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Example 7 with XdrOutputStream

use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.

the class V10Database method internalDetach.

@Override
protected final void internalDetach() throws SQLException {
    // TODO Move to wire operations as it is almost identical to service detach?
    synchronized (getSynchronizationObject()) {
        try {
            try {
                final XdrOutputStream xdrOut = getXdrOut();
                if (isAttached()) {
                    xdrOut.writeInt(op_detach);
                    xdrOut.writeInt(getHandle());
                }
                xdrOut.writeInt(op_disconnect);
                xdrOut.flush();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
            if (isAttached()) {
                try {
                    // Consume op_detach response
                    wireOperations.readResponse(null);
                } catch (IOException ex) {
                    throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
                }
            }
            try {
                closeConnection();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
        } catch (SQLException ex) {
            try {
                closeConnection();
            } catch (Exception ex2) {
            // ignore
            }
            throw ex;
        } finally {
            setDetached();
        }
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) IOException(java.io.IOException) SQLException(java.sql.SQLException) SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException)

Example 8 with XdrOutputStream

use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.

the class V10OutputBlob method putSegment.

@Override
public void putSegment(byte[] segment) throws SQLException {
    try {
        if (segment.length == 0) {
            throw new FbExceptionBuilder().exception(jb_blobPutSegmentEmpty).toSQLException();
        }
        // TODO Handle by performing multiple puts?
        if (segment.length > getMaximumSegmentSize()) {
            throw new FbExceptionBuilder().exception(jb_blobPutSegmentTooLong).toSQLException();
        }
        synchronized (getSynchronizationObject()) {
            checkDatabaseAttached();
            checkTransactionActive();
            checkBlobOpen();
            final FbWireDatabase database = getDatabase();
            try {
                final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
                xdrOut.writeInt(op_put_segment);
                xdrOut.writeInt(getHandle());
                xdrOut.writeInt(segment.length);
                xdrOut.writeBuffer(segment);
                xdrOut.flush();
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
            }
            try {
                database.readResponse(null);
            } catch (IOException e) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
            }
        }
    } catch (SQLException e) {
        exceptionListenerDispatcher.errorOccurred(e);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Example 9 with XdrOutputStream

use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.

the class V10Statement method sendPrepare.

/**
 * Sends the statement prepare to the connection.
 *
 * @param statementText
 *         Statement
 * @throws SQLException
 * @throws IOException
 */
protected void sendPrepare(final String statementText) throws SQLException, IOException {
    final XdrOutputStream xdrOut = getXdrOut();
    xdrOut.writeInt(WireProtocolConstants.op_prepare_statement);
    xdrOut.writeInt(getTransaction().getHandle());
    xdrOut.writeInt(getHandle());
    xdrOut.writeInt(getDatabase().getConnectionDialect());
    xdrOut.writeString(statementText, getDatabase().getEncoding());
    xdrOut.writeBuffer(getStatementInfoRequestItems());
    xdrOut.writeInt(getDefaultSqlInfoSize());
}
Also used : XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream)

Example 10 with XdrOutputStream

use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.

the class V10Transaction method finishTransaction.

private void finishTransaction(final int commitOrRollback) throws SQLException {
    assert commitOrRollback == op_commit || commitOrRollback == op_rollback : "Unsupported operation code " + commitOrRollback;
    try {
        final XdrOutputStream xdrOut = getXdrOut();
        xdrOut.writeInt(commitOrRollback);
        xdrOut.writeInt(handle);
        xdrOut.flush();
    } catch (IOException ioex) {
        throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioex).toSQLException();
    }
    try {
        getDatabase().readResponse(null);
    } catch (IOException ioex) {
        throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ioex).toSQLException();
    }
}
Also used : XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Aggregations

XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)41 SQLException (java.sql.SQLException)25 IOException (java.io.IOException)24 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)22 SimpleServer (org.firebirdsql.common.SimpleServer)4 Encoding (org.firebirdsql.encodings.Encoding)3 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)2 SQLNonTransientException (java.sql.SQLNonTransientException)2 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)2 GenericResponse (org.firebirdsql.gds.ng.wire.GenericResponse)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 BitSet (java.util.BitSet)1 WireCrypt (org.firebirdsql.gds.ng.WireCrypt)1 ClientAuthBlock (org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock)1 EncryptionIdentifier (org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier)1