[java-plugin-storage-jdbc] 03/03: OSJ-342 Investigate Strategies to end of life our use of Hibernate in V5
Rod Widdowson
rdw at steadingsoftware.com
Wed Jun 1 10:34:37 UTC 2022
This is an automated email from the git hooks/post-receive script.
rdw 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=b73a5da619c202eea2f9aa843877dc067bdeb58b
commit b73a5da619c202eea2f9aa843877dc067bdeb58b
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Jun 1 11:33:53 2022 +0100
OSJ-342 Investigate Strategies to end of life our use of Hibernate in V5
https://shibboleth.atlassian.net/browse/OSJ-342
Add database validation (controlled by p:verify)
---
.../storage/jdbc/impl/JDBCStorageService.java | 45 +++++++++++++++++++++-
1 file changed, 43 insertions(+), 2 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 5ecf6bf..828d7a0 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
@@ -62,7 +62,10 @@ import net.shibboleth.utilities.java.support.primitive.StringSupport;
*/
public final class JDBCStorageService extends AbstractStorageService implements StorageCapabilitiesEx {
- /* Default SQL. Keep it here to keep it together and to allow isertion into javadoc */
+ /** The context, key and value we test the database with. */
+ static final String VERIFY_STRING = "net.shibboleth.plugin.storage.jdbc.impl.test";
+
+ /* Default SQL. Keep it here to keep it together and to allow insertion into javadoc */
/** The SQL to get all the contexts.*/
static final String DEFAULT_READ_CONTEXTS_SQL = "SELECT context FROM StorageRecords";
@@ -126,10 +129,13 @@ public final class JDBCStorageService extends AbstractStorageService implements
/** What transaction isolation do we want? */
private int transactionIsolation = Connection.TRANSACTION_SERIALIZABLE;
-
+
/** If non-null we doing local locking. */
private ReadWriteLock readWriteLock;
+ /** Are we verifying the database during initialize? */
+ private boolean verify;
+
/** Error messages that signal a transaction should be retried. */
@Nonnull @NonnullElements private Collection<String> retryableErrors = Collections.emptyList();
@@ -249,6 +255,13 @@ public final class JDBCStorageService extends AbstractStorageService implements
}
}
+ /** Set whether we are to verify the database during initialize.
+ * @param what the value to set
+ */
+ public void setVerify(final boolean what) {
+ verify = what;
+ }
+
/** Set the parameter that will be passed to {@link Connection#setTransactionIsolation(int)}.
* @param what the value to set
*/
@@ -404,6 +417,13 @@ public final class JDBCStorageService extends AbstractStorageService implements
protected void doInitialize() throws ComponentInitializationException {
Constraint.isNotNull(dataSource, "data source must be specified and non-null");
super.doInitialize();
+ if (verify) {
+ try {
+ verifyDatabase();
+ } catch (final IOException | ComponentInitializationException e) {
+ throw new ComponentInitializationException(e);
+ }
+ }
}
/**
@@ -1019,6 +1039,27 @@ public final class JDBCStorageService extends AbstractStorageService implements
}
}
+ /**
+ * Check the database and the presence of a uniqueness constraint.
+ * - Create a record and give it 10 minutes life
+ * - Read it back
+ * - Delete it
+ *
+ * @throws IOException if our methods fail
+ * @throws ComponentInitializationException if no record was inserted or the wrong value came back
+ */
+ private void verifyDatabase() throws IOException, ComponentInitializationException {
+ create(VERIFY_STRING, VERIFY_STRING, VERIFY_STRING, System.currentTimeMillis() + 10 * 60 * 1000);
+ final StorageRecord<?> record = read(VERIFY_STRING, VERIFY_STRING);
+ if (record == null) {
+ throw new ComponentInitializationException("Insert into database failed");
+ }
+ if (!VERIFY_STRING.equals(record.getValue())) {
+ throw new ComponentInitializationException("Value read back was incorrect");
+ }
+ delete(VERIFY_STRING, VERIFY_STRING);
+ }
+
/** Return the value of expires in the supplied column of the supplied {@link ResultSet}.
* @param results the results whose current row we want to inspect
* @param columm the column
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list