Skip to content

Commit

Permalink
Make DataSet and DataSetRepo database agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
Martijn Maas committed Feb 8, 2018
1 parent d1420b2 commit 1f6901b
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
import com.sleepycat.bind.EntryBinding;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler;
import nl.knaw.huygens.timbuctoo.v5.dataset.StoreProvider;

public interface BdbEnvironmentCreator extends nl.knaw.huygens.timbuctoo.v5.dataset.EnvironmentCreator {

public interface BdbEnvironmentCreator {
<KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName,
boolean allowDuplicates, EntryBinding<KeyT> keyBinder,
EntryBinding<ValueT> valueBinder,
IsCleanHandler<KeyT, ValueT> cleanHandler)
throws BdbDbCreationException;

/**
* Closes and remove all the databases for a data set
*/
void closeEnvironment(String ownerId, String dataSetId);

void start();

void stop();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.sleepycat.je.EnvironmentConfig;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler;
import nl.knaw.huygens.timbuctoo.v5.dataset.StoreProvider;
import nl.knaw.huygens.timbuctoo.v5.filehelper.FileHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -40,6 +41,11 @@ public BdbPersistentEnvironmentCreator(@JsonProperty("databaseLocation") String
configuration.setSharedCache(true);
}

@Override
public StoreProvider createStoreProvider(String userId, String dataSetId) {
return new BdbStoreProvider(userId, dataSetId, this);
}

@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName,
boolean allowDuplicates, EntryBinding<KeyT> keyBinder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.io.IOException;

public class BdbStoreProvider {
public class BdbStoreProvider implements nl.knaw.huygens.timbuctoo.v5.dataset.StoreProvider {
private static final StringStringIsCleanHandler stringStringIsCleanHandler = new StringStringIsCleanHandler();
private static final TupleBinding<String> stringBinding = TupleBinding.getPrimitiveBinding(String.class);
private static final TupleBinding<Integer> integerBinding = TupleBinding.getPrimitiveBinding(Integer.class);
Expand All @@ -34,6 +34,7 @@ public BdbStoreProvider(String userId, String dataSetId, BdbEnvironmentCreator d
this.dataStoreFactory = dataStoreFactory;
}

@Override
public BdbTripleStore createTripleStore()
throws DataStoreCreationException {
try {
Expand All @@ -51,6 +52,7 @@ public BdbTripleStore createTripleStore()
}
}

@Override
public BdbTypeNameStore createTypeNameStore(String rdfPrefix)
throws DataStoreCreationException {
try {
Expand All @@ -71,6 +73,7 @@ public BdbTypeNameStore createTypeNameStore(String rdfPrefix)
}
}

@Override
public BdbSchemaStore createSchemaStore(ImportStatus importStatus)
throws DataStoreCreationException {
try {
Expand All @@ -91,6 +94,7 @@ public BdbSchemaStore createSchemaStore(ImportStatus importStatus)
}
}

@Override
public TruePatchStore createTruePatchStore() throws DataStoreCreationException {
try {
return new BdbTruePatchStore(
Expand All @@ -109,6 +113,7 @@ public TruePatchStore createTruePatchStore() throws DataStoreCreationException {
}
}

@Override
public UpdatedPerPatchStore createUpdatePerPatchStore()
throws DataStoreCreationException {
try {
Expand Down Expand Up @@ -138,6 +143,7 @@ public String getValue() {
}
}

@Override
public BdbRmlDataSourceStore createRmlDataSourceStore(ImportStatus importStatus)
throws DataStoreCreationException {
try {
Expand All @@ -159,6 +165,7 @@ public BdbRmlDataSourceStore createRmlDataSourceStore(ImportStatus importStatus)
}


@Override
public VersionStore createVersionStore() throws DataStoreCreationException {
try {
return new BdbVersionStore(dataStoreFactory.getDatabase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.google.common.collect.Maps;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbEnvironmentCreator;
import nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData;
import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet;
import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData;
Expand Down Expand Up @@ -59,7 +58,7 @@ public class DataSetRepository {
private final ExecutorService executorService;
private final PermissionFetcher permissionFetcher;
private final DataSetConfiguration configuration;
private final BdbEnvironmentCreator dataStoreFactory;
private final EnvironmentCreator dataStoreFactory;
private final Map<String, Map<String, DataSet>> dataSetMap;
private final Map<String, Set<DataSetMetaData>> metaDataSet;
private final TimbuctooRdfIdHelper rdfIdHelper;
Expand All @@ -71,7 +70,7 @@ public class DataSetRepository {


public DataSetRepository(ExecutorService executorService, PermissionFetcher permissionFetcher,
DataSetConfiguration configuration, BdbEnvironmentCreator dataStoreFactory,
DataSetConfiguration configuration, EnvironmentCreator dataStoreFactory,
TimbuctooRdfIdHelper rdfIdHelper, Consumer<String> onUpdated,
boolean publicByDefault) throws IOException {
this.executorService = executorService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package nl.knaw.huygens.timbuctoo.v5.dataset;

public interface EnvironmentCreator {
StoreProvider createStoreProvider(String userId,
String dataSetId);

/**
* Closes and remove all the databases for a data set
*/
void closeEnvironment(String ownerId, String dataSetId);

void start();

void stop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package nl.knaw.huygens.timbuctoo.v5.dataset;

import nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException;
import nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbRmlDataSourceStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbSchemaStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTripleStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTypeNameStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.rmldatasource.RmlDataSourceStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.truepatch.TruePatchStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.updatedperpatchstore.UpdatedPerPatchStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.versionstore.VersionStore;

public interface StoreProvider {
QuadStore createTripleStore()
throws DataStoreCreationException;

TypeNameStore createTypeNameStore(String rdfPrefix)
throws DataStoreCreationException;

SchemaStore createSchemaStore(ImportStatus importStatus)
throws DataStoreCreationException;

TruePatchStore createTruePatchStore() throws DataStoreCreationException;

UpdatedPerPatchStore createUpdatePerPatchStore()
throws DataStoreCreationException;

RmlDataSourceStore createRmlDataSourceStore(ImportStatus importStatus)
throws DataStoreCreationException;

VersionStore createVersionStore() throws DataStoreCreationException;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package nl.knaw.huygens.timbuctoo.v5.dataset.dto;

import com.google.common.collect.Lists;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbEnvironmentCreator;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbStoreProvider;
import nl.knaw.huygens.timbuctoo.v5.dataset.DataSetConfiguration;
import nl.knaw.huygens.timbuctoo.v5.dataset.EnvironmentCreator;
import nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager;
import nl.knaw.huygens.timbuctoo.v5.dataset.StoreProvider;
import nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException;
import nl.knaw.huygens.timbuctoo.v5.datastores.implementations.RdfDescriptionSaver;
import nl.knaw.huygens.timbuctoo.v5.datastores.storeupdater.StoreUpdater;
Expand Down Expand Up @@ -35,8 +35,8 @@ public abstract class DataSet {


public static DataSet dataSet(DataSetMetaData metadata, DataSetConfiguration configuration,
FileHelper fileHelper, ExecutorService executorService, String rdfPrefix,
BdbEnvironmentCreator dataStoreFactory, ResourceSync resourceSync, Runnable onUpdated)
FileHelper fileHelper, ExecutorService executorService, String rdfPrefix,
EnvironmentCreator dataStoreFactory, ResourceSync resourceSync, Runnable onUpdated)
throws IOException, DataStoreCreationException, ResourceSyncException {

String userId = metadata.getOwnerId();
Expand All @@ -54,7 +54,7 @@ public static DataSet dataSet(DataSetMetaData metadata, DataSetConfiguration con
onUpdated
);

BdbStoreProvider storeProvider = new BdbStoreProvider(userId, dataSetId, dataStoreFactory);
StoreProvider storeProvider = dataStoreFactory.createStoreProvider(userId, dataSetId);

try {
importManager.subscribeToRdf(new RdfDescriptionSaver(descriptionFile, metadata.getBaseUri(),
Expand Down Expand Up @@ -130,7 +130,7 @@ public void stop() {

protected abstract String getDataSetName();

protected abstract BdbEnvironmentCreator getBdbEnvironmentCreator();
protected abstract EnvironmentCreator getBdbEnvironmentCreator();

public abstract SchemaStore getSchemaStore();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import graphql.schema.GraphQLOutputType;
import graphql.schema.GraphQLSchema;
import graphql.schema.GraphQLType;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbEnvironmentCreator;
import nl.knaw.huygens.timbuctoo.v5.dataset.EnvironmentCreator;
import nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager;
import nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData;
import nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet;
Expand All @@ -19,7 +19,6 @@
import nl.knaw.huygens.timbuctoo.v5.datastores.prefixstore.TypeNameStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore;
import nl.knaw.huygens.timbuctoo.v5.datastores.schemastore.SchemaStore;
import nl.knaw.huygens.timbuctoo.v5.filestorage.FileStorage;
import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.DatabaseResult;
import nl.knaw.huygens.timbuctoo.v5.graphql.datafetchers.dto.SubjectReference;
import nl.knaw.huygens.timbuctoo.v5.rml.RdfDataSourceFactory;
Expand Down Expand Up @@ -157,7 +156,7 @@ protected String getDataSetName() {
}

@Override
protected BdbEnvironmentCreator getBdbEnvironmentCreator() {
protected EnvironmentCreator getBdbEnvironmentCreator() {
throw new UnsupportedOperationException("Not yet implemented");//FIXME: implement
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import com.sleepycat.je.Environment;
import com.sleepycat.je.EnvironmentConfig;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbEnvironmentCreator;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbStoreProvider;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbWrapper;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException;
import nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler;
import nl.knaw.huygens.timbuctoo.v5.dataset.StoreProvider;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;

Expand Down Expand Up @@ -42,6 +44,11 @@ public BdbNonPersistentEnvironmentCreator() {
environmentMap = Maps.newHashMap();
}

@Override
public StoreProvider createStoreProvider(String userId, String dataSetId) {
return new BdbStoreProvider(userId, dataSetId, this);
}

@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName,
boolean allowDuplicates, EntryBinding<KeyT> keyBinder,
Expand Down

0 comments on commit 1f6901b

Please sign in to comment.