Search in sources :

Example 6 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class FBMaintenanceManager method limboTransactionsAsList.

// ----------- Transaction Management ----------------------------
public List<Long> limboTransactionsAsList() throws SQLException {
    // See also fbscvmgr.cpp method printInfo
    final OutputStream saveOut = getLogger();
    final List<Long> result = new ArrayList<>();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final byte[] output;
    try {
        setLogger(out);
        executeRepairOperation(isc_spb_rpr_list_limbo_trans);
        output = out.toByteArray();
    } finally {
        setLogger(saveOut);
    }
    int idx = 0;
    while (idx < output.length) {
        switch(output[idx++]) {
            case isc_spb_single_tra_id:
            case isc_spb_multi_tra_id:
                {
                    long trId = iscVaxLong(output, idx, 4);
                    idx += 4;
                    result.add(trId);
                    break;
                }
            case isc_spb_single_tra_id_64:
            case isc_spb_multi_tra_id_64:
                {
                    long trId = iscVaxLong(output, idx, 8);
                    idx += 8;
                    result.add(trId);
                    break;
                }
            // Information items we will ignore for now
            case isc_spb_tra_id:
                idx += 4;
                break;
            case isc_spb_tra_id_64:
                idx += 8;
                break;
            case isc_spb_tra_state:
            case isc_spb_tra_advise:
                idx++;
                break;
            case isc_spb_tra_host_site:
            case isc_spb_tra_remote_site:
            case isc_spb_tra_db_path:
                int length = iscVaxInteger2(output, idx);
                idx += 2;
                idx += length;
                break;
            default:
                throw new FbExceptionBuilder().exception(isc_fbsvcmgr_info_err).messageParameter(output[idx - 1] & 0xFF).toSQLException();
        }
    }
    return result;
}
Also used : FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VaxEncoding.iscVaxLong(org.firebirdsql.gds.VaxEncoding.iscVaxLong) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class V10Database method reconnectTransaction.

@Override
public final FbTransaction reconnectTransaction(long transactionId) throws SQLException {
    try {
        checkAttached();
        synchronized (getSynchronizationObject()) {
            try {
                final XdrOutputStream xdrOut = getXdrOut();
                xdrOut.writeInt(op_reconnect);
                xdrOut.writeInt(getHandle());
                final byte[] transactionIdBuffer = getTransactionIdBuffer(transactionId);
                xdrOut.writeBuffer(transactionIdBuffer);
                xdrOut.flush();
            } catch (IOException ioex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioex).toSQLException();
            }
            try {
                final GenericResponse response = readGenericResponse(null);
                final FbWireTransaction transaction = protocolDescriptor.createTransaction(this, response.getObjectHandle(), TransactionState.PREPARED);
                transactionAdded(transaction);
                return transaction;
            } catch (IOException ioex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ioex).toSQLException();
            }
        }
    } catch (SQLException ex) {
        exceptionListenerDispatcher.errorOccurred(ex);
        throw ex;
    }
}
Also used : SQLException(java.sql.SQLException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Example 8 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder 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 9 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder 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 10 with FbExceptionBuilder

use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.

the class V10Database method initAsynchronousChannel.

@Override
public final FbWireAsynchronousChannel initAsynchronousChannel() throws SQLException {
    checkAttached();
    final int auxHandle;
    final int port;
    synchronized (getSynchronizationObject()) {
        try {
            final XdrOutputStream xdrOut = getXdrOut();
            xdrOut.writeInt(op_connect_request);
            // Connection type (p_req_type)
            xdrOut.writeInt(P_REQ_async);
            // p_req_object
            xdrOut.writeInt(getHandle());
            // p_req_partner
            xdrOut.writeInt(0);
            xdrOut.flush();
        } catch (IOException ex) {
            throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
        }
        try {
            final GenericResponse response = readGenericResponse(null);
            auxHandle = response.getObjectHandle();
            final byte[] data = response.getData();
            // bytes 0 - 1: sin family (ignore)
            // bytes 2 - 3: sin port (port to connect to)
            port = ((data[2] & 0xFF) << 8) + (data[3] & 0xFF);
        // remaining bytes: IP address + other info(?) (ignore, can't be trusted, and invalid in FB3 and higher; always use original hostname)
        } catch (IOException ex) {
            throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
        }
    }
    final FbWireAsynchronousChannel channel = protocolDescriptor.createAsynchronousChannel(this);
    channel.connect(connection.getServerName(), port, auxHandle);
    return channel;
}
Also used : FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Aggregations

FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)51 SQLException (java.sql.SQLException)31 IOException (java.io.IOException)27 XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)22 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)6 GenericResponse (org.firebirdsql.gds.ng.wire.GenericResponse)6 SQLNonTransientException (java.sql.SQLNonTransientException)4 AbstractWireOperations (org.firebirdsql.gds.ng.wire.AbstractWireOperations)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)3 BigInteger (java.math.BigInteger)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)2 SQLWarning (java.sql.SQLWarning)2 Cipher (javax.crypto.Cipher)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 Encoding (org.firebirdsql.encodings.Encoding)2