Search in sources :

Example 1 with BdbTripleStore

use of nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTripleStore in project timbuctoo by HuygensING.

the class BdbTripleStoreTest method makeCollection.

@Before
public void makeCollection() throws Exception {
    databaseCreator = new BdbNonPersistentEnvironmentCreator();
    tripleStore = new BdbTripleStore(databaseCreator.getDatabase("userId", "dataSetId", "rdfData", true, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler()));
    // to make the test work on slow systems
    Thread.sleep(2000);
}
Also used : StringStringIsCleanHandler(nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler) BdbTripleStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTripleStore) BdbNonPersistentEnvironmentCreator(nl.knaw.huygens.timbuctoo.v5.dropwizard.BdbNonPersistentEnvironmentCreator) Before(org.junit.Before)

Example 2 with BdbTripleStore

use of nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTripleStore in project timbuctoo by HuygensING.

the class DataSet method dataSet.

public static DataSet dataSet(DataSetMetaData metadata, ExecutorService executorService, String rdfPrefix, BdbEnvironmentCreator dataStoreFactory, Runnable onUpdated, DataSetStorage dataSetStorage) throws IOException, DataStoreCreationException {
    String userId = metadata.getOwnerId();
    String dataSetId = metadata.getDataSetId();
    File descriptionFile = dataSetStorage.getResourceSyncDescriptionFile();
    FileStorage fileStorage = dataSetStorage.getFileStorage();
    ImportManager importManager = new ImportManager(dataSetStorage.getLogList(), fileStorage, fileStorage, dataSetStorage.getLogStorage(), executorService, dataSetStorage.getRdfIo(), onUpdated);
    try {
        importManager.subscribeToRdf(new RdfDescriptionSaver(descriptionFile, metadata.getBaseUri(), importManager.getImportStatus()));
    } catch (ParserConfigurationException | SAXException e) {
        LOG.error("Could not construct import manager of data set", e);
    }
    final TupleBinding<String> stringBinding = TupleBinding.getPrimitiveBinding(String.class);
    try {
        StringStringIsCleanHandler stringStringIsCleanHandler = new StringStringIsCleanHandler();
        BdbTripleStore quadStore = new BdbTripleStore(dataStoreFactory.getDatabase(userId, dataSetId, "rdfData", true, stringBinding, stringBinding, stringStringIsCleanHandler));
        final BdbTypeNameStore typeNameStore = new BdbTypeNameStore(new BdbBackedData(dataStoreFactory.getDatabase(userId, dataSetId, "typenames", false, stringBinding, stringBinding, stringStringIsCleanHandler)), rdfPrefix);
        final BdbSchemaStore schema = new BdbSchemaStore(new BdbBackedData(dataStoreFactory.getDatabase(userId, dataSetId, "schema", false, stringBinding, stringBinding, stringStringIsCleanHandler)), importManager.getImportStatus());
        final BdbTruePatchStore truePatchStore = new BdbTruePatchStore(dataStoreFactory.getDatabase(userId, dataSetId, "truePatch", true, stringBinding, stringBinding, stringStringIsCleanHandler));
        final TupleBinding<Integer> integerBinding = TupleBinding.getPrimitiveBinding(Integer.class);
        final UpdatedPerPatchStore updatedPerPatchStore = new UpdatedPerPatchStore(dataStoreFactory.getDatabase(userId, dataSetId, "updatedPerPatch", true, integerBinding, stringBinding, new IsCleanHandler<Integer, String>() {

            @Override
            public Integer getKey() {
                return Integer.MAX_VALUE;
            }

            @Override
            public String getValue() {
                return "isClean";
            }
        }));
        final BdbRmlDataSourceStore rmlDataSourceStore = new BdbRmlDataSourceStore(dataStoreFactory.getDatabase(userId, dataSetId, "rmlSource", true, stringBinding, stringBinding, stringStringIsCleanHandler), importManager.getImportStatus());
        VersionStore versionStore = new VersionStore(dataStoreFactory.getDatabase(userId, dataSetId, "versions", false, stringBinding, integerBinding, new IsCleanHandler<String, Integer>() {

            @Override
            public String getKey() {
                return "isClean";
            }

            @Override
            public Integer getValue() {
                return Integer.MAX_VALUE;
            }
        }));
        final StoreUpdater storeUpdater = new StoreUpdater(dataStoreFactory, quadStore, typeNameStore, truePatchStore, updatedPerPatchStore, Lists.newArrayList(schema, rmlDataSourceStore), versionStore, importManager.getImportStatus());
        importManager.subscribeToRdf(storeUpdater);
        ImmutableDataSet dataSet = ImmutableDataSet.builder().ownerId(userId).dataSetName(dataSetId).bdbEnvironmentCreator(dataStoreFactory).metadata(metadata).quadStore(quadStore).typeNameStore(typeNameStore).schemaStore(schema).dataSource(new RdfDataSourceFactory(rmlDataSourceStore)).schemaStore(schema).importManager(importManager).dataSetStorage(dataSetStorage).build();
        importManager.init(dataSet);
        if (!quadStore.isClean() || !typeNameStore.isClean() || !schema.isClean() || !truePatchStore.isClean() || !updatedPerPatchStore.isClean() || !rmlDataSourceStore.isClean() || !versionStore.isClean()) {
            LOG.error("Data set '{}__{}' data is corrupted, starting to reimport.", userId, dataSetId);
            quadStore.empty();
            typeNameStore.empty();
            schema.empty();
            truePatchStore.empty();
            updatedPerPatchStore.empty();
            rmlDataSourceStore.empty();
            versionStore.empty();
            importManager.reprocessLogs();
        } else {
            // process unprocessed logs
            importManager.processLogs();
        }
        return dataSet;
    } catch (BdbDbCreationException e) {
        throw new DataStoreCreationException(e.getCause());
    }
}
Also used : ImportManager(nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager) BdbSchemaStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbSchemaStore) BdbTruePatchStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTruePatchStore) SAXException(org.xml.sax.SAXException) VersionStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.VersionStore) BdbBackedData(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbBackedData) BdbTypeNameStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTypeNameStore) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) UpdatedPerPatchStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.UpdatedPerPatchStore) StringStringIsCleanHandler(nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler) RdfDescriptionSaver(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.RdfDescriptionSaver) BdbRmlDataSourceStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbRmlDataSourceStore) StoreUpdater(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.StoreUpdater) IsCleanHandler(nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler) StringStringIsCleanHandler(nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler) BdbDbCreationException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException) BdbTripleStore(nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTripleStore) FileStorage(nl.knaw.huygens.timbuctoo.v5.filestorage.FileStorage) RdfDataSourceFactory(nl.knaw.huygens.timbuctoo.v5.rml.RdfDataSourceFactory) DataStoreCreationException(nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException) File(java.io.File)

