You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2015/03/22 23:04:53 UTC
[10/14] clerezza git commit: CLEREZZA-966: moved jena.tdb.storage
into the hierarchy
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
deleted file mode 100644
index ac0dc89..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedSingleTdbDatasetTest.java
+++ /dev/null
@@ -1,261 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.Set;
-
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.osgi.service.cm.ConfigurationException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.wymiwyg.commons.util.Util;
-
-
-public class MultiThreadedSingleTdbDatasetTest {
-
- private Logger log = LoggerFactory.getLogger(MultiThreadedSingleTdbDatasetTest.class);
-
- private static final String TEST_GRAPH_URI_PREFIX = "http://www.example.org/multiThreadTest";
- private int[] graphNum = new int[]{0};
- /**
- * how many threads to start
- */
- private static final int TEST_THREAD_COUNT = 25;
- private static final int VALIDATE_THREAD_COUNT = 2;
- /**
- * how many seconds to let them run
- */
- private static final int DELAY = 15;
-
-
- protected final List<MGraph> mGraphs = new ArrayList<MGraph>();
- protected final List<Set<Triple>> testTriplesList = new ArrayList<Set<Triple>>();
- private Random random = new Random();
-
- class TestThread extends Thread {
-
- private boolean stopRequested;
- private int addedTripleCount = 0;
-
- public TestThread(final int id) {
- setName("Test Thread "+id);
- start();
- }
-
- public void requestStop() {
- stopRequested = true;
- }
-
- @Override
- public void run() {
- while (!stopRequested) {
- float r;
- synchronized (random) {
- r = random.nextFloat();
- }
- MGraph graph;
- Set<Triple> testTriples;
- if(r > 0.995){
- int num;
- synchronized (graphNum) {
- num = graphNum[0];
- graphNum[0]++;
- }
- graph = provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+num));
- log.info(" ... creating the {}. Grpah", num+1);
- testTriples = new HashSet<Triple>();
- synchronized (mGraphs) {
- mGraphs.add(graph);
- testTriplesList.add(testTriples);
- }
- } else { //map the range [0..0.995] to the mGraphs
- synchronized (mGraphs) {
- int num = Math.round(r*(float)(mGraphs.size()-1)/0.995f);
- graph = mGraphs.get(num);
- testTriples = testTriplesList.get(num);
- }
- }
- Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
- Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
- graph.add(triple);
- addedTripleCount++;
- if ((addedTripleCount % 100) == 0) {
- testTriples.add(triple);
- }
- }
- }
-
- public int getAddedTripleCount() {
- return addedTripleCount;
- }
-
- }
- /**
- * Iterates over max. the first 10 triples of a Graph
- * while acquiring a read lock on the graph.
- * @author westei
- *
- */
- class ValidatorThread extends Thread {
-
- boolean stopRequested = false;
-
- public ValidatorThread(int id) {
- setName("Validator Thread "+id);
- start();
- }
-
- public void requestStop() {
- stopRequested = true;
- }
-
- @Override
- public void run() {
- while (!stopRequested) {
- float r;
- synchronized (random) {
- r = random.nextFloat();
- }
- int num = Math.round(r*(float)(mGraphs.size()-1));
- LockableMGraph graph;
- synchronized (mGraphs) {
- graph = (LockableMGraph)mGraphs.get(num);
- }
- int elem = 0;
- graph.getLock().readLock().lock();
- try {
- Iterator<Triple> it = graph.iterator();
- while(it.hasNext() && elem < 10){
- elem++;
- it.next();
- }
- } finally {
- graph.getLock().readLock().unlock();
- }
- //iterate inly every 200ms
- try {
- Thread.sleep(200);
- } catch (InterruptedException e) {
- //ignore
- }
- }
- }
-
-
-
- }
-
-
-
- private static File tempFile;
- private static Dictionary<String,Object> config;
- private static SingleTdbDatasetTcProvider provider;
- @BeforeClass
- public static void setup() throws IOException, ConfigurationException {
- tempFile = File.createTempFile("tdbdatasettest", null);
- tempFile.delete();
- tempFile.mkdirs();
- config = new Hashtable<String,Object>();
- config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
- provider = new SingleTdbDatasetTcProvider(config);
- }
- @Before
- public void createGraphs(){
- mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
- testTriplesList.add(new HashSet<Triple>());
- graphNum[0]++;
- mGraphs.add(provider.createMGraph(new UriRef(TEST_GRAPH_URI_PREFIX+graphNum[0])));
- testTriplesList.add(new HashSet<Triple>());
- graphNum[0]++;
- }
- @Test
- public void perform() throws InterruptedException {
- TestThread[] threads = new TestThread[TEST_THREAD_COUNT];
- for (int i = 0; i < threads.length; i++) {
- threads[i] = new TestThread(i);
- }
- ValidatorThread[] validators = new ValidatorThread[VALIDATE_THREAD_COUNT];
- for(int i = 0; i < validators.length; i++) {
- validators [i] = new ValidatorThread(i);
- }
- Thread.sleep(DELAY*1000);
- for (TestThread testThread : threads) {
- testThread.requestStop();
- }
- for (ValidatorThread validator : validators) {
- validator.requestStop();
- }
- for (TestThread testThread : threads) {
- testThread.join();
- }
- for (ValidatorThread validator : validators) {
- validator.join();
- }
- int addedTriples = 0;
- for (TestThread testThread : threads) {
- addedTriples += testThread.getAddedTripleCount();
- }
- int graphTriples = 0;
- log.info("Test created {} graphs with {} triples", mGraphs.size(), addedTriples);
- for(int i = 0;i < mGraphs.size(); i++){
- MGraph graph = mGraphs.get(i);
- graphTriples += graph.size();
- log.info(" > Grpah {}: {} triples",i,graph.size());
- for (Triple testTriple : testTriplesList.get(i)) {
- Assert.assertTrue(graph.contains(testTriple));
- }
- }
- Assert.assertEquals(addedTriples, graphTriples);
- }
- @AfterClass
- public static void cleanUpDirectory() throws IOException {
- provider.deactivate(null);
- try {
- TdbTcProvider.delete(tempFile);
- } catch (IOException e) {
- System.err.println("Failed removing tempfile "+tempFile);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
deleted file mode 100644
index 91791c3..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.felix.scr.annotations.Activate;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.wymiwyg.commons.util.Util;
-
-
-public class MultiThreadedTest {
-
-
-
- /**
- * how many threads to start
- */
- private static final int THREAD_COUNT = 200;
- /**
- * how many seconds to let them run
- */
- private static final int DELAY = 15;
-
-
- private MGraph mGraph;
- private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>());
-
- class TestThread extends Thread {
-
- private final int id;
- private boolean stopRequested;
- private int addedTripleCount = 0;
- private Object exception;
-
- public TestThread(final int id) {
- this.id = id;
- start();
- }
-
- public void requestStop() {
- stopRequested = true;
- }
-
- @Override
- public void run() {
- while (!stopRequested) {
- try {
- Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
- Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
- mGraph.add(triple);
- addedTripleCount++;
- if ((addedTripleCount % 100) == 0) {
- testTriples.add(triple);
- }
- } catch (Exception e) {
- exception = e;
- }
- }
- }
-
- public int getAddedTripleCount() {
- return addedTripleCount;
- }
-
- }
-
-
-
- @Before
- public void setUp() throws IOException {
- File tempFile;
- UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
- TdbTcProvider tdbTcProvider;
- tempFile = File.createTempFile("tdbtest", null);
- tempFile.delete();
- tempFile.mkdirs();
- tdbTcProvider = new TdbTcProvider(tempFile);
- tdbTcProvider.activate(null);
- mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
- }
-
- @Test
- public void perform() throws InterruptedException {
- TestThread[] threads = new TestThread[THREAD_COUNT];
- for (int i = 0; i < threads.length; i++) {
- threads[i] = new TestThread(i);
- }
- Thread.sleep(DELAY*1000);
- for (TestThread testThread : threads) {
- testThread.requestStop();
- }
- for (TestThread testThread : threads) {
- testThread.join();
- }
- int addedTriples = 0;
- for (TestThread testThread : threads) {
- addedTriples += testThread.getAddedTripleCount();
- }
- Assert.assertEquals(addedTriples, mGraph.size());
- for (Triple testTriple : testTriples) {
- Assert.assertTrue(mGraph.contains(testTriple));
- }
- for (TestThread testThread : threads) {
- Assert.assertNull(testThread.exception);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
deleted file mode 100644
index 76505b3..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/MultiThreadedTestSingleTdb.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Set;
-
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Literal;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.felix.scr.annotations.Activate;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.service.cm.ConfigurationException;
-import org.wymiwyg.commons.util.Util;
-
-
-public class MultiThreadedTestSingleTdb {
-
-
-
- /**
- * how many threads to start
- */
- private static final int THREAD_COUNT = 100;
- /**
- * how many seconds to let them run
- */
- private static final int DELAY = 15;
-
-
- private MGraph mGraph;
- private Set<Triple> testTriples = Collections.synchronizedSet(new HashSet<Triple>());
-
- class TestThread extends Thread {
-
- private final int id;
- private boolean stopRequested;
- private int addedTripleCount = 0;
- private Object exception;
-
- public TestThread(final int id) {
- this.id = id;
- start();
- }
-
- public void requestStop() {
- stopRequested = true;
- }
-
- @Override
- public void run() {
- while (!stopRequested) {
- try {
- Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
- Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
- mGraph.add(triple);
- addedTripleCount++;
- if ((addedTripleCount % 100) == 0) {
- testTriples.add(triple);
- }
- } catch (Exception e) {
- exception = e;
- }
- }
- }
-
- public int getAddedTripleCount() {
- return addedTripleCount;
- }
-
- }
-
-
-
- @Before
- public void setUp() throws IOException, ConfigurationException {
- File tempFile;
- UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
- TcProvider tdbTcProvider;
- tempFile = File.createTempFile("tdbtest", null);
- tempFile.delete();
- tempFile.mkdirs();
- Dictionary<String, Object> dict = new Hashtable<String, Object>();
- dict.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
- tdbTcProvider = new SingleTdbDatasetTcProvider(dict);
- //tdbTcProvider.activate(null);
- mGraph = tdbTcProvider.createMGraph(MGRAPHNAME);
- }
-
- @Test
- public void perform() throws InterruptedException {
- TestThread[] threads = new TestThread[THREAD_COUNT];
- for (int i = 0; i < threads.length; i++) {
- threads[i] = new TestThread(i);
- }
- Thread.sleep(DELAY*1000);
- for (TestThread testThread : threads) {
- testThread.requestStop();
- }
- for (TestThread testThread : threads) {
- testThread.join();
- }
- int addedTriples = 0;
- for (TestThread testThread : threads) {
- addedTriples += testThread.getAddedTripleCount();
- }
- Assert.assertEquals(addedTriples, mGraph.size());
- for (Triple testTriple : testTriples) {
- Assert.assertTrue(mGraph.contains(testTriple));
- }
- for (TestThread testThread : threads) {
- Assert.assertNull(testThread.exception);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
deleted file mode 100644
index cc3741b..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetMGraphTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.test.MGraphTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.osgi.service.cm.ConfigurationException;
-
-public class SingleTdbDatasetMGraphTest extends MGraphTest {
-
- private static final String MGRAPHNAME_PREFIX = "http://text.example.org/testGraph";
- private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
- private static int testGraphCounter = 0;
-
- private static File tempFile;
- private static Dictionary<String,Object> config;
- private static SingleTdbDatasetTcProvider provider;
-
- @BeforeClass
- public static void setup() throws IOException, ConfigurationException {
- tempFile = File.createTempFile("tdbdatasettest", null);
- tempFile.delete();
- tempFile.mkdirs();
- config = new Hashtable<String,Object>();
- config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
- config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
- provider = new SingleTdbDatasetTcProvider(config);
- }
-
- @AfterClass
- public static void cleanUpDirectory() throws IOException {
- for(int i = 0; i < testGraphCounter;i++){
- provider.deleteTripleCollection(new UriRef(MGRAPHNAME_PREFIX+i));
- }
- provider.deactivate(null);
- try {
- TdbTcProvider.delete(tempFile);
- } catch (IOException e) {
- System.err.println("Couldn't remove "+tempFile);
- }
- }
-
- @Override
- protected MGraph getEmptyMGraph() {
- MGraph graph = provider.createMGraph(new UriRef(MGRAPHNAME_PREFIX+testGraphCounter));
- testGraphCounter++;
- return graph;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
deleted file mode 100644
index b3849dd..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProviderTest.java
+++ /dev/null
@@ -1,168 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.test.TcProviderTest;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.service.cm.ConfigurationException;
-
-public class SingleTdbDatasetTcProviderTest extends TcProviderTest {
-
- private static File tempFile;
- private static Dictionary<String,Object> config;
- private static SingleTdbDatasetTcProvider provider;
- private static UriRef UNION_GRAPH_NAME = new UriRef("http://www.example.org/unionGraph");
-
- @Before
- public void setup() throws IOException, ConfigurationException {
- tempFile = File.createTempFile("tdbdatasettest", null);
- tempFile.delete();
- tempFile.mkdirs();
- config = new Hashtable<String,Object>();
- config.put(SingleTdbDatasetTcProvider.TDB_DIR, tempFile.getAbsolutePath());
- config.put(SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME, UNION_GRAPH_NAME.getUnicodeString());
- //config.put(SingleTdbDatasetTcProvider.USE_GRAPH_NAME_SUFFIXES, true);
- }
-
- @Override
- protected TcProvider getInstance() {
- //tests want us to deactivate/activate the TcProvider on multiple calls
- //to getInstance within the same test
- if(provider !=null){
- try {
- provider.deactivate(null);
- provider = null;
- } catch (Exception e) {
- System.err.println("Error cleaning up: "+e.getMessage());
- }
- }
- try {
- provider = new SingleTdbDatasetTcProvider(config);
- } catch (Exception e) {
- throw new RuntimeException("forwarding ...",e);
- }
- return provider;
- }
-
- @After
- public void cleanData() throws IOException{
- //We need to remove all remaining data after a test
- if(provider != null){
- try {
- provider.deactivate(null);
- TdbTcProvider.delete(tempFile);
- provider = null;
- } catch (Exception e) {
- System.err.println("Error cleaning up: "+e.getMessage());
- }
- }
- }
-
- /**
- * The union graph is read only!
- */
- @Test(expected=NoSuchEntityException.class)
- public void testUnionMgraph(){
- TcProvider provider = getInstance();
- provider.getMGraph(UNION_GRAPH_NAME);
- }
-
- /**
- * Assert union graph on an empty dataset
- */
- @Test
- public void testEmptyUnionGraph(){
- TcProvider provider = getInstance();
- Graph graph = provider.getGraph(UNION_GRAPH_NAME);
- Assert.assertNotNull(graph);
- }
-
- @Test
- public void testUnionGraph() throws Exception{
- TcProvider provider = getInstance();
- UriRef type = new UriRef("http://www.w3.org/2000/01/rdf-schema#type");
- UriRef name = new UriRef("http://schema.org/name");
- UriRef personType = new UriRef("http://schema.org/Person");
- UriRef companyType = new UriRef("http://schema.org/Company");
- UriRef worksFor = new UriRef("http://schema.org/works-for");
-
- //create a graph with persons
- MGraph persons = new SimpleMGraph();
- UriRef tim = new UriRef("http://people.org/tim.johnson");
- persons.add(new TripleImpl(tim, type, personType));
- persons.add(new TripleImpl(tim, name, new PlainLiteralImpl("Tim Johnson")));
- UriRef john = new UriRef("http://people.org/john.swenson");
- persons.add(new TripleImpl(john, type, personType));
- persons.add(new TripleImpl(john, name, new PlainLiteralImpl("John Swenson")));
- provider.createGraph(new UriRef("urn:persons"), persons.getGraph());
-
- //create a MGraph with data about persons
- MGraph orgdata = provider.createMGraph(new UriRef("urn:orgdata"));
- UriRef talinor = new UriRef("http://company.org/talinor");
- orgdata.add(new TripleImpl(talinor, type, companyType));
- orgdata.add(new TripleImpl(talinor, name, new PlainLiteralImpl("Talinor Inc.")));
- orgdata.add(new TripleImpl(john, worksFor, talinor));
- UriRef kondalor = new UriRef("http://company.org/kondalor");
- orgdata.add(new TripleImpl(kondalor, type, companyType));
- orgdata.add(new TripleImpl(kondalor, name, new PlainLiteralImpl("Kondalor Ges.m.b.H.")));
- orgdata.add(new TripleImpl(tim, worksFor, kondalor));
-
- //now get the union graph
- Graph data = provider.getGraph(UNION_GRAPH_NAME);
- Assert.assertNotNull(data);
- //CLEREZZA-714: getTriples need to correctly return the UnionGraph
- data = (Graph)provider.getTriples(UNION_GRAPH_NAME);
- Assert.assertNotNull(data);
- //NOTE: Jena TDB does not support getSize for the union graph
-// int expectedTripleCount = persons.size()+orgdata.size();
-// Assert.assertEquals("Uniongraph has "+data.size()
-// +" triples (expected "+expectedTripleCount+")",
-// expectedTripleCount, data.size());
- Iterator<Triple> it = data.filter(null, type, companyType);
- Set<UriRef> expected = new HashSet<UriRef>(Arrays.asList(talinor,kondalor));
- while(it.hasNext()){
- NonLiteral subject = it.next().getSubject();
- Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
- }
- Assert.assertTrue("Missing "+expected, expected.isEmpty());
-
- it = data.filter(null, type, personType);
- expected = new HashSet<UriRef>(Arrays.asList(john,tim));
- while(it.hasNext()){
- NonLiteral subject = it.next().getSubject();
- Assert.assertTrue("Unexpected "+subject, expected.remove(subject));
- }
- Assert.assertTrue("Missing "+expected, expected.isEmpty());
- }
-
- @Test
- public void testListGraph(){
- TcProvider provider = getInstance();
- //No union graph in listMGraphs
- Set<UriRef> mgl = provider.listMGraphs();
- Assert.assertFalse("Mgraph list don't contain the read-only union-graph", mgl.contains(UNION_GRAPH_NAME));
- //Union graph in listGraphs
- Set<UriRef> gl = provider.listGraphs();
- Assert.assertTrue("Graph list contain the read-only union-graph", gl.contains(UNION_GRAPH_NAME));
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
deleted file mode 100644
index e09c0e4..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbMGraphTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.Iterator;
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.TypedLiteral;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.test.MGraphTest;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class TdbMGraphTest extends MGraphTest {
- private static File tempFile;
- final private UriRef MGRAPHNAME = new UriRef("http://text.example.org/");
- static private TdbTcProvider tdbTcProvider;
-
- @BeforeClass
- public static void setupDirectory() throws IOException {
- tempFile = File.createTempFile("tdbtest", null);
- tempFile.delete();
- tempFile.mkdirs();
- tdbTcProvider = new TdbTcProvider(tempFile);
- }
-
- @AfterClass
- public static void cleanUpDirectory() throws IOException {
- try {
- TdbTcProvider.delete(tempFile);
- } catch (IOException e) {
- System.err.println("failed to delete temp directory: "+tempFile);
- }
- }
-
- @After
- public void cleanUpGraph() {
- tdbTcProvider.deleteTripleCollection(MGRAPHNAME);
- }
-
- @Override
- protected MGraph getEmptyMGraph() {
- return tdbTcProvider.createMGraph(MGRAPHNAME);
- }
-
- @Test
- public void dateStorage() {
- MGraph graph = getEmptyMGraph();
- Date date = new Date(0);
- LiteralFactory literalFactory = LiteralFactory.getInstance();
- TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
- Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), dateLiteral);
- graph.add(triple);
- Assert.assertTrue(graph.contains(triple));
- }
-
- @Test
- public void dateStorage2() {
- MGraph graph = getEmptyMGraph();
- Date date = new Date(0);
- LiteralFactory literalFactory = LiteralFactory.getInstance();
- TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
- System.out.println(dateLiteral);
- UriRef property = new UriRef("http://example.com/property");
- Triple triple = new TripleImpl(new BNode(), property, dateLiteral);
- graph.add(triple);
-
- Triple tripleFromGraph = null;
- Iterator<Triple> propertyTriples = graph.filter(null, property, dateLiteral);
- if (propertyTriples.hasNext()) {
- tripleFromGraph = propertyTriples.next();
- } else {
- Assert.assertTrue(false);
- }
- Assert.assertEquals(dateLiteral, tripleFromGraph.getObject());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java b/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
deleted file mode 100644
index 2964385..0000000
--- a/rdf.jena.tdb.storage/src/test/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProviderTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-
-
-import org.junit.After;
-import org.junit.Before;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.test.TcProviderTest;
-
-/**
- *
- * @author mir
- */
-public class TdbTcProviderTest extends TcProviderTest {
-
- private File tempFile;
- private TdbTcProvider lastInstance;
-
- @Before
- public void setupDirectory() throws IOException {
- tempFile = File.createTempFile("tdbtest", null);
- tempFile.delete();
- tempFile.mkdirs();
- }
-
- @After
- public void cleanUp() throws IOException {
- TdbTcProvider.delete(tempFile);
- }
-
-
- @Override
- protected TcProvider getInstance() {
- if (lastInstance != null) {
- lastInstance.deactivate(null);
- }
- lastInstance = new TdbTcProvider(tempFile);
- lastInstance.activate(null);
- return lastInstance;
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/pom.xml b/rdf/jena/pom.xml
index cac069e..54b054b 100644
--- a/rdf/jena/pom.xml
+++ b/rdf/jena/pom.xml
@@ -47,8 +47,9 @@
<module>facade</module>
<module>parser</module>
<module>serializer</module>
- <module>storage</module>
<module>sparql</module>
+ <module>storage</module>
+ <module>tdb.storage</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/LICENSE
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/LICENSE b/rdf/jena/tdb.storage/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/rdf/jena/tdb.storage/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/pom.xml
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/pom.xml b/rdf/jena/tdb.storage/pom.xml
new file mode 100644
index 0000000..9306ee3
--- /dev/null
+++ b/rdf/jena/tdb.storage/pom.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>clerezza</artifactId>
+ <groupId>org.apache.clerezza</groupId>
+ <version>0.5</version>
+ <relativePath>../parent</relativePath>
+ </parent>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.tdb.storage</artifactId>
+ <packaging>bundle</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Clerezza - SCB Jena TDB Storage Provider</name>
+ <description>A Jena TDB based storage provider</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core</artifactId>
+ <version>0.14</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.ontologies</artifactId>
+ <version>0.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.commons</artifactId>
+ <version>0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.storage</artifactId>
+ <version>0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.jena.sparql</artifactId>
+ <version>0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-tdb</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>14.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
+ <artifactId>rdf.core.test</artifactId>
+ <scope>test</scope>
+ <version>0.15</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
new file mode 100644
index 0000000..a3cdd19
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
@@ -0,0 +1,46 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
+import org.apache.clerezza.rdf.core.event.FilterTriple;
+import org.apache.clerezza.rdf.core.event.GraphListener;
+import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
+
+/**
+ * {@link LockableMGraph} wrapper that uses a single {@link ReadWriteLock} for
+ * the Jena TDB {@link SingleTdbDatasetTcProvider#dataset}
+ * @author Rupert Westenthaler
+ *
+ */
+public class DatasetLockedMGraph extends LockableMGraphWrapper {
+
+
+ /**
+ * Constructs a LocalbleMGraph for an MGraph.
+ *
+ * @param providedMGraph a non-lockable mgraph
+ */
+ public DatasetLockedMGraph(final ReadWriteLock lock, final MGraph providedMGraph) {
+ super(providedMGraph, lock);
+ }
+
+ //Maybe overwriting this prevents unnecessary locking
+ /*
+ @Override
+ public Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object) {
+ //users will need to aquire a readlock while iterating
+ return wrapped.filter(subject, predicate, object);
+ }
+ */
+
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
new file mode 100644
index 0000000..7b6421f
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
@@ -0,0 +1,149 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import java.util.concurrent.locks.ReadWriteLock;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
+import org.apache.clerezza.rdf.core.impl.SimpleGraph;
+import org.apache.clerezza.rdf.core.impl.util.PrivilegedGraphWrapper;
+import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
+import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
+import org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.sparql.core.DatasetGraph;
+import com.hp.hpl.jena.sparql.core.Quad;
+import com.hp.hpl.jena.tdb.TDB;
+
+/**
+ * Represents the Jena {@link Model} and the Clerezza {@link Graph} or
+ * {@link MGraph}. It also provide access to the {@link JenaGraphAdaptor}
+ * so that this component can add parsed data to {@link Graph}s created
+ * by calls to {@link SingleTdbDatasetTcProvider#createGraph(UriRef, TripleCollection)}.
+ * @author Rupert Westenthaler
+ *
+ */
+public class ModelGraph {
+ /**
+ * The Jena Model
+ */
+ private final Model model;
+ /**
+ * The JenaGraphAdapter. Note that in case of read-only in anonymous
+ * subclass is used that prevents the creation of an in-memory copy
+ * of the data when calling {@link JenaGraphAdaptor#getGraph()}.
+ */
+ private JenaGraphAdaptor jenaAdapter;
+ /**
+ * The {@link Graph}(in case of read-only) or {@link MGraph} (if read/write)
+ * that can be shared with other components. The instance stored by this
+ * variable will use all the required Wrappers such as such as
+ * {@link LockableMGraphWrapper lockable} and {@link PrivilegedMGraphWrapper
+ * privileged}.
+ */
+ private TripleCollection graph;
+ /**
+ * keeps the state if this represents an {@link Graph} (read-only) or
+ * {@link MGraph}(read/write) ModelGraph.
+ */
+ private final boolean readWrite;
+
+ /**
+ * Constructs and initializes the ModelGraph
+ * @param model the Jena Model
+ * @param readWrite if the Clerezza counterpart should be read- and
+ * write-able or read-only.
+ */
+ public ModelGraph(final ReadWriteLock lock, Model model, boolean readWrite){
+ if(model == null){
+ throw new IllegalArgumentException("The parsed Model MUST NOT be NULL");
+ }
+ this.model = model;
+ this.readWrite = readWrite;
+ if(!readWrite){ //construct an graph
+ jenaAdapter = new JenaGraphAdaptor(model.getGraph()){
+ /**
+ * Ensure that no in-memory copies are created for read only
+ * Jena Graphs
+ * @return
+ */
+ @Override
+ public Graph getGraph() {
+ return new SimpleGraph(this,true);
+ }
+ };
+ graph = new PrivilegedGraphWrapper(jenaAdapter.getGraph());
+ } else { //construct an MGraph
+ jenaAdapter = new JenaGraphAdaptor(model.getGraph());
+ this.graph = new DatasetLockedMGraph(lock,
+ new PrivilegedMGraphWrapper(jenaAdapter));
+ }
+ }
+ /**
+ * The {@link JenaGraphAdaptor}. For internal use only! Do not pass
+ * this instance to other components. Use {@link #getGraph()} and
+ * {@link #getMGraph()} instead!
+ * @return the plain {@link JenaGraphAdaptor}
+ */
+ public JenaGraphAdaptor getJenaAdapter(){
+ return jenaAdapter;
+ }
+
+ public boolean isReadWrite(){
+ return readWrite;
+ }
+ /**
+ * Getter for the {@link MGraph}
+ * @return the {@link MGraph}
+ * @throws IllegalStateException if this {@link ModelGraph} is NOT
+ * {@link #readWrite}
+ */
+ public MGraph getMGraph(){
+ if(!readWrite){
+ throw new IllegalStateException("Unable to return MGraph for read-only models");
+ }
+ return (MGraph)graph;
+ }
+ /**
+ * Getter for the {@link Graph}
+ * @return the {@link Graph}
+ * @throws IllegalStateException if this {@link ModelGraph} is
+ * {@link #readWrite}
+ */
+ public Graph getGraph() {
+ if(readWrite){
+ throw new IllegalStateException("Unable to return Graph for read/write models.");
+ }
+ return (Graph)graph;
+ }
+ /**
+ * closes this ModelGraph and frees up all Jena TDB related resources.
+ */
+ public void close(){
+ this.graph = null;
+ this.jenaAdapter = null;
+ sync();
+ this.model.close();
+ }
+ /**
+ * Synchronize the Jena Model with the field system by calling
+ * {@link TDB#sync(Model)}
+ */
+ public void sync(){
+ TDB.sync(model);
+ }
+ /**
+ * Removes all triples from the Jena Model and than calls {@link #close()}
+ * to free remaining resources. Note that in Jena TDB a named model is
+ * deleted if no more triples with the given context are present within
+ * the {@link Quad} store of the Jena TDB {@link DatasetGraph}.
+ */
+ public void delete(){
+ this.model.removeAll();
+ close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
new file mode 100644
index 0000000..ccf3003
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
@@ -0,0 +1,22 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import org.apache.clerezza.rdf.core.UriRef;
+
+/**
+ * Provides static methods in order to represent classes used to
+ * represent named graphs.
+ *
+ * @author misl
+ *
+ */
+public class Symbols {
+
+ public static UriRef Index = new UriRef("http://clerezza.apache.org/storage/Index");
+
+ public static UriRef Default = new UriRef("http://clerezza.apache.org/storage/Default");
+
+ public static UriRef Graph = new UriRef("http://clerezza.apache.org/storage/Graph");
+
+ public static UriRef MGraph = new UriRef("http://clerezza.apache.org/storage/MGraph");
+
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
new file mode 100644
index 0000000..fb165d0
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
@@ -0,0 +1,62 @@
+package org.apache.clerezza.rdf.jena.tdb.internals;
+
+import java.util.AbstractSet;
+import java.util.Iterator;
+
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.ontologies.RDF;
+
+/**
+ * Represents a set of uri ref Set<UriRef>
+ * @author Minto van der Sluis
+ */
+public class UriRefSet extends AbstractSet<UriRef> {
+ private ModelGraph graphNameIndex;
+ private UriRef graphType;
+
+ public UriRefSet(ModelGraph index, UriRef object) {
+ graphNameIndex = index;
+ graphType = object;
+ }
+
+ @Override
+ public int size() {
+ // TODO: How to get the proper size based on graphType
+ return graphNameIndex.getMGraph().size();
+ }
+
+ @Override
+ public Iterator<UriRef> iterator() {
+ final Iterator<Triple> indexIter = graphNameIndex.getMGraph().filter( null, RDF.type, graphType );
+ return new Iterator<UriRef>() {
+ @Override
+ public boolean hasNext() {
+ return indexIter.hasNext();
+ }
+
+ @Override
+ public UriRef next() {
+ return UriRef.class.cast(indexIter.next().getSubject());
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ @Override
+ public boolean add(UriRef o) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ if (o instanceof UriRef) {
+ return graphNameIndex.getMGraph().filter(UriRef.class.cast(o), RDF.type, graphType).hasNext();
+ }
+ return false;
+ }
+};
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
new file mode 100644
index 0000000..c8a7a5f
--- /dev/null
+++ b/rdf/jena/tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
@@ -0,0 +1,110 @@
+package org.apache.clerezza.rdf.jena.tdb.storage;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
+import org.apache.clerezza.rdf.core.sparql.query.Query;
+import org.apache.clerezza.rdf.jena.sparql.ResultSetWrapper;
+import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.QueryException;
+import com.hp.hpl.jena.query.QueryExecException;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.update.GraphStore;
+import com.hp.hpl.jena.update.GraphStoreFactory;
+import com.hp.hpl.jena.update.UpdateAction;
+import org.apache.clerezza.rdf.core.UriRef;
+
+abstract class BaseTdbTcProvider implements QueryableTcProvider{
+
+ // ------------------------------------------------------------------------
+ // Object attributes
+ // ------------------------------------------------------------------------
+
+ private Dataset dataset;
+
+ // ------------------------------------------------------------------------
+ // Implementing QueryableTcProvider
+ // ------------------------------------------------------------------------
+
+ @Override
+ public Object executeSparqlQuery(final String query, UriRef defaultGraph) {
+ // Missing permission (java.lang.RuntimePermission getClassLoader)
+ // when calling QueryFactory.create causes ExceptionInInitializerError
+ // to be thrown.
+ // QueryExecutionFactory.create requires
+ // (java.io.FilePermission [etc/]location-mapping.* read)
+ // Thus, they are placed within doPrivileged
+ QueryExecution qexec = AccessController
+ .doPrivileged(new PrivilegedAction<QueryExecution>() {
+
+ @Override
+ public QueryExecution run() {
+ try {
+ com.hp.hpl.jena.query.Query jenaQuery = QueryFactory
+ .create(query);
+ if (jenaQuery.isUnknownType()) {
+ return null;
+ }
+ return QueryExecutionFactory.create(jenaQuery, getDataset());
+ } catch (QueryException ex) {
+ return null;
+ }
+ }
+ });
+
+ if (qexec == null) {
+ return executeUpdate(query);
+ }
+
+ try {
+ try {
+ return new ResultSetWrapper(qexec.execSelect());
+ } catch (QueryExecException e) {
+ try {
+ return Boolean.valueOf(qexec.execAsk());
+ } catch (QueryExecException e2) {
+ try {
+ return new JenaGraphAdaptor(qexec.execDescribe()
+ .getGraph()).getGraph();
+ } catch (QueryExecException e3) {
+ return new JenaGraphAdaptor(qexec.execConstruct()
+ .getGraph()).getGraph();
+ }
+ }
+ }
+ } finally {
+ qexec.close();
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters / Setters
+ // ------------------------------------------------------------------------
+
+ public Dataset getDataset() {
+ if (dataset == null) {
+ throw new RuntimeException("Missing Dataset!");
+ }
+ return dataset;
+ }
+
+ public void setDataset(Dataset dataset) {
+ this.dataset = dataset;
+ }
+
+ // ------------------------------------------------------------------------
+ // Private methods
+ // ------------------------------------------------------------------------
+
+ private Object executeUpdate(String query) {
+ GraphStore graphStore = GraphStoreFactory.create(getDataset()) ;
+ UpdateAction.parseExecute(query, graphStore) ;
+ return true;
+ }
+}