[java-shib-attribute] branch main updated: JSATTR-37 Review JDBC code for commit/rollback leaks
Rod Widdowson
rdw at steadingsoftware.com
Wed Sep 25 12:49:20 UTC 2024
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-shib-attribute.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=48405232a51599b014b63a7e1bbc138d3a0e8137
The following commit(s) were added to refs/heads/main by this push:
new 48405232a JSATTR-37 Review JDBC code for commit/rollback leaks
48405232a is described below
commit 48405232a51599b014b63a7e1bbc138d3a0e8137
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Sep 25 13:48:36 2024 +0100
JSATTR-37 Review JDBC code for commit/rollback leaks
https://shibboleth.atlassian.net/browse/JSATTR-37
Made the same changes as was made to the same sub class in JJDBC-30
---
.../idp/attribute/impl/JDBCPairwiseIdStore.java | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java b/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java
index f5c76e5e0..0903c5244 100644
--- a/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java
+++ b/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java
@@ -640,6 +640,7 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
assert initialValueStore != null;
retValue = initialValueStore.getBySourceValue(pid, allowCreate);
if (retValue == null) {
+ dbConn.rollback();
throw new IOException("Unable to obtain value from initial value store");
}
} else {
@@ -947,6 +948,15 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
/** The lock we may or may not have set up. */
@Nullable private final Lock threadLock;
+ /** Was this created autocommit? */
+ private final boolean isAutoCommit;
+
+ /** Has {@link #commit()} been called? */
+ private boolean isCommited;
+
+ /** Has {@link #rollback()} been called? */
+ private boolean isRolledBack;
+
/** Constructor.
* @param autoCommit what to set {@link Connection#setAutoCommit(boolean)} ti
* @param writeLock if we are also arbitrating table access (as per {@link JDBCPairwiseIdStore#setLocalLocking(boolean)})
@@ -958,6 +968,7 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
assert conn != null;
connection = conn;
connection.setAutoCommit(autoCommit);
+ isAutoCommit = autoCommit;
connection.setTransactionIsolation(transactionIsolation);
if (readWriteLock != null) {
final Lock tlock;
@@ -993,11 +1004,23 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
* @throws SQLException if encapsulated {@link Connection} does
*/
public void commit() throws SQLException {
+ assert !isAutoCommit && !isCommited && !isRolledBack;
+ isCommited = true;
connection.commit();
}
+ /** Delegated operation to the encapsulated {@link Connection}.
+ * @throws SQLException if encapsulated {@link Connection} does
+ */
+ public void rollback() throws SQLException {
+ assert !isAutoCommit && !isCommited && !isRolledBack;
+ isRolledBack = true;
+ connection.rollback();
+ }
+
/** {@inheritDoc} */
public void close() {
+ assert isAutoCommit || isCommited || isRolledBack;
try {
connection.close();
} catch (final SQLException e) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list