[java-opensaml COMMIT] in /trunk/opensaml-storage-impl: pom.xml src/main/java/org/opensaml/storage/impl/JPAStorageSer...
noreply at shibboleth.net
noreply at shibboleth.net
Tue Feb 17 15:11:39 EST 2015
Author: dfisher
Date: Tue Feb 17 15:11:39 2015
New Revision: 4228
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4228&view=rev
Log:
OSJ-101.
Updated JPAStorageService to include transactionRetry property with default value of
3.
Updated write methods to loop and retry on RollbackException.
Added mysql and postgres as test dependencies, beans that use them are lazy init.
Modified:
trunk/opensaml-storage-impl/pom.xml
trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JPAStorageService.java
trunk/opensaml-storage-impl/src/test/java/org/opensaml/storage/impl/JPAStorageServiceTest.java
trunk/opensaml-storage-impl/src/test/resources/org/opensaml/storage/impl/jpa-spring-context.xml
Modified: trunk/opensaml-storage-impl/pom.xml
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-storage-impl/pom.xml?rev=4228&r1=4227&r2=4228&view=diff
==============================================================================
--- trunk/opensaml-storage-impl/pom.xml (original)
+++ trunk/opensaml-storage-impl/pom.xml Tue Feb 17 15:11:39 2015
@@ -85,6 +85,26 @@
</dependency>
<dependency>
+ <groupId>com.mchange</groupId>
+ <artifactId>c3p0</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ <version>9.3-1101-jdbc41</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.34</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>${spring.groupId}</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
Modified: trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JPAStorageService.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JPAStorageService.java?rev=4228&r1=4227&r2=4228&view=diff
==============================================================================
--- trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JPAStorageService.java (original)
+++ trunk/opensaml-storage-impl/src/main/java/org/opensaml/storage/impl/JPAStorageService.java Tue Feb 17 15:11:39 2015
@@ -32,11 +32,14 @@
import javax.persistence.EntityTransaction;
import javax.persistence.LockModeType;
import javax.persistence.Query;
-
+import javax.persistence.RollbackException;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NonNegative;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.annotation.constraint.Positive;
import net.shibboleth.utilities.java.support.collection.Pair;
+import net.shibboleth.utilities.java.support.component.ComponentSupport;
import net.shibboleth.utilities.java.support.logic.Constraint;
import org.opensaml.storage.AbstractStorageService;
@@ -56,6 +59,9 @@
/** Entity manager factory. */
@Nonnull private final EntityManagerFactory entityManagerFactory;
+ /** Number of times to retry a transaction if it rolls back. Default value is {@value} . */
+ @NonNegative private int transactionRetry = 3;
+
/**
* Creates a new JPA storage service.
*
@@ -69,6 +75,27 @@
setValueSize(Integer.MAX_VALUE);
}
+ /**
+ * Returns the number of times a transaction will be retried if a {@link RollbackException} is encountered.
+ *
+ * @return number of transaction retries
+ */
+ public int getTransactionRetry() {
+ return transactionRetry;
+ }
+
+ /**
+ * Sets the number of times a transaction will be retried.
+ *
+ * @param retry number of transaction retries
+ */
+ public void setTransactionRetry(final int retry) {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+ transactionRetry =
+ (int) Constraint.isGreaterThanOrEqual(0, retry,
+ "Transaction retry must be greater than or equal to zero");
+ }
+
/** {@inheritDoc} */
@Override protected void doDestroy() {
if (entityManagerFactory.isOpen()) {
@@ -77,69 +104,83 @@
super.doDestroy();
}
+ // Checkstyle: MethodLength OFF
// Checkstyle: CyclomaticComplexity OFF
/** {@inheritDoc} */
@Override public boolean create(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key,
@Nonnull @NotEmpty final String value, @Nullable @Positive final Long expiration) throws IOException {
EntityManager manager = null;
- EntityTransaction transaction = null;
- try {
- manager = entityManagerFactory.createEntityManager();
[... 710 lines stripped ...]
More information about the commits
mailing list