use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class JnaService method attach.
@Override
public void attach() throws SQLException {
try {
if (isAttached()) {
throw new SQLException("Already attached to a service");
}
final ServiceParameterBuffer spb = PARAMETER_CONVERTER.toServiceParameterBuffer(connection);
final byte[] serviceName = getEncoding().encodeToCharset(connection.getAttachUrl());
final byte[] spbArray = spb.toBytesWithType();
synchronized (getSynchronizationObject()) {
try {
clientLibrary.isc_service_attach(statusVector, (short) serviceName.length, serviceName, handle, (short) spbArray.length, spbArray);
processStatusVector();
} catch (SQLException ex) {
safelyDetach();
throw ex;
} catch (Exception ex) {
safelyDetach();
// TODO Replace with specific error (eg native client error)
throw new FbExceptionBuilder().exception(ISCConstants.isc_network_error).messageParameter(connection.getAttachUrl()).cause(ex).toSQLException();
}
setAttached();
afterAttachActions();
}
} catch (SQLException e) {
exceptionListenerDispatcher.errorOccurred(e);
throw e;
}
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class ChaChaEncryptionPlugin method createCipher.
private Cipher createCipher(int mode, ChaChaIV iv, byte[] key) throws SQLException {
try {
Cipher chaChaCipher = Cipher.getInstance(CHA_CHA_20_CIPHER_NAME);
SecretKeySpec chaChaKey = new SecretKeySpec(key, CHA_CHA_20_CIPHER_NAME);
chaChaCipher.init(mode, chaChaKey, iv.toParameterSpec());
return chaChaCipher;
} catch (NoSuchPaddingException | NoSuchAlgorithmException e) {
throw new FbExceptionBuilder().nonTransientException(jb_cryptAlgorithmNotAvailable).messageParameter(getEncryptionIdentifier().toString()).cause(e).toFlatSQLException();
} catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
throw new FbExceptionBuilder().nonTransientException(jb_cryptInvalidKey).messageParameter(getEncryptionIdentifier().toString()).cause(e).toFlatSQLException();
}
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class AbstractFbWireBlob method getBlobInfo.
// NOTE If we need to override some of the blob operations below in the future, consider introducing a separate
// object that is injected by the ProtocolDescriptor so that we don't need to override separately for input and output.
@Override
public byte[] getBlobInfo(final byte[] requestItems, final int bufferLength) throws SQLException {
try {
synchronized (getSynchronizationObject()) {
try {
final XdrOutputStream xdrOut = getDatabase().getXdrStreamAccess().getXdrOut();
xdrOut.writeInt(WireProtocolConstants.op_info_blob);
xdrOut.writeInt(getHandle());
// incarnation
xdrOut.writeInt(0);
xdrOut.writeBuffer(requestItems);
xdrOut.writeInt(bufferLength);
xdrOut.flush();
} catch (IOException ex) {
throw new FbExceptionBuilder().exception(ISCConstants.isc_net_write_err).cause(ex).toSQLException();
}
try {
// TODO: Blob warning callback or just database default?
GenericResponse response = getDatabase().readGenericResponse(null);
return response.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 V15WireOperations method readCryptKeyCallback.
@Override
protected DbCryptData readCryptKeyCallback() throws IOException, SQLException {
final XdrInputStream xdrIn = getXdrIn();
// p_cc_data
final byte[] pluginData = xdrIn.readBuffer();
// p_cc_reply
final int replySize = xdrIn.readInt();
try {
return new DbCryptData(pluginData, replySize);
} catch (RuntimeException e) {
throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_dbCryptDataError).cause(e).toSQLException();
}
}
use of org.firebirdsql.gds.ng.FbExceptionBuilder in project jaybird by FirebirdSQL.
the class DbAttachInfo method parseLegacyConnectString.
private static DbAttachInfo parseLegacyConnectString(String connectString) throws SQLException {
// NOTE: This method does not support IPv6 addresses enclosed in []
String server = null;
String fileName;
Integer port = null;
int sep = connectString.indexOf(':');
if (sep == 0) {
throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_invalidConnectionString).messageParameter(connectString).messageParameter("Path separator ':' at beginning").toFlatSQLException();
} else if (sep == 1 && !isLikelyWindowsAbsolutePath(connectString) || sep > 1) {
server = connectString.substring(0, sep);
fileName = connectString.substring(sep + 1);
int portSep = server.indexOf('/');
if (portSep == 0 || portSep == server.length() - 1) {
throw new FbExceptionBuilder().nonTransientConnectionException(JaybirdErrorCodes.jb_invalidConnectionString).messageParameter(connectString).messageParameter("Port separator '/' at beginning or end").toFlatSQLException();
} else if (portSep > 0) {
String portString = server.substring(portSep + 1);
port = parsePortNumber(connectString, portString);
server = server.substring(0, portSep);
}
} else {
fileName = connectString;
}
return new DbAttachInfo(server, port, fileName);
}
Aggregations