Search in sources :

Example 16 with XdrOutputStream

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

the class V10AsynchronousChannel method queueEvent.

@Override
public void queueEvent(EventHandle eventHandle) throws SQLException {
    if (!(eventHandle instanceof WireEventHandle))
        throw new SQLNonTransientException("Invalid event handle type: " + eventHandle.getClass().getName());
    final WireEventHandle wireEventHandle = (WireEventHandle) eventHandle;
    wireEventHandle.assignNewLocalId();
    addChannelListener(wireEventHandle);
    synchronized (database.getSynchronizationObject()) {
        try {
            if (log.isDebugEnabled()) {
                log.debug("Queue event: " + wireEventHandle);
            }
            final XdrOutputStream dbXdrOut = database.getXdrStreamAccess().getXdrOut();
            dbXdrOut.writeInt(op_que_events);
            dbXdrOut.writeInt(auxHandle);
            dbXdrOut.writeBuffer(wireEventHandle.toByteArray());
            // AST info
            dbXdrOut.writeLong(0);
            dbXdrOut.writeInt(wireEventHandle.getLocalId());
            dbXdrOut.flush();
        } catch (IOException e) {
            throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
        }
        try {
            final GenericResponse response = database.readGenericResponse(null);
            wireEventHandle.setEventId(response.getObjectHandle());
        } catch (IOException e) {
            throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
        }
    }
}
Also used : SQLNonTransientException(java.sql.SQLNonTransientException) FbExceptionBuilder(org.firebirdsql.gds.ng.FbExceptionBuilder) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) IOException(java.io.IOException)

Example 17 with XdrOutputStream

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

the class V10Database method startTransaction.

@Override
public final FbWireTransaction startTransaction(TransactionParameterBuffer tpb) throws SQLException {
    try {
        checkAttached();
        synchronized (getSynchronizationObject()) {
            try {
                final XdrOutputStream xdrOut = getXdrOut();
                xdrOut.writeInt(op_transaction);
                xdrOut.writeInt(getHandle());
                xdrOut.writeTyped(tpb);
                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.ACTIVE);
                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 18 with XdrOutputStream

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

the class V10Database method dropDatabase.

@Override
public final void dropDatabase() throws SQLException {
    try {
        checkAttached();
        synchronized (getSynchronizationObject()) {
            try {
                try {
                    final XdrOutputStream xdrOut = getXdrOut();
                    xdrOut.writeInt(op_drop_database);
                    xdrOut.writeInt(getHandle());
                    xdrOut.flush();
                } catch (IOException ioex) {
                    throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioex).toSQLException();
                }
                try {
                    readResponse(null);
                } catch (IOException ioex) {
                    throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ioex).toSQLException();
                }
            } finally {
                try {
                    closeConnection();
                } catch (IOException e) {
                    log.debug("Ignored exception on connection close in dropDatabase()", e);
                }
            }
        }
    } 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 19 with XdrOutputStream

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

the class V10Database method sendAttachOrCreateToBuffer.

/**
 * Sends the buffer for op_attach or op_create
 *
 * @param dpb
 *         Database parameter buffer
 * @param create
 *         <code>true</code> create database, <code>false</code> only
 *         attach
 * @throws SQLException
 *         If the connection is not open
 * @throws IOException
 *         For errors writing to the connection
 */
protected final void sendAttachOrCreateToBuffer(DatabaseParameterBuffer dpb, boolean create) throws SQLException, IOException {
    final int operation = create ? op_create : op_attach;
    final XdrOutputStream xdrOut = getXdrOut();
    final Encoding filenameEncoding = getFilenameEncoding(dpb);
    xdrOut.writeInt(operation);
    // Database object ID
    xdrOut.writeInt(0);
    xdrOut.writeString(connection.getAttachObjectName(), filenameEncoding);
    dpb = ((DatabaseParameterBufferExtension) dpb).removeExtensionParams();
    xdrOut.writeTyped(dpb);
}
Also used : XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) Encoding(org.firebirdsql.encodings.Encoding)

Example 20 with XdrOutputStream

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

the class V10Database method getDatabaseInfo.

@Override
public final byte[] getDatabaseInfo(byte[] requestItems, int maxBufferLength) throws SQLException {
    // TODO Write common info request implementation shared for db, sql, transaction and blob?
    try {
        checkAttached();
        synchronized (getSynchronizationObject()) {
            try {
                final XdrOutputStream xdrOut = getXdrOut();
                xdrOut.writeInt(op_info_database);
                xdrOut.writeInt(getHandle());
                // incarnation
                xdrOut.writeInt(0);
                xdrOut.writeBuffer(requestItems);
                xdrOut.writeInt(maxBufferLength);
                xdrOut.flush();
            } catch (IOException ex) {
                throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
            }
            try {
                final GenericResponse genericResponse = readGenericResponse(null);
                return genericResponse.getData();
            } 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)

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