use of org.firebirdsql.util.SQLExceptionChainBuilder in project jaybird by FirebirdSQL.
the class FBManagedConnection method disassociateConnections.
/**
* Disassociate connections from current managed connection.
*/
private void disassociateConnections() throws ResourceException {
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
// Iterate over copy of list as connection.close() will remove connection
List<FBConnection> connectionHandleCopy = new ArrayList<>(connectionHandles);
for (FBConnection connection : connectionHandleCopy) {
try {
connection.close();
} catch (SQLException sqlex) {
chain.append(sqlex);
}
}
if (chain.hasException())
throw new FBResourceException(chain.getException());
}
use of org.firebirdsql.util.SQLExceptionChainBuilder in project jaybird by FirebirdSQL.
the class ChaChaEncryptionPlugin method initializeEncryption.
@Override
public EncryptionInitInfo initializeEncryption() {
SQLExceptionChainBuilder<SQLException> chainBuilder = new SQLExceptionChainBuilder<>();
Cipher encryptionCipher = null;
Cipher decryptionCipher = null;
try (ChaChaIV iv = new ChaChaIV()) {
encryptionCipher = createEncryptionCipher(iv, chainBuilder);
decryptionCipher = createDecryptionCipher(iv, chainBuilder);
} catch (SQLException e) {
chainBuilder.append(e);
}
if (chainBuilder.hasException()) {
return EncryptionInitInfo.failure(getEncryptionIdentifier(), chainBuilder.getException());
}
return EncryptionInitInfo.success(getEncryptionIdentifier(), encryptionCipher, decryptionCipher);
}
use of org.firebirdsql.util.SQLExceptionChainBuilder in project jaybird by FirebirdSQL.
the class FBResultSet method closeFields.
/**
* Close the fields if they were open (applies mainly to the stream fields).
*
* @throws SQLException
* if something wrong happened.
*/
protected void closeFields() throws SQLException {
// TODO See if we can apply completion reason logic (eg no need to close blob on commit)
wasNullValid = false;
// if there are no fields to close, then nothing to do
if (closeableFields.isEmpty())
return;
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
// close current fields, so that resources are freed.
for (final FBCloseableField field : closeableFields) {
try {
field.close();
} catch (SQLException ex) {
chain.append(ex);
}
}
if (chain.hasException()) {
throw chain.getException();
}
}
use of org.firebirdsql.util.SQLExceptionChainBuilder in project jaybird by FirebirdSQL.
the class V13WireOperations method tryKnownServerKeys.
private void tryKnownServerKeys() throws IOException, SQLException {
boolean initializedEncryption = false;
SQLExceptionChainBuilder<SQLException> chainBuilder = new SQLExceptionChainBuilder<>();
for (KnownServerKey.PluginSpecificData pluginSpecificData : getPluginSpecificData()) {
EncryptionIdentifier encryptionIdentifier = pluginSpecificData.getEncryptionIdentifier();
EncryptionPluginSpi currentEncryptionSpi = SUPPORTED_ENCRYPTION_PLUGINS.get(encryptionIdentifier);
if (currentEncryptionSpi == null) {
continue;
}
try (CryptSessionConfig cryptSessionConfig = getCryptSessionConfig(encryptionIdentifier, pluginSpecificData.getSpecificData())) {
EncryptionPlugin encryptionPlugin = currentEncryptionSpi.createEncryptionPlugin(cryptSessionConfig);
EncryptionInitInfo encryptionInitInfo = encryptionPlugin.initializeEncryption();
if (encryptionInitInfo.isSuccess()) {
enableEncryption(encryptionInitInfo);
clearServerKeys();
initializedEncryption = true;
log.debug("Wire encryption established with " + encryptionIdentifier);
break;
} else {
chainBuilder.append(encryptionInitInfo.getException());
}
} catch (SQLException e) {
chainBuilder.append(e);
}
}
if (!initializedEncryption && getAttachProperties().getWireCryptAsEnum() == WireCrypt.REQUIRED) {
FbExceptionBuilder exceptionBuilder = new FbExceptionBuilder().nonTransientException(ISCConstants.isc_wirecrypt_incompatible);
if (chainBuilder.hasException()) {
exceptionBuilder.cause(chainBuilder.getException());
}
throw exceptionBuilder.toFlatSQLException();
}
if (chainBuilder.hasException()) {
SQLException current = chainBuilder.getException();
if (log.isWarnEnabled()) {
log.warn(initializedEncryption ? "Wire encryption established, but some plugins failed; see other loglines for details" : "No wire encryption established because of errors");
log.warn("Encryption plugin failed; see debug level for stacktraces:\n" + ExceptionHelper.collectAllMessages(current));
}
if (log.isDebugEnabled()) {
do {
log.debug("Encryption plugin failed", current);
} while ((current = current.getNextException()) != null);
}
}
}
use of org.firebirdsql.util.SQLExceptionChainBuilder in project jaybird by FirebirdSQL.
the class Arc4EncryptionPlugin method initializeEncryption.
@Override
public EncryptionInitInfo initializeEncryption() {
SQLExceptionChainBuilder<SQLException> chainBuilder = new SQLExceptionChainBuilder<>();
Cipher encryptionCipher = createEncryptionCipher(chainBuilder);
Cipher decryptionCipher = createDecryptionCipher(chainBuilder);
if (chainBuilder.hasException()) {
return EncryptionInitInfo.failure(getEncryptionIdentifier(), chainBuilder.getException());
}
return EncryptionInitInfo.success(getEncryptionIdentifier(), encryptionCipher, decryptionCipher);
}
Aggregations