This repository has been archived by the owner on Sep 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 2.8.0: Bumped spring dependency to 4.0.4 More fine-grained synchronization in DynamicRepositoryManagerConnectionFactory Updated tests Added isolation support Conflicts: pom.xml
- Loading branch information
Showing
9 changed files
with
199 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/org/openrdf/spring/IsolationLevelAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.openrdf.spring; | ||
|
||
import org.openrdf.IsolationLevel; | ||
import org.openrdf.IsolationLevels; | ||
import org.openrdf.sail.Sail; | ||
import org.springframework.transaction.InvalidIsolationLevelException; | ||
import org.springframework.transaction.TransactionDefinition; | ||
|
||
/** | ||
* <p>Adapter to convert spring {@link TransactionDefinition} isolation levels to corresponding OpenRDF | ||
* {@link org.openrdf.IsolationLevel}s.</p> | ||
* <p/> | ||
* <p>The conversion depends on the provided {@link org.openrdf.sail.Sail} and its transaction capabilities. | ||
* If the {@link org.openrdf.sail.Sail} is not compatible with the provided isolation level, an | ||
* {@link org.springframework.transaction.InvalidIsolationLevelException} is thrown.<p/> | ||
* | ||
* @author ameingast@gmail.com | ||
*/ | ||
class IsolationLevelAdapter { | ||
static IsolationLevel adaptToRdfIsolation(Sail sail, int springIsolation) { | ||
switch (springIsolation) { | ||
case TransactionDefinition.ISOLATION_DEFAULT: | ||
return sail.getDefaultIsolationLevel(); | ||
case TransactionDefinition.ISOLATION_READ_COMMITTED: | ||
return determineIsolationLevel(sail, IsolationLevels.READ_COMMITTED); | ||
case TransactionDefinition.ISOLATION_READ_UNCOMMITTED: | ||
return determineIsolationLevel(sail, IsolationLevels.READ_UNCOMMITTED); | ||
case TransactionDefinition.ISOLATION_REPEATABLE_READ: | ||
throw new InvalidIsolationLevelException("Unsupported isolation level for sail: " + sail + ": " + springIsolation); | ||
case TransactionDefinition.ISOLATION_SERIALIZABLE: | ||
return determineIsolationLevel(sail, IsolationLevels.SERIALIZABLE); | ||
default: | ||
throw new InvalidIsolationLevelException("Unsupported isolation level for sail: " + sail + ": " + springIsolation); | ||
} | ||
} | ||
|
||
private static IsolationLevel determineIsolationLevel(Sail sail, IsolationLevel isolationLevel) { | ||
if (sail.getSupportedIsolationLevels().contains(isolationLevel)) { | ||
return isolationLevel; | ||
} else { | ||
throw new InvalidIsolationLevelException("Unsupported isolation level for sail: " + sail + ": " + isolationLevel); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.openrdf.spring; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Ignore; | ||
import org.junit.runner.RunWith; | ||
import org.openrdf.model.URI; | ||
import org.openrdf.model.ValueFactory; | ||
import org.openrdf.model.impl.ValueFactoryImpl; | ||
import org.openrdf.query.BindingSet; | ||
import org.openrdf.query.QueryLanguage; | ||
import org.openrdf.query.TupleQuery; | ||
import org.openrdf.query.TupleQueryResult; | ||
import org.openrdf.repository.RepositoryConnection; | ||
import org.openrdf.repository.RepositoryException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
@Ignore | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(locations = "/repositoryTestContext.xml") | ||
public abstract class BaseTest { | ||
@Autowired | ||
protected SesameConnectionFactory repositoryConnectionFactory; | ||
|
||
@Autowired | ||
protected SesameConnectionFactory repositoryManagerConnectionFactory; | ||
|
||
protected static void assertDataPresent(SesameConnectionFactory sesameConnectionFactory) throws Exception { | ||
RepositoryConnection connection = sesameConnectionFactory.getConnection(); | ||
final TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT ?s ?o WHERE { ?s <http://example.com/b> ?o . }"); | ||
TupleQueryResult result = tupleQuery.evaluate(); | ||
|
||
withTupleQueryResult(result, new TupleQueryResultHandler() { | ||
@Override | ||
public void handle(TupleQueryResult tupleQueryResult) throws Exception { | ||
Assert.assertTrue(tupleQueryResult.hasNext()); | ||
|
||
BindingSet bindingSet = tupleQueryResult.next(); | ||
|
||
Assert.assertEquals("http://example.com/a", bindingSet.getBinding("s").getValue().stringValue()); | ||
Assert.assertEquals("http://example.com/c", bindingSet.getBinding("o").getValue().stringValue()); | ||
} | ||
}); | ||
} | ||
|
||
private static void withTupleQueryResult(TupleQueryResult tupleQueryResult, | ||
TupleQueryResultHandler tupleQueryResultHandler) throws Exception { | ||
try { | ||
tupleQueryResultHandler.handle(tupleQueryResult); | ||
} finally { | ||
tupleQueryResult.close(); | ||
} | ||
} | ||
|
||
protected static void addData(SesameConnectionFactory sesameConnectionFactory) throws RepositoryException { | ||
ValueFactory f = ValueFactoryImpl.getInstance(); | ||
URI a = f.createURI("http://example.com/a"); | ||
URI b = f.createURI("http://example.com/b"); | ||
URI c = f.createURI("http://example.com/c"); | ||
|
||
RepositoryConnection connection = sesameConnectionFactory.getConnection(); | ||
connection.add(a, b, c); | ||
} | ||
|
||
static interface TupleQueryResultHandler { | ||
void handle(TupleQueryResult tupleQueryResult) throws Exception; | ||
} | ||
} |
Oops, something went wrong.