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();
}
}
}
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;
}
}
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;
}
}
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);
}
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;
}
}
Aggregations