Example 3 with BdbTripleStore

use of nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTripleStore in project timbuctoo by HuygensING.

the class ChangeFetcherImplTest method showsAdditions.

@Test
public void showsAdditions() throws Exception {
    final BdbNonPersistentEnvironmentCreator databaseCreator = new BdbNonPersistentEnvironmentCreator();
    final BdbTripleStore bdbTripleStore = new BdbTripleStore(databaseCreator.getDatabase("a", "b", "rdfData", true, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler()));
    final BdbTruePatchStore truePatchStore = new BdbTruePatchStore(databaseCreator.getDatabase("a", "b", "truePatch", true, TupleBinding.getPrimitiveBinding(String.class), TupleBinding.getPrimitiveBinding(String.class), new StringStringIsCleanHandler()));
    bdbTripleStore.putQuad("subj", "pred", OUT, "obj", null, null);
    truePatchStore.put("subj", 0, "pred", OUT, true, "obj", null, null);
    ChangeFetcherImpl changeFetcher = new ChangeFetcherImpl(truePatchStore, bdbTripleStore, 0);
    try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, false, false, true)) {
        assertThat(predicates.count(), is(1L));
    }
    try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, true, true)) {
        assertThat(predicates.count(), is(1L));
    }
    try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, false, true)) {
        assertThat(predicates.count(), is(1L));
    }
    bdbTripleStore.putQuad("subj", "pred", OUT, "obj2", null, null);
    truePatchStore.put("subj", 1, "pred", OUT, true, "obj2", null, null);
    changeFetcher = new ChangeFetcherImpl(truePatchStore, bdbTripleStore, 1);
    try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, false, false, true)) {
        assertThat(predicates.count(), is(1L));
    }
    try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, true, true)) {
        assertThat(predicates.count(), is(2L));
    }
    try (Stream<CursorQuad> predicates = changeFetcher.getPredicates("subj", "pred", OUT, true, false, true)) {
        assertThat(predicates.count(), is(1L));
    }
}
Also used : StringStringIsCleanHandler(nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler) CursorQuad(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad) BdbNonPersistentEnvironmentCreator(nl.knaw.huygens.timbuctoo.v5.dropwizard.BdbNonPersistentEnvironmentCreator) Test(org.junit.Test)

Aggregations

StringStringIsCleanHandler (nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler)3 BdbTripleStore (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTripleStore)2 BdbNonPersistentEnvironmentCreator (nl.knaw.huygens.timbuctoo.v5.dropwizard.BdbNonPersistentEnvironmentCreator)2 File (java.io.File)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BdbDbCreationException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException)1 IsCleanHandler (nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.IsCleanHandler)1 ImportManager (nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager)1 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)1 RdfDescriptionSaver (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.RdfDescriptionSaver)1 BdbBackedData (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbBackedData)1 BdbRmlDataSourceStore (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbRmlDataSourceStore)1 BdbSchemaStore (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbSchemaStore)1 BdbTruePatchStore (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTruePatchStore)1 BdbTypeNameStore (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.BdbTypeNameStore)1 StoreUpdater (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.StoreUpdater)1 UpdatedPerPatchStore (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.UpdatedPerPatchStore)1 VersionStore (nl.knaw.huygens.timbuctoo.v5.datastores.implementations.bdb.VersionStore)1 CursorQuad (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.dto.CursorQuad)1 FileStorage (nl.knaw.huygens.timbuctoo.v5.filestorage.FileStorage)1