Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

import java.util.concurrent.Future;

import org.apache.commons.rdf.api.IRI;

/**
* A service that persists resources by appending to their records. Nothing that
* is recorded by {@link #add} will be deleted by using {@code add} again.
*
* @author ajs6f
*
* @param <T> the type of identifier for resources that can be persisted by this service
* @param <U> the type of resource that can be persisted by this service
* @param <T> the type of resource that can be persisted by this service
*/
public interface ImmutableDataService<T, U> extends RetrievalService<T, U> {
public interface ImmutableDataService<T> extends RetrievalService<T> {

/**
* @param identifier the identifier under which to persist a resource
* @param session the session context for this operation
* @param resource a resource to persist
* @return whether the resource was successfully persisted
*/
Future<Boolean> add(T identifier, Session session, U resource);
Future<Boolean> add(IRI identifier, Session session, T resource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
*/
public abstract class JoiningResourceService implements ResourceService {

private final ImmutableDataService<IRI, Resource> immutableData;
private final ImmutableDataService<Resource> immutableData;

private final MutableDataService<IRI, Resource> mutableData;
private final MutableDataService<Resource> mutableData;

/**
* @param mutableData service in which to persist mutable data
* @param immutableData service in which to persist immutable data
*/
public JoiningResourceService(final MutableDataService<IRI, Resource> mutableData,
final ImmutableDataService<IRI, Resource> immutableData) {
public JoiningResourceService(final MutableDataService<Resource> mutableData,
final ImmutableDataService<Resource> immutableData) {
this.immutableData = immutableData;
this.mutableData = mutableData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,38 @@

import java.util.concurrent.Future;

import org.apache.commons.rdf.api.IRI;

/**
* A service that persists resources by <i>replacing</i> their records.
*
* @author ajs6f
* @param <T> the type of identifier used by this service
* @param <U> the type of resource that can be persisted by this service
*/
public interface MutableDataService<T, U> extends RetrievalService<T, U> {
public interface MutableDataService<U> extends RetrievalService<U> {

/**
* @param identifier the identifier for the resource to persist
* @param session the session context for this operation
* @param resource a resource to persist
* @return whether the resource was successfully persisted
*/
Future<Boolean> create(T identifier, Session session, U resource);
Future<Boolean> create(IRI identifier, Session session, U resource);

/**
* @param identifier the identifier for the resource to persist
* @param session the session context for this operation
* @param resource a resource to persist
* @return whether the resource was successfully persisted
*/
Future<Boolean> replace(T identifier, Session session, U resource);
Future<Boolean> replace(IRI identifier, Session session, U resource);

/**
* @param identifier the identifier for the resource to delete
* @param session the session context for this operation
* @param resource a resource to delete
* @return whether the resource was successfully deleted
*/
Future<Boolean> delete(T identifier, Session session, U resource);
Future<Boolean> delete(IRI identifier, Session session, U resource);

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
*
* @author acoburn
*/
public interface ResourceService extends MutableDataService<IRI, Resource>,
ImmutableDataService<IRI, Resource> {
public interface ResourceService extends MutableDataService<Resource>, ImmutableDataService<Resource> {

@Override
default Future<Boolean> add(IRI identifier, Session session, Resource resource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
import java.time.Instant;
import java.util.Optional;

import org.apache.commons.rdf.api.IRI;

/**
* A service that can retrieve resources of some type, featuring optional
* retrieval by time.
*
* @author ajs6f
* @param <T> the type of identifier used by this service
* @param <U> the type of resource available from this service
* @param <T> the type of resource available from this service
*/
public interface RetrievalService<T, U> {
public interface RetrievalService<T> {

/**
* Get a resource by the given identifier.
*
* @param identifier the resource identifier
* @return the resource
*/
Optional<? extends U> get(T identifier);
Optional<? extends T> get(IRI identifier);

/**
* Get a resource by the given identifier and time.
Expand All @@ -42,7 +43,7 @@ public interface RetrievalService<T, U> {
* @param time the time
* @return the resource
*/
default Optional<? extends U> get(T identifier, Instant time) {
default Optional<? extends T> get(IRI identifier, Instant time) {
return get(identifier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static Quad createQuad(final BlankNodeOrIRI g, final BlankNodeOrIRI s, f

private static IRI badId = createIRI("http://bad.com");

private static class TestableRetrievalService implements RetrievalService<IRI, Resource> {
private static class TestableRetrievalService implements RetrievalService<Resource> {

protected final Map<IRI, Resource> resources = synchronizedMap(new HashMap<>());

Expand All @@ -82,7 +82,7 @@ protected CompletableFuture<Boolean> isntBadId(final IRI identifier) {
}

private static class TestableImmutableService extends TestableRetrievalService
implements ImmutableDataService<IRI, Resource> {
implements ImmutableDataService<Resource> {

@Override
public Future<Boolean> add(final IRI identifier, final Session session, final Resource newRes) {
Expand All @@ -91,10 +91,10 @@ public Future<Boolean> add(final IRI identifier, final Session session, final Re
}
}

private final ImmutableDataService<IRI, Resource> testImmutableService = new TestableImmutableService();
private final ImmutableDataService<Resource> testImmutableService = new TestableImmutableService();

private static class TestableMutableDataService extends TestableRetrievalService
implements MutableDataService<IRI, Resource> {
implements MutableDataService<Resource> {

@Override
public Future<Boolean> create(final IRI identifier, final Session session, final Resource resource) {
Expand All @@ -115,12 +115,12 @@ public Future<Boolean> delete(final IRI identifier, final Session session, final
}
};

private final MutableDataService<IRI, Resource> testMutableService = new TestableMutableDataService();
private final MutableDataService<Resource> testMutableService = new TestableMutableDataService();

private static class TestableJoiningResourceService extends JoiningResourceService {

public TestableJoiningResourceService(final ImmutableDataService<IRI, Resource> immutableData,
final MutableDataService<IRI, Resource> mutableData) {
public TestableJoiningResourceService(final ImmutableDataService<Resource> immutableData,
final MutableDataService<Resource> mutableData) {
super(mutableData, immutableData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public class ResourceServiceTest {
private static Resource mockResource;

@Mock
private RetrievalService<IRI, Resource> mockRetrievalService;
private RetrievalService<Resource> mockRetrievalService;

private static class MyRetrievalService implements RetrievalService<IRI, Resource> {
private static class MyRetrievalService implements RetrievalService<Resource> {
@Override
public Optional<Resource> get(final IRI id) {
return of(mockResource);
Expand All @@ -94,7 +94,7 @@ public void setUp() {

@Test
public void testRetrievalService2() {
final RetrievalService<IRI, Resource> svc = new MyRetrievalService();
final RetrievalService<Resource> svc = new MyRetrievalService();
final Optional<? extends Resource> res = svc.get(existing);
final Optional<? extends Resource> res2 = svc.get(existing, now());
assertTrue(res.isPresent());
Expand Down