use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V10Statement method sendExecute.
/**
* Sends the execute (for <code>op_execute</code> or <code>op_execute2</code>) to the database.
*
* @param operation
* Operation (<code>op_execute</code> or <code>op_execute2</code>)
* @param parameters
* Parameters
* @throws IOException
* @throws SQLException
*/
protected void sendExecute(final int operation, final RowValue parameters) throws IOException, SQLException {
assert operation == WireProtocolConstants.op_execute || operation == WireProtocolConstants.op_execute2 : "Needs to be called with operation op_execute or op_execute2";
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(operation);
xdrOut.writeInt(getHandle());
xdrOut.writeInt(getTransaction().getHandle());
if (parameters != null && parameters.getCount() > 0) {
final RowDescriptor parameterDescriptor = getParameterDescriptor();
xdrOut.writeBuffer(calculateBlr(parameterDescriptor, parameters));
// message number = in_message_type
xdrOut.writeInt(0);
// Number of messages
xdrOut.writeInt(1);
writeSqlData(parameterDescriptor, parameters);
} else {
xdrOut.writeBuffer(null);
// message number = in_message_type
xdrOut.writeInt(0);
// Number of messages
xdrOut.writeInt(0);
}
if (operation == WireProtocolConstants.op_execute2) {
final RowDescriptor fieldDescriptor = getFieldDescriptor();
xdrOut.writeBuffer(fieldDescriptor != null && fieldDescriptor.getCount() > 0 ? calculateBlr(fieldDescriptor) : null);
// out_message_number = out_message_type
xdrOut.writeInt(0);
}
}
use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V10Statement method setCursorName.
public void setCursorName(String cursorName) throws SQLException {
try {
synchronized (getSynchronizationObject()) {
checkStatementValid();
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(WireProtocolConstants.op_set_cursor);
xdrOut.writeInt(getHandle());
// Null termination is needed due to a quirk of the protocol
xdrOut.writeString(cursorName + '\0', getDatabase().getEncoding());
// Cursor type
xdrOut.writeInt(0);
xdrOut.flush();
} catch (IOException ex) {
switchState(StatementState.ERROR);
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
// TODO Do we need to do anything else with this response?
getDatabase().readGenericResponse(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;
}
}
use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V10Transaction method getTransactionInfo.
@Override
public byte[] getTransactionInfo(byte[] requestItems, int maxBufferLength) throws SQLException {
try {
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_info_transaction);
xdrOut.writeInt(getHandle());
// incarnation(?)
xdrOut.writeInt(0);
xdrOut.writeBuffer(requestItems);
xdrOut.writeInt(maxBufferLength);
xdrOut.flush();
} catch (IOException ioex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioex).toSQLException();
}
try {
final GenericResponse genericResponse = getDatabase().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;
}
}
use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V10Transaction method prepare.
@Override
public void prepare(byte[] recoveryInformation) throws SQLException {
try {
synchronized (getSynchronizationObject()) {
switchState(TransactionState.PREPARING);
try {
final XdrOutputStream xdrOut = getXdrOut();
if (recoveryInformation != null) {
xdrOut.writeInt(op_prepare2);
xdrOut.writeInt(handle);
xdrOut.writeBuffer(recoveryInformation);
} else {
xdrOut.writeInt(op_prepare);
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();
}
switchState(TransactionState.PREPARED);
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
} finally {
if (getState() != TransactionState.PREPARED) {
log.warn("Prepare not completed", new RuntimeException("Prepare not completed"));
}
}
}
use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class TestV10EventHandling method checkAsynchronousDisconnection.
private void checkAsynchronousDisconnection(int disconnectOperation) throws Exception {
try (SimpleServer simpleServer = new SimpleServer()) {
final FbWireAsynchronousChannel channel = new V10AsynchronousChannel(createDummyDatabase());
Thread establishChannel = new Thread(new Runnable() {
@Override
public void run() {
try {
channel.connect("localhost", simpleServer.getPort(), 1);
} catch (SQLException e) {
// suppress
}
}
});
establishChannel.start();
simpleServer.acceptConnection();
AsynchronousProcessor.getInstance().registerAsynchronousChannel(channel);
establishChannel.join(500);
assertTrue("Expected connected channel", channel.isConnected());
final XdrOutputStream out = new XdrOutputStream(simpleServer.getOutputStream());
out.writeInt(disconnectOperation);
out.flush();
Thread.sleep(500);
assertFalse("Expected disconnected channel", channel.isConnected());
}
}
Aggregations