[java-opensaml] 05/05: Missing methods

Rod Widdowson rdw at steadingsoftware.com
Thu May 12 10:13:01 UTC 2022


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch dev/OSJ-342
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=c1224f89f489bbb26a279f5fb6ae3705f54202cd

commit c1224f89f489bbb26a279f5fb6ae3705f54202cd
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue May 10 20:10:29 2022 +0100

    Missing methods
---
 .../opensaml/storage/impl/JDBCStorageService.java  | 69 +++++++++++++++++++++-
 1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JDBCStorageService.java b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JDBCStorageService.java
index 2525243cb..e424db6e6 100644
--- a/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JDBCStorageService.java
+++ b/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JDBCStorageService.java
@@ -563,12 +563,77 @@ public final class JDBCStorageService extends AbstractStorageService implements
 
     /** {@inheritDoc} */
     public void reap(String context) throws IOException {
-        throw new IOException("Not implemented");
+        //
+        // Constraints, Logging
+        //
+        int retries = transactionRetry;
+        while (true) {
+            try (Connection connection = getConnection(true)) {
+                final PreparedStatement updateStmnt = connection.prepareStatement("DELETE FROM StorageRecords WHERE context = ? AND expires <= ?");
+                updateStmnt.setString(1, context);
+                setExpires(updateStmnt, 2, System.currentTimeMillis());
+                updateStmnt.execute();
+                connection.commit();
+                return;
+            }
+            catch (final SQLException e) {
+                boolean retry = false;
+                for (final String msg : retryableErrors) {
+                    if (e.getSQLState() != null && e.getSQLState().contains(msg)) {
+                        log.warn("Caught retryable SQL exception", e);
+                        retry = true;
+                        break;
+                    }
+                }
+                if (retry) {
+                    if (--retries < 0) {
+                        log.warn("Error retryable, but retry limit exceeded");
+                        throw new IOException(e);
+                    }
+                    log.info("Retrying JDBC DeleteByContext Operation");
+                } else {
+                    throw new IOException(e);
+                }
+            }
+        }
     }
 
     /** {@inheritDoc} */
     public void updateContextExpiration(String context, Long expires) throws IOException {
-        throw new IOException("Not implemented");
+        //
+        // Constraints, Logging
+        //
+        int retries = transactionRetry;
+        while (true) {
+            try (Connection connection = getConnection(true)) {
+                final PreparedStatement updateStmnt = connection.prepareStatement("UPDATE StorageRecords SET expires = ? WHERE context = ? AND expires > ? ");
+                setExpires(updateStmnt, 1, expires);
+                updateStmnt.setString(2, context);
+                setExpires(updateStmnt, 3, System.currentTimeMillis());
+                updateStmnt.execute();
+                connection.commit();
+                return;
+            }
+            catch (final SQLException e) {
+                boolean retry = false;
+                for (final String msg : retryableErrors) {
+                    if (e.getSQLState() != null && e.getSQLState().contains(msg)) {
+                        log.warn("Caught retryable SQL exception", e);
+                        retry = true;
+                        break;
+                    }
+                }
+                if (retry) {
+                    if (--retries < 0) {
+                        log.warn("Error retryable, but retry limit exceeded");
+                        throw new IOException(e);
+                    }
+                    log.info("Retrying JDBC DeleteByContext Operation");
+                } else {
+                    throw new IOException(e);
+                }
+            }
+        }
     }
 
     /** {@inheritDoc} */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list