use of org.firebirdsql.gds.ng.FbExceptionBuilder 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.ng.FbExceptionBuilder 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.ng.FbExceptionBuilder 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.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class V10Service method internalDetach.
@Override
protected void internalDetach() throws SQLException {
synchronized (getSynchronizationObject()) {
try {
try {
final XdrOutputStream xdrOut = getXdrOut();
if (isAttached()) {
xdrOut.writeInt(op_service_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.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class V10Service method getServiceInfo.
@Override
public byte[] getServiceInfo(ServiceParameterBuffer serviceParameterBuffer, ServiceRequestBuffer serviceRequestBuffer, int maxBufferLength) throws SQLException {
try {
checkAttached();
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_service_info);
xdrOut.writeInt(getHandle());
// incarnation
xdrOut.writeInt(0);
xdrOut.writeBuffer(serviceParameterBuffer != null ? serviceParameterBuffer.toBytes() : null);
xdrOut.writeBuffer(serviceRequestBuffer.toBytes());
xdrOut.writeInt(maxBufferLength);
xdrOut.flush();
} catch (IOException ex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
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