use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class FBMaintenanceManager method limboTransactionsAsList.
// ----------- Transaction Management ----------------------------
public List<Long> limboTransactionsAsList() throws SQLException {
// See also fbscvmgr.cpp method printInfo
final OutputStream saveOut = getLogger();
final List<Long> result = new ArrayList<>();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final byte[] output;
try {
setLogger(out);
executeRepairOperation(isc_spb_rpr_list_limbo_trans);
output = out.toByteArray();
} finally {
setLogger(saveOut);
}
int idx = 0;
while (idx < output.length) {
switch(output[idx++]) {
case isc_spb_single_tra_id:
case isc_spb_multi_tra_id:
{
long trId = iscVaxLong(output, idx, 4);
idx += 4;
result.add(trId);
break;
}
case isc_spb_single_tra_id_64:
case isc_spb_multi_tra_id_64:
{
long trId = iscVaxLong(output, idx, 8);
idx += 8;
result.add(trId);
break;
}
// Information items we will ignore for now
case isc_spb_tra_id:
idx += 4;
break;
case isc_spb_tra_id_64:
idx += 8;
break;
case isc_spb_tra_state:
case isc_spb_tra_advise:
idx++;
break;
case isc_spb_tra_host_site:
case isc_spb_tra_remote_site:
case isc_spb_tra_db_path:
int length = iscVaxInteger2(output, idx);
idx += 2;
idx += length;
break;
default:
throw new FbExceptionBuilder().exception(isc_fbsvcmgr_info_err).messageParameter(output[idx - 1] & 0xFF).toSQLException();
}
}
return result;
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class V10Database method reconnectTransaction.
@Override
public final FbTransaction reconnectTransaction(long transactionId) throws SQLException {
try {
checkAttached();
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_reconnect);
xdrOut.writeInt(getHandle());
final byte[] transactionIdBuffer = getTransactionIdBuffer(transactionId);
xdrOut.writeBuffer(transactionIdBuffer);
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.PREPARED);
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.ng.FbExceptionBuilder 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.ng.FbExceptionBuilder 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.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class V10Database method initAsynchronousChannel.
@Override
public final FbWireAsynchronousChannel initAsynchronousChannel() throws SQLException {
checkAttached();
final int auxHandle;
final int port;
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_connect_request);
// Connection type (p_req_type)
xdrOut.writeInt(P_REQ_async);
// p_req_object
xdrOut.writeInt(getHandle());
// p_req_partner
xdrOut.writeInt(0);
xdrOut.flush();
} catch (IOException ex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
final GenericResponse response = readGenericResponse(null);
auxHandle = response.getObjectHandle();
final byte[] data = response.getData();
// bytes 0 - 1: sin family (ignore)
// bytes 2 - 3: sin port (port to connect to)
port = ((data[2] & 0xFF) << 8) + (data[3] & 0xFF);
// remaining bytes: IP address + other info(?) (ignore, can't be trusted, and invalid in FB3 and higher; always use original hostname)
} catch (IOException ex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ex).toSQLException();
}
}
final FbWireAsynchronousChannel channel = protocolDescriptor.createAsynchronousChannel(this);
channel.connect(connection.getServerName(), port, auxHandle);
return channel;
}
Aggregations