use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V10InputBlob method seek.
@Override
public void seek(int offset, SeekMode seekMode) throws SQLException {
try {
synchronized (getSynchronizationObject()) {
checkDatabaseAttached();
checkTransactionActive();
final FbWireDatabase database = getDatabase();
try {
final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
xdrOut.writeInt(op_seek_blob);
xdrOut.writeInt(getHandle());
xdrOut.writeInt(seekMode.getSeekModeId());
xdrOut.writeInt(offset);
xdrOut.flush();
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
}
try {
database.readResponse(null);
// object handle in response is the current position in the blob (see .NET provider source)
} 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 V10InputBlob method getSegment.
@Override
public byte[] getSegment(final int sizeRequested) throws SQLException {
try {
if (sizeRequested <= 0) {
throw new FbExceptionBuilder().exception(jb_blobGetSegmentNegative).messageParameter(sizeRequested).toSQLException();
}
// TODO Is this actually a real limitation, or are larger sizes possible?
int actualSize = 2 + Math.min(sizeRequested, getMaximumSegmentSize());
synchronized (getSynchronizationObject()) {
checkDatabaseAttached();
checkTransactionActive();
checkBlobOpen();
final GenericResponse response;
final FbWireDatabase database = getDatabase();
try {
final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
xdrOut.writeInt(op_get_segment);
xdrOut.writeInt(getHandle());
xdrOut.writeInt(actualSize);
// length of segment send buffer (always 0 in get)
xdrOut.writeInt(0);
xdrOut.flush();
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
}
try {
response = database.readGenericResponse(null);
// TODO Meaning of 2
if (response.getObjectHandle() == 2) {
// TODO what if I seek on a stream blob?
setEof();
}
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
}
final byte[] responseBuffer = response.getData();
if (responseBuffer.length == 0) {
return responseBuffer;
}
final ByteArrayOutputStream bos = new ByteArrayOutputStream(actualSize);
int position = 0;
while (position < responseBuffer.length) {
final int segmentLength = iscVaxInteger2(responseBuffer, position);
position += 2;
bos.write(responseBuffer, position, segmentLength);
position += segmentLength;
}
return bos.toByteArray();
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V10InputBlob method open.
// TODO Need blob specific warning callback?
@Override
public void open() throws SQLException {
try {
synchronized (getSynchronizationObject()) {
checkDatabaseAttached();
checkTransactionActive();
checkBlobClosed();
final FbWireDatabase database = getDatabase();
try {
final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
final BlobParameterBuffer blobParameterBuffer = getBlobParameterBuffer();
if (blobParameterBuffer == null) {
xdrOut.writeInt(op_open_blob);
} else {
xdrOut.writeInt(op_open_blob2);
xdrOut.writeTyped(blobParameterBuffer);
}
xdrOut.writeInt(getTransaction().getHandle());
xdrOut.writeLong(getBlobId());
xdrOut.flush();
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
}
try {
final GenericResponse genericResponse = database.readGenericResponse(null);
setHandle(genericResponse.getObjectHandle());
setOpen(true);
resetEof();
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
}
// TODO Request information on the blob?
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V10OutputBlob method open.
// TODO Need blob specific warning callback?
@Override
public void open() throws SQLException {
try {
synchronized (getSynchronizationObject()) {
checkDatabaseAttached();
checkTransactionActive();
checkBlobClosed();
if (getBlobId() != FbBlob.NO_BLOB_ID) {
throw new FbExceptionBuilder().nonTransientException(ISCConstants.isc_segstr_no_op).toSQLException();
}
final FbWireDatabase database = getDatabase();
try {
final XdrOutputStream xdrOut = database.getXdrStreamAccess().getXdrOut();
final BlobParameterBuffer blobParameterBuffer = getBlobParameterBuffer();
if (blobParameterBuffer == null) {
xdrOut.writeInt(op_create_blob);
} else {
xdrOut.writeInt(op_create_blob2);
xdrOut.writeTyped(blobParameterBuffer);
}
xdrOut.writeInt(getTransaction().getHandle());
xdrOut.writeLong(FbBlob.NO_BLOB_ID);
xdrOut.flush();
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(e).toSQLException();
}
try {
final GenericResponse genericResponse = database.readGenericResponse(null);
setHandle(genericResponse.getObjectHandle());
setBlobId(genericResponse.getBlobId());
setOpen(true);
} catch (IOException e) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(e).toSQLException();
}
// TODO Request information on the blob?
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.
the class V12Database method cancelOperation.
@Override
public void cancelOperation(int kind) throws SQLException {
try {
if (kind == ISCConstants.fb_cancel_abort) {
try {
// In case of abort we forcibly close the connection
closeConnection();
} catch (IOException ioe) {
throw new SQLNonTransientConnectionException("Connection abort failed", ioe);
}
} else {
checkConnected();
try {
// We circumvent the normal xdrOut to minimize the chance of interleaved writes
// TODO We may still need to do separate write / read synchronization to ensure this works correctly
final ByteArrayOutputStream out = new ByteArrayOutputStream(8);
final XdrOutputStream xdr = new XdrOutputStream(out, false);
xdr.writeInt(WireProtocolConstants.op_cancel);
xdr.writeInt(kind);
wireOperations.writeDirect(out.toByteArray());
} catch (IOException ioe) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioe).toSQLException();
}
}
} catch (SQLException ex) {
exceptionListenerDispatcher.errorOccurred(ex);
throw ex;
}
}
Aggregations