[java-plugin-storage-jdbc] branch main updated: JJDBC-20 - Extend to support EnumeratableStorageService interface
Scott Cantor
cantor.2 at osu.edu
Thu Aug 3 19:26:02 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-plugin-storage-jdbc.
View the commit online:
http://git.shibboleth.net/view/?p=java-plugin-storage-jdbc.git;a=commit;h=c62de5cf16c4fd108c7427d8e3d023e5ec94eed1
The following commit(s) were added to refs/heads/main by this push:
new c62de5c JJDBC-20 - Extend to support EnumeratableStorageService interface
c62de5c is described below
commit c62de5cf16c4fd108c7427d8e3d023e5ec94eed1
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Aug 3 15:25:59 2023 -0400
JJDBC-20 - Extend to support EnumeratableStorageService interface
https://shibboleth.atlassian.net/browse/JJDBC-20
Implement new method.
---
.../storage/jdbc/impl/JDBCStorageService.java | 79 +++++++++++++++++-----
1 file changed, 61 insertions(+), 18 deletions(-)
diff --git a/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java b/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java
index 9326eb6..ecd6b37 100644
--- a/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java
+++ b/jdbc-storage-impl/src/main/java/net/shibboleth/plugin/storage/jdbc/impl/JDBCStorageService.java
@@ -71,10 +71,10 @@ public final class JDBCStorageService extends AbstractStorageService
/** The SQL to get all the records for a specific context.*/
static final String DEFAULT_READ_ALL_BY_CONTEXT_SQL =
- "SELECT id, expires, value, version FROM StorageRecords WHERE context = ?";
+ "SELECT id, expires, value, version FROM StorageRecords WHERE context=?";
/** The SQL to get check whether this record already exists and is unexpired prior to a create.*/
- static final String DEFAULT_PRE_CREATE_QUERY_SQL = "SELECT expires FROM StorageRecords WHERE context =? AND id=?";
+ static final String DEFAULT_PRE_CREATE_QUERY_SQL = "SELECT expires FROM StorageRecords WHERE context=? AND id=?";
/** The SQL to create a new record. */
static final String DEFAULT_CREATE_CREATE_RECORD_SQL =
@@ -86,18 +86,18 @@ public final class JDBCStorageService extends AbstractStorageService
/** The SQL to read a single record.*/
static final String DEFAULT_READ_RECORD_SQL =
- "SELECT version, expires, value FROM StorageRecords WHERE context =? AND id=?";
+ "SELECT version, expires, value FROM StorageRecords WHERE context=? AND id=?";
/** The SQL to check whether a record exists prior to updating it. */
static final String DEFAULT_PRE_UPDATE_QUERY_SQL =
- "SELECT version, expires, value FROM StorageRecords WHERE context =? AND id=?";
+ "SELECT version, expires, value FROM StorageRecords WHERE context=? AND id=?";
/** The SQL to update a record. */
static final String DEFAULT_UPDATE_RECORD_SQL =
"UPDATE StorageRecords SET value=?, version=?, expires=? WHERE context=? AND id=?";
/** The SQL to check whether a record exists prior to deleting it.*/
- static final String DEFAULT_PRE_DELETE_QUERY_SQL ="SELECT version FROM StorageRecords WHERE context =? AND id=?";
+ static final String DEFAULT_PRE_DELETE_QUERY_SQL ="SELECT version FROM StorageRecords WHERE context=? AND id=?";
/** The SQL to delete a record. */
static final String DEFAULT_DELETE_RECORD_SQL = "DELETE FROM StorageRecords WHERE context=? AND id=?";
@@ -111,10 +111,14 @@ public final class JDBCStorageService extends AbstractStorageService
/** The SQL to update the expiration for a given context. */
static final String DEFAULT_UPDATE_EXPIRES_BY_CONTEXT_SQL =
- "UPDATE StorageRecords SET expires = ? WHERE context = ? AND expires > ? ";
+ "UPDATE StorageRecords SET expires=? WHERE context = ? AND expires > ? ";
/** The SQL to delete a given context. */
- static final String DEFAULT_DELETE_BY_CONTEXT_SQL = "DELETE FROM StorageRecords WHERE context = ? ";
+ static final String DEFAULT_DELETE_BY_CONTEXT_SQL = "DELETE FROM StorageRecords WHERE context=? ";
+
+ /** The SQL to fetch the keys in a context. */
+ static final String DEFAULT_GET_CONTEXT_KEYS_SQL =
+ "SELECT id FROM StorageRecords WHERE context=? AND (expires IS NULL OR expires > ?)";
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(JDBCStorageService.class);
@@ -225,10 +229,16 @@ public final class JDBCStorageService extends AbstractStorageService
@Nonnull @NotEmpty private String updateExpiresByContextSQL = DEFAULT_UPDATE_EXPIRES_BY_CONTEXT_SQL;
/**
- * The SQL to to delete a given context. .
+ * The SQL to to delete a given context.
* Default: {@value #DEFAULT_DELETE_BY_CONTEXT_SQL}
*/
@Nonnull @NotEmpty private String deleteByContextSQL = DEFAULT_DELETE_BY_CONTEXT_SQL;
+
+ /**
+ * The SQL to fetch the keys in a context.
+ * Default: {@value #DEFAULT_GET_CONTEXT_KEYS_SQL}
+ */
+ @Nonnull @NotEmpty private String getContextKeysSQL = DEFAULT_GET_CONTEXT_KEYS_SQL;
/** Constructor.
* Set the defaults so that they can be over-ridden by Spring.
@@ -376,7 +386,7 @@ public final class JDBCStorageService extends AbstractStorageService
/** Set the SQL to check whether a record exists prior to deleting it.
* @param what The SQL to set.
*/
- public void setPreDeleteQuerySQL(final String what) {
+ public void setPreDeleteQuerySQL(@Nonnull @NotEmpty final String what) {
preDeleteQuerySQL = Constraint.isNotNull(StringSupport.trimOrNull(what),
"PreDeleteSQL should be non-null and non empty");
}
@@ -393,7 +403,7 @@ public final class JDBCStorageService extends AbstractStorageService
* Used as part of the {@link #getCleanupTask()}.
* @param what The SQL to set.
*/
- public void setDeleteByExpiredSQL(final String what) {
+ public void setDeleteByExpiredSQL(@Nonnull @NotEmpty final String what) {
deleteByExpiredSQL = Constraint.isNotNull(StringSupport.trimOrNull(what),
"DeleteByExpiredSQL should be non-null and non empty");
}
@@ -402,7 +412,7 @@ public final class JDBCStorageService extends AbstractStorageService
* Used as part of {@link #reap(String)}.
* @param what The SQL to set.
*/
- public void setDeleteByContextExpiredSQL(final String what) {
+ public void setDeleteByContextExpiredSQL(@Nonnull @NotEmpty final String what) {
deleteByContextExpiredSQL = Constraint.isNotNull(StringSupport.trimOrNull(what),
"DeleteByContextExpiredSQL should be non-null and non empty");
}
@@ -410,7 +420,7 @@ public final class JDBCStorageService extends AbstractStorageService
/** Set the SQL to update the expiration of a record specified by context.
* @param what The SQL to set.
*/
- public void setUpdateExpiresByContextSQL(final String what) {
+ public void setUpdateExpiresByContextSQL(@Nonnull @NotEmpty final String what) {
updateExpiresByContextSQL = Constraint.isNotNull(StringSupport.trimOrNull(what),
"UpdateExpiresByContextSQL should be non-null and non empty");
}
@@ -418,10 +428,22 @@ public final class JDBCStorageService extends AbstractStorageService
/** Set the SQL to Delete a specified Context.
* @param what The SQL to set.
*/
- public void setDeleteByContextSQL(final String what) {
+ public void setDeleteByContextSQL(@Nonnull @NotEmpty final String what) {
deleteByContextSQL = Constraint.isNotNull(StringSupport.trimOrNull(what),
"DeleteByContextSQL should be non-null and non empty");
}
+
+ /**
+ * Set the SQL to fetch the keys in a specified context.
+ *
+ * @param what the SQL to set
+ *
+ * @since 2.0.0
+ */
+ public void setGetContextKeysSQL(@Nonnull @NotEmpty final String what) {
+ this.getContextKeysSQL = Constraint.isNotNull(StringSupport.trimOrNull(what),
+ "GetContextKeysSQL cannot be null or empty");
+ }
/** {@inheritDoc} */
protected void doInitialize() throws ComponentInitializationException {
@@ -736,7 +758,7 @@ public final class JDBCStorageService extends AbstractStorageService
* @throws IOException if errors occur in the update process
* @throws VersionMismatchException if the record found contains a version that does not match the parameter
*/
- // Checkstyle: CyclomaticComplexity OFF
+// Checkstyle: CyclomaticComplexity|MethodLength OFF
@Nullable protected Long updateImpl(@Nullable final Long version,
@Nonnull @NotEmpty final String context,
@Nonnull @NotEmpty final String key,
@@ -813,7 +835,7 @@ public final class JDBCStorageService extends AbstractStorageService
}
}
}
- // Checkstyle: CyclomaticComplexity ON
+// Checkstyle: CyclomaticComplexity|MethodLength ON
/** {@inheritDoc} */
@Override public boolean deleteWithVersion(@Positive final long version,
@@ -1025,7 +1047,7 @@ public final class JDBCStorageService extends AbstractStorageService
try (ConnectionWithLock connection = new ConnectionWithLock(true, true)) {
final PreparedStatement updateStmnt = connection.prepareStatement(deleteByContextSQL);
updateStmnt.setString(1, context);
- log.trace("UpdateContextExpiration:: '{}': 1: '{}'", deleteByContextSQL, context);
+ log.trace("UpdateContextExpiration:: '{}': 1: '{}'", deleteByContextSQL, context);
updateStmnt.execute();
return;
@@ -1055,8 +1077,29 @@ public final class JDBCStorageService extends AbstractStorageService
/** {@inheritDoc} */
@Nonnull public Iterable<String> getContextKeys(@Nonnull @NotEmpty final String context) throws IOException {
- // TODO: implement this
- return CollectionSupport.emptyList();
+ final List<String> result = new ArrayList<>();
+
+ try (final ConnectionWithLock connection= new ConnectionWithLock(true, false)) {
+ final PreparedStatement query = connection.prepareStatement(getContextKeysSQL);
+ query.setString(1, context);
+
+ final Long now = System.currentTimeMillis();
+ setExpires(query, 2, now);
+
+ log.trace("GetContextKeys:: '{}': 1: '{}', 2: '{}'", deleteByContextSQL, context, now);
+
+ final ResultSet results = query.executeQuery();
+
+ while (results.next()) {
+ final String key = results.getString(1);
+ result.add(key);
+ }
+ return result;
+
+ } catch (final SQLException e) {
+ log.error("GetContextKeys failed", e);
+ throw new IOException(e);
+ }
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list