use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class V10Service method startServiceAction.
@Override
public void startServiceAction(ServiceRequestBuffer serviceRequestBuffer) throws SQLException {
try {
checkAttached();
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_service_start);
xdrOut.writeInt(getHandle());
// incarnation
xdrOut.writeInt(0);
xdrOut.writeBuffer(serviceRequestBuffer.toBytes());
xdrOut.flush();
} catch (IOException ex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
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 startTransaction.
@Override
public final FbWireTransaction startTransaction(TransactionParameterBuffer tpb) throws SQLException {
try {
checkAttached();
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_transaction);
xdrOut.writeInt(getHandle());
xdrOut.writeTyped(tpb);
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.ACTIVE);
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 getDatabaseInfo.
@Override
public final byte[] getDatabaseInfo(byte[] requestItems, int maxBufferLength) throws SQLException {
// TODO Write common info request implementation shared for db, sql, transaction and blob?
try {
checkAttached();
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_info_database);
xdrOut.writeInt(getHandle());
// incarnation
xdrOut.writeInt(0);
xdrOut.writeBuffer(requestItems);
xdrOut.writeInt(maxBufferLength);
xdrOut.flush();
} catch (IOException ex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
final 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;
}
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class V10Database method dropDatabase.
@Override
public final void dropDatabase() throws SQLException {
try {
checkAttached();
synchronized (getSynchronizationObject()) {
try {
try {
final XdrOutputStream xdrOut = getXdrOut();
xdrOut.writeInt(op_drop_database);
xdrOut.writeInt(getHandle());
xdrOut.flush();
} catch (IOException ioex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ioex).toSQLException();
}
try {
readResponse(null);
} catch (IOException ioex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_read_err).cause(ioex).toSQLException();
}
} finally {
try {
closeConnection();
} catch (IOException e) {
log.debug("Ignored exception on connection close in dropDatabase()", e);
}
}
}
} catch (SQLException ex) {
exceptionListenerDispatcher.errorOccurred(ex);
throw ex;
}
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class SrpClient method clientProof.
byte[] clientProof(String user, String password, byte[] authData) throws SQLException {
if (authData == null || authData.length == 0) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_auth_data).toFlatSQLException();
}
if (authData.length > EXPECTED_AUTH_DATA_LENGTH) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_auth_datalength).messageParameter(authData.length).messageParameter(EXPECTED_AUTH_DATA_LENGTH).messageParameter("data").toFlatSQLException();
}
final int saltLength = VaxEncoding.iscVaxInteger2(authData, 0);
if (saltLength > SRP_SALT_SIZE * 2) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_auth_datalength).messageParameter(saltLength).messageParameter(SRP_SALT_SIZE * 2).messageParameter("salt").toFlatSQLException();
}
final byte[] salt = Arrays.copyOfRange(authData, 2, saltLength + 2);
final int keyLength = VaxEncoding.iscVaxInteger2(authData, saltLength + 2);
final int serverKeyStart = saltLength + 4;
if (authData.length - serverKeyStart != keyLength) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_auth_datalength).messageParameter(keyLength).messageParameter(authData.length - serverKeyStart).messageParameter("key").toFlatSQLException();
}
final String hexServerPublicKey = new String(authData, serverKeyStart, authData.length - serverKeyStart, StandardCharsets.US_ASCII);
final BigInteger serverPublicKey = new BigInteger(padHexBinary(hexServerPublicKey), 16);
return clientProof(user, password, salt, serverPublicKey);
}
Aggregations