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