This is an automated email from the ASF dual-hosted git repository. hasan pushed a commit to branch reunited in repository https://gitbox.apache.org/repos/asf/clerezza.git
commit b314faa852faef954471773c784dd6ec6f266548 Author: Hasan <[email protected]> AuthorDate: Thu Feb 7 08:27:31 2019 +0100 CLEREZZA-1034: Merge rdf simple storage into dataset module --- dataset/pom.xml | 34 +++-- .../clerezza/simple/storage/SimpleTcProvider.java | 166 +++++++++++++++++++++ .../org.apache.clerezza.dataset.WeightedTcProvider | 1 + .../simple/storage/AccessViaTcManager.java | 40 +++++ .../simple/storage/GenericTcProviderTest.java | 43 ++++++ .../simple/storage/SimpleGraphGenericTest.java | 35 +++++ pom.xml | 2 +- 7 files changed, 305 insertions(+), 16 deletions(-) diff --git a/dataset/pom.xml b/dataset/pom.xml index 3ce095f..5225584 100644 --- a/dataset/pom.xml +++ b/dataset/pom.xml @@ -1,21 +1,20 @@ <?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 - 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. + 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" @@ -52,6 +51,11 @@ <version>8-SNAPSHOT</version> </dependency> <dependency> + <groupId>org.apache.clerezza</groupId> + <artifactId>test.utils</artifactId> + <version>8-SNAPSHOT</version> + </dependency> + <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> </dependency> @@ -93,7 +97,7 @@ <extensions>true</extensions> <configuration> <instructions> - <Export-Package>org.apache.clerezza.dataset.*</Export-Package> + <Export-Package>org.apache.clerezza.dataset.*, org.apache.clerezza.simple.storage.*</Export-Package> </instructions> </configuration> </plugin> diff --git a/dataset/src/main/java/org/apache/clerezza/simple/storage/SimpleTcProvider.java b/dataset/src/main/java/org/apache/clerezza/simple/storage/SimpleTcProvider.java new file mode 100644 index 0000000..f602ee4 --- /dev/null +++ b/dataset/src/main/java/org/apache/clerezza/simple/storage/SimpleTcProvider.java @@ -0,0 +1,166 @@ +/* + * 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.simple.storage; + +import org.apache.clerezza.api.Graph; +import org.apache.clerezza.api.IRI; +import org.apache.clerezza.api.ImmutableGraph; +import org.apache.clerezza.api.impl.graph.SimpleGraph; +import org.apache.clerezza.api.impl.graph.SimpleImmutableGraph; +import org.apache.clerezza.dataset.*; +import org.osgi.service.component.annotations.Component; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@Component(service = WeightedTcProvider.class, property = TcManager.GENERAL_PURPOSE_TC+"=true") +public class SimpleTcProvider implements WeightedTcProvider { + + private Map<IRI, Graph> tripleMap = new HashMap<IRI, Graph>(); + + @Override + public ImmutableGraph createImmutableGraph(IRI name, Graph triples) + throws EntityAlreadyExistsException { + if ((name == null) || (name.getUnicodeString() == null) + || (name.getUnicodeString().trim().length() == 0)) { + throw new IllegalArgumentException("Name must not be null"); + } + + try { + // throws NoSuchEntityException if a Graph with that name + // already exists + this.getGraph(name); + } catch (NoSuchEntityException e) { + ImmutableGraph result; + if (triples == null) { + result = new SimpleImmutableGraph(new SimpleGraph()); + } else { + if (ImmutableGraph.class.isAssignableFrom(triples.getClass())) { + result = (ImmutableGraph) triples; + } else { + result = new SimpleImmutableGraph(triples); + } + } + tripleMap.put(name, result); + + return result; + } + throw new EntityAlreadyExistsException(name); + } + + @Override + public Graph createGraph(IRI name) throws EntityAlreadyExistsException { + if ((name == null) || (name.getUnicodeString() == null) + || (name.getUnicodeString().trim().length() == 0)) { + throw new IllegalArgumentException("Name must not be null"); + } + + try { + // throws NoSuchEntityException if a Graph with that name + // already exists + this.getGraph(name); + } catch (NoSuchEntityException e) { + Graph result = new SimpleGraph(); + tripleMap.put(name, result); + return result; + } + throw new EntityAlreadyExistsException(name); + } + + @Override + public void deleteGraph(IRI name) + throws NoSuchEntityException, EntityUndeletableException { + if (tripleMap.remove(name) == null) { + throw new NoSuchEntityException(name); + } + } + + @Override + public ImmutableGraph getImmutableGraph(IRI name) throws NoSuchEntityException { + Graph tripleCollection = tripleMap.get(name); + if (tripleCollection == null) { + throw new NoSuchEntityException(name); + } else if (ImmutableGraph.class.isAssignableFrom(tripleCollection.getClass())) { + return (ImmutableGraph) tripleCollection; + } + throw new NoSuchEntityException(name); + } + + @Override + public Graph getMGraph(IRI name) throws NoSuchEntityException { + Graph tripleCollection = tripleMap.get(name); + if (tripleCollection == null) { + throw new NoSuchEntityException(name); + } else if (!ImmutableGraph.class.isAssignableFrom(tripleCollection.getClass())) { + return (Graph) tripleCollection; + } + throw new NoSuchEntityException(name); + } + + @Override + public Set<IRI> getNames(ImmutableGraph graph) { + throw new UnsupportedOperationException( + "Not supported yet. equals() has to be implemented first"); + } + + @Override + public Graph getGraph(IRI name) + throws NoSuchEntityException { + Graph tripleCollection = tripleMap.get(name); + if (tripleCollection == null) { + throw new NoSuchEntityException(name); + } else { + return tripleCollection; + } + } + + @Override + public int getWeight() { + return 1; + } + + @Override + public Set<IRI> listImmutableGraphs() { + Set<IRI> result = new HashSet<IRI>(); + for (IRI uriRef : listGraphs()) { + if (tripleMap.get(uriRef) instanceof ImmutableGraph) { + result.add(uriRef); + } + } + return result; + } + + @Override + public Set<IRI> listMGraphs() { + Set<IRI> result = new HashSet<IRI>(); + for (IRI uriRef : listGraphs()) { + if (!(tripleMap.get(uriRef) instanceof ImmutableGraph)) { + result.add(uriRef); + } + } + return result; + } + + @Override + public Set<IRI> listGraphs() { + return tripleMap.keySet(); + } +} diff --git a/dataset/src/main/resources/META-INF/services/org.apache.clerezza.dataset.WeightedTcProvider b/dataset/src/main/resources/META-INF/services/org.apache.clerezza.dataset.WeightedTcProvider new file mode 100644 index 0000000..f2b0733 --- /dev/null +++ b/dataset/src/main/resources/META-INF/services/org.apache.clerezza.dataset.WeightedTcProvider @@ -0,0 +1 @@ +org.apache.clerezza.simple.storage.SimpleTcProvider \ No newline at end of file diff --git a/dataset/src/test/java/org/apache/clerezza/simple/storage/AccessViaTcManager.java b/dataset/src/test/java/org/apache/clerezza/simple/storage/AccessViaTcManager.java new file mode 100644 index 0000000..3afbd63 --- /dev/null +++ b/dataset/src/test/java/org/apache/clerezza/simple/storage/AccessViaTcManager.java @@ -0,0 +1,40 @@ +/* + * 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.simple.storage; + +import org.apache.clerezza.api.Graph; +import org.apache.clerezza.api.IRI; +import org.apache.clerezza.api.impl.graph.SimpleGraph; +import org.apache.clerezza.dataset.TcManager; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author developer + */ +public class AccessViaTcManager { + + @Test + public void simple() { + Graph g = TcManager.getInstance().createGraph(new IRI("http://example.org/foo")); + Assert.assertTrue(g instanceof SimpleGraph); + } + +} diff --git a/dataset/src/test/java/org/apache/clerezza/simple/storage/GenericTcProviderTest.java b/dataset/src/test/java/org/apache/clerezza/simple/storage/GenericTcProviderTest.java new file mode 100644 index 0000000..65dcd10 --- /dev/null +++ b/dataset/src/test/java/org/apache/clerezza/simple/storage/GenericTcProviderTest.java @@ -0,0 +1,43 @@ +/* + * 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.simple.storage; + +import org.apache.clerezza.dataset.TcProvider; +import org.apache.clerezza.test.utils.TcProviderTest; +import org.junit.After; + +/** + * + * @author mir + */ +public class GenericTcProviderTest extends TcProviderTest { + + SimpleTcProvider provider = new SimpleTcProvider(); + + @After + public void cleanUp() { + provider = new SimpleTcProvider(); + } + + @Override + protected TcProvider getInstance() { + return provider; + } + +} diff --git a/dataset/src/test/java/org/apache/clerezza/simple/storage/SimpleGraphGenericTest.java b/dataset/src/test/java/org/apache/clerezza/simple/storage/SimpleGraphGenericTest.java new file mode 100644 index 0000000..0445e97 --- /dev/null +++ b/dataset/src/test/java/org/apache/clerezza/simple/storage/SimpleGraphGenericTest.java @@ -0,0 +1,35 @@ +/* + * 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.simple.storage; + +import org.apache.clerezza.api.Graph; +import org.apache.clerezza.api.impl.graph.SimpleGraph; +import org.apache.clerezza.test.utils.GraphTest; + +/** + * + * @author mir + */ +public class SimpleGraphGenericTest extends GraphTest{ + + @Override + protected Graph getEmptyGraph() { + return new SimpleGraph(); + } +} diff --git a/pom.xml b/pom.xml index 9e0dc55..46ccaf4 100644 --- a/pom.xml +++ b/pom.xml @@ -45,8 +45,8 @@ <module>api.impl</module> <module>sparql</module> <module>representation</module> - <module>dataset</module> <module>test.utils</module> + <module>dataset</module> <module>impl.sparql</module> <module>jaxrs.rdf.providers</module> <module>parent</module>
