Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
Updated to Java 8 and Sesame 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ameingast committed Dec 5, 2015
1 parent 0d0fec8 commit 83ddc78
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 80 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2013 Andreas Meingast <ameingast@gmail.com>
Copyright 2013 - 2015 Andreas Meingast <ameingast@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
18 changes: 10 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-spring</artifactId>

<version>2.8.6</version>
<version>4.0.0</version>
<name>${project.artifactId}</name>

<description>
Expand Down Expand Up @@ -104,15 +104,14 @@
<scope>test</scope>
</dependency>

<!-- logging -->
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>

<!-- Test -->
<!-- Unit Testing-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -139,20 +138,23 @@
<source>${language-level}</source>
<target>${language-level}</target>
<encoding>${encoding}</encoding>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerArgument>-Xlint:all,-serial</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<spring.version>4.2.1.RELEASE</spring.version>
<spring.version>4.2.3.RELEASE</spring.version>
<sesame.version>${project.version}</sesame.version>
<junit.version>4.12</junit.version>
<slf4j.version>1.7.12</slf4j.version>
<cglib.version>3.1</cglib.version>
<slf4j.version>1.7.13</slf4j.version>
<cglib.version>3.2.0</cglib.version>
<maven-compiler.version>3.3</maven-compiler.version>

<encoding>UTF-8</encoding>
<language-level>1.6</language-level>
<language-level>1.8</language-level>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ public class DynamicRepositoryManagerConnectionFactory implements SesameConnecti
* identify the {@link org.openrdf.repository.Repository} to which connections will be opened is retrieved
* from via a call-back from <code>repositoryIdProvider</code>.
*/
public DynamicRepositoryManagerConnectionFactory(RepositoryManager repositoryManager,
RepositoryIdProvider repositoryIdProvider) {
DynamicRepositoryManagerConnectionFactory(RepositoryManager repositoryManager,
RepositoryIdProvider repositoryIdProvider) {
this(repositoryManager, null, repositoryIdProvider);
}

public DynamicRepositoryManagerConnectionFactory(RepositoryManager repositoryManager,
RepositoryImplConfig repositoryImplConfig,
RepositoryIdProvider repositoryIdProvider) {
DynamicRepositoryManagerConnectionFactory(RepositoryManager repositoryManager,
RepositoryImplConfig repositoryImplConfig,
RepositoryIdProvider repositoryIdProvider) {
this.repositoryManager = repositoryManager;
this.repositoryImplConfig = repositoryImplConfig;
this.repositoryIdProvider = repositoryIdProvider;
this.repositoryConnectionFactoryMap = new HashMap<String, RepositoryConnectionFactory>(128);
this.repositoryConnectionFactoryMap = new HashMap<>(128);
}

/**
Expand Down Expand Up @@ -124,9 +124,7 @@ private RepositoryConnectionFactory initializeRepositoryConnectionFactory(String
}

return new RepositoryConnectionFactory(repository);
} catch (RepositoryException e) {
throw new SesameTransactionException(e);
} catch (RepositoryConfigException e) {
} catch (RepositoryException | RepositoryConfigException e) {
throw new SesameTransactionException(e);
}
}
Expand Down Expand Up @@ -160,7 +158,7 @@ public String toString() {
* Call-back helper to provide runtime-dynamic repository-ids for
* {@link org.openrdf.spring.DynamicRepositoryManagerConnectionFactory}.
*/
public static interface RepositoryIdProvider {
public interface RepositoryIdProvider {
String getRepositoryId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.transaction.TransactionSystemException;

Expand All @@ -17,6 +19,8 @@
* @see SesameConnectionFactory
*/
public class RepositoryConnectionFactory implements DisposableBean, SesameConnectionFactory {
private static final Logger log = LoggerFactory.getLogger(RepositoryConnectionFactory.class);

private final ThreadLocal<SesameTransactionObject> localTransactionObject;

private final Repository repository;
Expand All @@ -28,7 +32,7 @@ public class RepositoryConnectionFactory implements DisposableBean, SesameConnec
*/
public RepositoryConnectionFactory(Repository repository) {
this.repository = repository;
localTransactionObject = new ThreadLocal<SesameTransactionObject>();
localTransactionObject = new ThreadLocal<>();
}

/**
Expand All @@ -46,7 +50,7 @@ public RepositoryConnection getConnection() {

try {
if (!repositoryConnection.isOpen()) {
throw new SesameTransactionException("Connection closed during transaction");
throw new SesameTransactionException("Cannot get connection. Connection closed during transaction.");
}

if (!repositoryConnection.isActive()) {
Expand Down Expand Up @@ -88,7 +92,7 @@ public void closeConnection() {
try {
repositoryConnection.close();
} catch (RepositoryException e) {
throw new SesameTransactionException(e);
log.error(e.getMessage(), e);
}

localTransactionObject.remove();
Expand Down Expand Up @@ -123,7 +127,7 @@ public void endTransaction(boolean rollback) throws RepositoryException {
RepositoryConnection repositoryConnection = sesameTransactionObject.getRepositoryConnection();

if (!repositoryConnection.isOpen()) {
throw new SesameTransactionException("Connection closed during transaction");
throw new SesameTransactionException("Cannot end transaction: Connection closed during transaction");
}

if (repositoryConnection.isActive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,10 @@ public class RepositoryManagerConnectionFactory extends DynamicRepositoryManager
* identify the {@link org.openrdf.repository.Repository} to which connections will be opened.
*/
public RepositoryManagerConnectionFactory(RepositoryManager repositoryManager, final String repositoryId) {
super(repositoryManager, new RepositoryIdProvider() {
@Override
public String getRepositoryId() {
return repositoryId;
}
});
super(repositoryManager, () -> repositoryId);
}

public RepositoryManagerConnectionFactory(RepositoryManager repositoryManager, RepositoryImplConfig repositoryImplConfig, final String repositoryId) {
super(repositoryManager, repositoryImplConfig, new RepositoryIdProvider() {
@Override
public String getRepositoryId() {
return repositoryId;
}
});
super(repositoryManager, repositoryImplConfig, () -> repositoryId);
}
}
23 changes: 0 additions & 23 deletions src/main/java/org/openrdf/spring/SafeTransactional.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface SesameConnectionFactory extends DisposableBean {
* <li>The connection was closed during the transaction</li>
* </ul>
*/
public RepositoryConnection getConnection();
RepositoryConnection getConnection();

/**
* <p>Closes the connection and cleans up the (thread-local) state for the current transaction.</p>
Expand Down
35 changes: 16 additions & 19 deletions src/test/java/org/openrdf/spring/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.openrdf.model.URI;
import org.openrdf.model.IRI;
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.model.impl.SimpleValueFactory;
import org.openrdf.query.BindingSet;
import org.openrdf.query.QueryLanguage;
import org.openrdf.query.TupleQuery;
Expand All @@ -26,44 +26,41 @@ public abstract class BaseTest {
@Autowired
protected SesameConnectionFactory repositoryManagerConnectionFactory;

protected static void assertDataPresent(SesameConnectionFactory sesameConnectionFactory) throws Exception {
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());
withTupleQueryResult(result, tupleQueryResult -> {
Assert.assertTrue(tupleQueryResult.hasNext());

BindingSet bindingSet = tupleQueryResult.next();
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());
}
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 {
TupleQueryResultHandler tupleQueryResultHandler) {
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");
static void addData(SesameConnectionFactory sesameConnectionFactory) throws RepositoryException {
ValueFactory f = SimpleValueFactory.getInstance();
IRI a = f.createIRI("http://example.com/a");
IRI b = f.createIRI("http://example.com/b");
IRI c = f.createIRI("http://example.com/c");

RepositoryConnection connection = sesameConnectionFactory.getConnection();
connection.add(a, b, c);
}

static interface TupleQueryResultHandler {
void handle(TupleQueryResult tupleQueryResult) throws Exception;
interface TupleQueryResultHandler {
void handle(TupleQueryResult tupleQueryResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public void testWrapTransactions() {
}

@Transactional
protected RepositoryConnection transactionScope() {
private RepositoryConnection transactionScope() {
return repositoryManagerConnectionFactory.getConnection();
}

protected RepositoryConnection transactionScopeWithoutAnnotation() {
private RepositoryConnection transactionScopeWithoutAnnotation() {
return repositoryManagerConnectionFactory.getConnection();
}

Expand Down

0 comments on commit 83ddc78

Please sign in to comment.