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:54 UTC
[11/14] clerezza git commit: CLEREZZA-966: moved jena.tdb.storage
into the hierarchy
CLEREZZA-966: moved jena.tdb.storage into the hierarchy
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/dac431ca
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/dac431ca
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/dac431ca
Branch: refs/heads/rdf-commons
Commit: dac431ca927bdf9a17461976876b9622631309a9
Parents: 0a84a39
Author: Reto Gmuer <re...@apache.org>
Authored: Sun Mar 22 18:00:22 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Sun Mar 22 18:00:22 2015 +0000
----------------------------------------------------------------------
pom.xml | 1 -
provisioning/rdf/pom.xml | 1 +
rdf.jena.tdb.storage/LICENSE | 201 ------
rdf.jena.tdb.storage/pom.xml | 112 ---
.../jena/tdb/internals/DatasetLockedMGraph.java | 46 --
.../rdf/jena/tdb/internals/ModelGraph.java | 149 ----
.../rdf/jena/tdb/internals/Symbols.java | 22 -
.../rdf/jena/tdb/internals/UriRefSet.java | 62 --
.../rdf/jena/tdb/storage/BaseTdbTcProvider.java | 110 ---
.../tdb/storage/SingleTdbDatasetTcProvider.java | 717 -------------------
.../rdf/jena/tdb/storage/TdbTcProvider.java | 434 -----------
....clerezza.rdf.core.access.WeightedTcProvider | 1 -
.../OSGI-INF/metatype/metatype.properties | 47 --
.../MultiThreadedSingleTdbDatasetTest.java | 261 -------
.../rdf/jena/tdb/storage/MultiThreadedTest.java | 143 ----
.../tdb/storage/MultiThreadedTestSingleTdb.java | 150 ----
.../tdb/storage/SingleTdbDatasetMGraphTest.java | 56 --
.../storage/SingleTdbDatasetTcProviderTest.java | 168 -----
.../rdf/jena/tdb/storage/TdbMGraphTest.java | 107 ---
.../rdf/jena/tdb/storage/TdbTcProviderTest.java | 61 --
rdf/jena/pom.xml | 3 +-
rdf/jena/tdb.storage/LICENSE | 201 ++++++
rdf/jena/tdb.storage/pom.xml | 112 +++
.../jena/tdb/internals/DatasetLockedMGraph.java | 46 ++
.../rdf/jena/tdb/internals/ModelGraph.java | 149 ++++
.../rdf/jena/tdb/internals/Symbols.java | 22 +
.../rdf/jena/tdb/internals/UriRefSet.java | 62 ++
.../rdf/jena/tdb/storage/BaseTdbTcProvider.java | 110 +++
.../tdb/storage/SingleTdbDatasetTcProvider.java | 717 +++++++++++++++++++
.../rdf/jena/tdb/storage/TdbTcProvider.java | 434 +++++++++++
....clerezza.rdf.core.access.WeightedTcProvider | 1 +
.../OSGI-INF/metatype/metatype.properties | 47 ++
.../MultiThreadedSingleTdbDatasetTest.java | 261 +++++++
.../rdf/jena/tdb/storage/MultiThreadedTest.java | 143 ++++
.../tdb/storage/MultiThreadedTestSingleTdb.java | 150 ++++
.../tdb/storage/SingleTdbDatasetMGraphTest.java | 56 ++
.../storage/SingleTdbDatasetTcProviderTest.java | 168 +++++
.../rdf/jena/tdb/storage/TdbMGraphTest.java | 107 +++
.../rdf/jena/tdb/storage/TdbTcProviderTest.java | 61 ++
39 files changed, 2850 insertions(+), 2849 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a9f6ebb..1ae7238 100644
--- a/pom.xml
+++ b/pom.xml
@@ -73,7 +73,6 @@
<module>rdf.cris</module>
<module>rdf.enrichment</module>
<module>rdf.file.storage</module>
- <module>rdf.jena.tdb.storage</module>
<module>rdf.locking</module>
<module>rdf.rdfjson</module>
<module>rdf.scala.utils</module>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/provisioning/rdf/pom.xml
----------------------------------------------------------------------
diff --git a/provisioning/rdf/pom.xml b/provisioning/rdf/pom.xml
index aba5127..d5acc70 100644
--- a/provisioning/rdf/pom.xml
+++ b/provisioning/rdf/pom.xml
@@ -55,6 +55,7 @@
<dependency>
<groupId>org.wymiwyg</groupId>
<artifactId>wymiwyg-commons-core</artifactId>
+ <version>0.8</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
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
deleted file mode 100644
index 261eeb9..0000000
--- a/rdf.jena.tdb.storage/LICENSE
+++ /dev/null
@@ -1,201 +0,0 @@
- 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
deleted file mode 100644
index 9306ee3..0000000
--- a/rdf.jena.tdb.storage/pom.xml
+++ /dev/null
@@ -1,112 +0,0 @@
-<?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
deleted file mode 100644
index a3cdd19..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/DatasetLockedMGraph.java
+++ /dev/null
@@ -1,46 +0,0 @@
-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
deleted file mode 100644
index 7b6421f..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/ModelGraph.java
+++ /dev/null
@@ -1,149 +0,0 @@
-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
deleted file mode 100644
index ccf3003..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/Symbols.java
+++ /dev/null
@@ -1,22 +0,0 @@
-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
deleted file mode 100644
index fb165d0..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/internals/UriRefSet.java
+++ /dev/null
@@ -1,62 +0,0 @@
-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
deleted file mode 100644
index c8a7a5f..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/BaseTdbTcProvider.java
+++ /dev/null
@@ -1,110 +0,0 @@
-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;
- }
-}
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/SingleTdbDatasetTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
deleted file mode 100644
index b8df417..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/SingleTdbDatasetTcProvider.java
+++ /dev/null
@@ -1,717 +0,0 @@
-package org.apache.clerezza.rdf.jena.tdb.storage;
-
-import java.io.File;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.TripleCollection;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
-import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.QueryableTcProvider;
-import org.apache.clerezza.rdf.core.access.TcProvider;
-import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.jena.tdb.internals.ModelGraph;
-import org.apache.clerezza.rdf.jena.tdb.internals.Symbols;
-import org.apache.clerezza.rdf.jena.tdb.internals.UriRefSet;
-import org.apache.clerezza.rdf.ontologies.RDF;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.ConfigurationPolicy;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.MapMaker;
-import com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.tdb.TDB;
-import com.hp.hpl.jena.tdb.TDBFactory;
-import org.apache.clerezza.rdf.core.access.TcManager;
-
-/**
- * {@link WeightedTcProvider} implementation for Jena TDB that uses a single
- * {@link TDBFactory#createDataset(String) Dataset} to store all created
- * {@link Graph} and {@link MGraph} instances.<p>
- * The {@link #TDB_DIR} is uses to configure the directory on the disc. It
- * supports property substitution <code>'${property}'</code> based on properties defined
- * in the {@link BundleContext#getProperty(String)} and
- * {@link System#getProperty(String)}. This is to easily allow configurations
- * such as <code>"${myHome}/myRdfStore"</code><p>
- * The {@link #DEFAULT_GRAPH_NAME} property can be used to define the
- * name of the Graph that exposes the {@link Dataset#getDefaultModel()} as
- * both {@link TcProvider#getGraph(UriRef)} and {@link TcProvider#getMGraph(UriRef)}.
- * This easily allows to access the union graph of the Jena TDB dataset.<p>
- * This {@link TcProvider} {@link ConfigurationPolicy#REQUIRE requires} an
- * configuration and uses the {@link Component#configurationFactory()
- * configuration factory}. Therefore it will be bot active until a valid
- * configuration is parsed to the {@link ConfigurationAdmin} service. However
- * it supports multiple instances to be created.<p>
- * Users that want to use multiple instances will need to use special filters
- * to ensure that the correct instance is injected to components. As by default
- * the instance with the highest {@link #WEIGHT} will be used by Clerezza
- * to create instances. A good practice to filter for multiple instances is
- * to add an additional user defined key to the configuration that can later
- * be used for filtering. Such additional keys will be savely ignored by
- * this implementation.<p>
- *
- * @author Rupert Westenthaler, MInto van der Sluis
- *
- */
-@Component(metatype=true, immediate=true,
- configurationFactory=true, policy=ConfigurationPolicy.OPTIONAL)
-@Service({WeightedTcProvider.class, TcProvider.class, QueryableTcProvider.class})
-@Properties(value={
- @Property(name=SingleTdbDatasetTcProvider.TDB_DIR),
- @Property(name=SingleTdbDatasetTcProvider.DEFAULT_GRAPH_NAME),
- @Property(name=SingleTdbDatasetTcProvider.SYNC_INTERVAL, intValue=SingleTdbDatasetTcProvider.DEFAULT_SYNC_INTERVAL),
- @Property(name=SingleTdbDatasetTcProvider.WEIGHT, intValue=105),
- @Property(name=TcManager.GENERAL_PURPOSE_TC, boolValue = true)
-})
-public class SingleTdbDatasetTcProvider extends BaseTdbTcProvider implements WeightedTcProvider {
-
- public static final String TDB_DIR = "tdb-dir";
- public static final String DEFAULT_GRAPH_NAME = "default-graph-name";
- public static final String WEIGHT = "weight";
- public static final String SYNC_INTERVAL = "sync-interval";
- public static final String USE_GRAPH_NAME_SUFFIXES = "use-graph-name-suffixes";
-
- public static final int DEFAULT_SYNC_INTERVAL = 6;
- public static final int MIN_SYNC_INTERVAL = 3;
-
- private final Logger log = LoggerFactory.getLogger(SingleTdbDatasetTcProvider.class);
-
- private int weight;
- private ModelGraph graphNameIndex;
- private int syncInterval = DEFAULT_SYNC_INTERVAL;
- private SyncThread syncThread;
-
- private final ReadWriteLock datasetLock = new ReentrantReadWriteLock();;
- private UriRef defaultGraphName;
-
- // Ensure that models not yet garbage collected get properly synced.
- private final ConcurrentMap<UriRef, ModelGraph> syncModels = new MapMaker().weakValues().makeMap();
-
- /**
- * This background thread ensures that changes to {@link Model}s are
- * synchronized with the file system. Only {@link ModelGraph}s where
- * <code>{@link ModelGraph#isReadWrite()} == true</code> are synced.<p>
- * This is similar to the synchronize thread used by the {@link TdbTcProvider}.
- * This thread is started during the
- * {@link ScalableSingleTdbDatasetTcProvider#activate(ComponentContext) activation}
- * ad the shutdown is requested during
- * {@link ScalableSingleTdbDatasetTcProvider#deactivate(ComponentContext) deactivation}
- */
- class SyncThread extends Thread {
- private boolean stopRequested = false;
-
- @Override
- public void run() {
- while (!stopRequested) {
- try {
- Thread.sleep(syncInterval*1000);
- } catch (InterruptedException ex) {
- interrupt();
- }
- if (!stopRequested) {
- datasetLock.writeLock().lock();
- try {
- for(ModelGraph mg : syncModels.values()){
- if(mg.isReadWrite()){
- mg.sync();
- } //else we do not need to sync read-only models
- }
- } finally {
- datasetLock.writeLock().unlock();
- }
- }
- }
- }
-
- public void requestStop() {
- stopRequested = true;
- }
- }
-
- /**
- * Default constructor used by OSGI
- */
- public SingleTdbDatasetTcProvider(){}
-
- /**
- * Creates a TDB single dataset {@link TcProvider} based on the parsed
- * configuration.<p>
- * The following properties are supported:<ul>
- * <li> {@link #TDB_DIR} (required): The directory used by Jena TDB. Property
- * substitution "${property-name}" with {@link System#getProperties()} is
- * supported.
- * <li> {@link #DEFAULT_GRAPH_NAME}: The name ({@link UriRef}) of the
- * {@link Graph} that exports the union graph. This graph allows to query
- * triples in any named model managed by this {@link TcProvider}.
- * <li> {@link #SYNC_INTERVAL}: The sync interval that
- * is used to write changes in the graph to the file system. If missing
- * the {@link #DEFAULT_SYNC_INTERVAL} is used. Values lower than
- * {@link #MIN_SYNC_INTERVAL} are ignored
- * <li>{@link #WEIGHT}: The weight of this {@link TcProvider}. If missing
- * <code>0</code> is used as weight.
- * </ul>
- * <b>NOTE</b> Users need to call {@link #close()} to free up system
- * resources when they are no longer need this instance.
- * @param config The configuration
- * @throws IOException the
- * @throws ConfigurationException
- */
- public SingleTdbDatasetTcProvider(Dictionary<String,Object> config) throws ConfigurationException, IOException{
- activate(null,config);
- }
- /**
- * Activate method used by OSGI
- * @param ctx
- * @throws ConfigurationException
- * @throws IOException
- */
- @Activate
- @SuppressWarnings("unchecked")
- protected void activate(ComponentContext ctx) throws ConfigurationException, IOException {
- activate(ctx.getBundleContext(),ctx.getProperties());
- }
-
- /**
- * Internally used for activation to support the instantiation via
- * {@link #ScalableSingleTdbDatasetTcProvider(Dictionary)} - to be used outside
- * an OSGI container.
- * @param bc the BundleContext or <code>null</code> if activating outside
- * an OSGI container. The BundleContext is just used to lookup properties
- * for {@link #substituteProperty(String, BundleContext)}.
- * @param config The configuration for this Instance. Note that {@link #TDB_DIR}
- * is required to be present.
- * @throws ConfigurationException if the parsed configuration is invalid
- * @throws IOException on any error while creating/accessing the Jena TDB
- * directory.
- */
- private void activate(BundleContext bc,Dictionary<String,Object> config) throws ConfigurationException, IOException {
- log.info("Activating scalable single Dataset TDB provider");
- Object value = config.get(WEIGHT);
- if(value instanceof Number){
- weight = ((Number)value).intValue();
- } else if(value != null){
- try {
- weight = new BigDecimal(value.toString()).intValueExact();
- } catch (RuntimeException e) {
- throw new ConfigurationException(WEIGHT, "Unable to parse integer weight!", e);
- }
- } else { //weight not defined
- weight = 0;
- }
- value = config.get(SYNC_INTERVAL);
- if(value instanceof Number){
- syncInterval = Math.max(((Number)value).intValue(),MIN_SYNC_INTERVAL);
- } else if(value != null){
- try {
- syncInterval = Math.max(new BigDecimal(value.toString()).intValueExact(),MIN_SYNC_INTERVAL);
- } catch (RuntimeException e) {
- throw new ConfigurationException(SYNC_INTERVAL, "Unable to parse integer weight!", e);
- }
- } else { //sync interval not defined
- syncInterval = DEFAULT_SYNC_INTERVAL;
- }
- value = config.get(TDB_DIR);
- File dataDir;
- if(value != null && !value.toString().isEmpty()){
- dataDir = new File(substituteProperty(value.toString(),bc)).getAbsoluteFile();
- } else {
- value = config.get(Constants.SERVICE_PID);
- if(value == null){
- throw new ConfigurationException(TDB_DIR, "No Data Directory for "
- + "the Jena TDB store parsed. Also unable to use the "
- + "'service.pid' property as default because this property "
- + "is not present in the parsed configuration.");
- }
- dataDir = bc.getDataFile("singleTdb"+File.separatorChar+value.toString());
- log.info("No TDB directory parsed - use default '{}'",dataDir);
- }
- //parse the default graph name
- value = config.get(DEFAULT_GRAPH_NAME);
- if(value != null && !value.toString().isEmpty()){
- try {
- new URI(value.toString());
- defaultGraphName = new UriRef(value.toString());
- } catch (URISyntaxException e) {
- throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The parsed name '"
- + value + "'for the default graph (union over all "
- + "named graphs managed by this Jena TDB dataset) MUST BE "
- + "an valid URI or NULL do deactivate this feature!",e);
- }
- } else {
- defaultGraphName = null; //deactivate the default graph name
- }
-
- //validate the parsed directory!
- if(!dataDir.exists()){
- if(dataDir.mkdirs()){
- log.info("Created Jena TDB data directory {}",dataDir);
- } else {
- throw new ConfigurationException(TDB_DIR, "Unable to create Jena TDB data directory '"+dataDir+"'!");
- }
- } else if(!dataDir.isDirectory()){
- throw new ConfigurationException("tdb.dir", "Configured jena TDB data directory '"
- + dataDir+"' already exists, but is not a Directory!");
- } //else exists and is a directory ... nothing to do
- TDB.getContext().set(TDB.symUnionDefaultGraph, true);
- setDataset( TDBFactory.createDataset(dataDir.getAbsolutePath()) );
- graphNameIndex = new ModelGraph(datasetLock, getDataset().getDefaultModel(),true);
-
- // Remove existing default graph names from the index (if might have changed
- // in the mean time).
- removeDefaultGraphFromIndex();
-
- //finally ensure the the defaultGraphName is not also used as a graph/mgraph name
- if (defaultGraphName != null) {
- if (isExistingGraphName(defaultGraphName)) {
- throw new ConfigurationException(DEFAULT_GRAPH_NAME, "The configured default graph name '"
- +defaultGraphName+"' is already used as a Graph or MGraph name!");
- } else {
- addToIndex( defaultGraphName, Symbols.Default );
- addToIndex( defaultGraphName, Symbols.Graph );
- }
- }
-
- syncThread = new SyncThread();
- syncThread.setDaemon(true);
- syncThread.setName("SyncDaemon for Jena TDB "+dataDir.getAbsolutePath());
- syncThread.start();
- }
-
- /**
- * call close in finalisation
- */
- @Override
- protected void finalize() throws Throwable {
- close();
- super.finalize();
- }
-
- /**
- * Closes this {@link TcProvider} instance and frees up all system resources.
- * This method needs only to be called when using this TcProvider outside
- * an OSGI environment.
- */
- public void close(){
- deactivate(null);
- }
-
- /**
- * Deactivates this component. Called by the OSGI environment if this
- * component gets deactivated.
- * @param ctx the ComponentContext. May be <code>null</code>
- */
- @Deactivate
- protected void deactivate(ComponentContext ctx) {
- if(syncThread != null){
- syncThread.requestStop();
- syncThread = null;
- }
- Dataset dataset = getDataset();
- if(dataset != null){ //avoid NPE on multiple calls
- datasetLock.writeLock().lock();
- try {
- for(ModelGraph mg : syncModels.values()){
- mg.close(); //close also syncs!
- }
- syncModels.clear();
-
- graphNameIndex.close();
- graphNameIndex = null;
-
- TDB.sync(dataset);
- dataset.close();
- setDataset(null);
- } finally {
- datasetLock.writeLock().unlock();
- }
- }
- }
-
- /**
- * Internal method used to retrieve an existing Jena {@link ModelGraph}
- * instance from {@link #syncModels} or initializes a new Jena TDB {@link Model}
- * and Clerezza {@link Graph}s/{@link MGraph}s.
- * @param name the name of the Graph to initialize/create
- * @param readWrite if <code>true</code> a {@link MGraph} is initialized.
- * Otherwise a {@link Graph} is created.
- * @param create if this method is allowed to create an new {@link Model} or
- * if an already existing model is initialized.
- * @return the initialized {@link Model} and @link Graph} or {@link MGraph}.
- * The returned instance will be also cached in {@link #syncModels}.
- * @throws NoSuchEntityException If <code>create == false</code> and no
- * {@link Model} for the parsed <code>name</code> exists.
- */
- private ModelGraph getModelGraph(UriRef name, boolean readWrite,boolean create) throws NoSuchEntityException {
- ModelGraph modelGraph = null;
- datasetLock.readLock().lock();
- try {
- if(readWrite) {
- // Reuse existing model if not yet garbage collected.
- modelGraph = syncModels.get(name);
- }
- if((modelGraph != null || isExistingGraphName(name)) && create){
- throw new EntityAlreadyExistsException(name);
- } else if(modelGraph == null){
- String modelName = name.getUnicodeString();
- modelGraph = new ModelGraph(datasetLock, name.equals(defaultGraphName) ?
- getDataset().getNamedModel("urn:x-arq:UnionGraph") :
- getDataset().getNamedModel(modelName),readWrite);
- if(readWrite) {
- // Keep track of readwrite model to be able to sync them.
- this.syncModels.put(name, modelGraph);
- }
- }
- } finally {
- datasetLock.readLock().unlock();
- }
- return modelGraph;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#getGraph(org.apache.clerezza.rdf.core.UriRef)
- */
- @Override
- public Graph getGraph(UriRef name) throws NoSuchEntityException {
- if(name == null){
- throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
- }
- datasetLock.readLock().lock();
- try {
- if (isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
- return getModelGraph(name,false,false).getGraph();
- } else {
- throw new NoSuchEntityException(name);
- }
- } finally {
- datasetLock.readLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#getMGraph(org.apache.clerezza.rdf.core.UriRef)
- */
- @Override
- public MGraph getMGraph(UriRef name) throws NoSuchEntityException {
- if(name == null){
- throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
- }
- datasetLock.readLock().lock();
- try {
- if(isExistingGraphName(name, Symbols.MGraph)){
- return getModelGraph(name,true,false).getMGraph();
- } else {
- throw new NoSuchEntityException(name);
- }
- } finally {
- datasetLock.readLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#getTriples(org.apache.clerezza.rdf.core.UriRef)
- */
- @Override
- public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
- if(name == null){
- throw new IllegalArgumentException("The parsed Graph UriRef MUST NOT be NULL!");
- }
- datasetLock.readLock().lock();
- try {
- if(isExistingGraphName(name, Symbols.Graph) || name.equals(defaultGraphName)){
- return getGraph(name);
- } else if(isExistingGraphName(name, Symbols.MGraph)){
- return getMGraph(name);
- } else {
- throw new NoSuchEntityException(name);
- }
- } finally {
- datasetLock.readLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#listGraphs()
- */
- @Override
- public Set<UriRef> listGraphs() {
- datasetLock.readLock().lock();
- try {
- return new HashSet(new UriRefSet( graphNameIndex, Symbols.Graph ));
- } finally {
- datasetLock.readLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#listMGraphs()
- */
- @Override
- public Set<UriRef> listMGraphs() {
- datasetLock.readLock().lock();
- try {
- return new HashSet(new UriRefSet( graphNameIndex, Symbols.MGraph ));
- } finally {
- datasetLock.readLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#listTripleCollections()
- */
- @Override
- public Set<UriRef> listTripleCollections() {
- datasetLock.readLock().lock();
- try {
- return new HashSet(new UriRefSet( graphNameIndex, null ));
- } finally {
- datasetLock.readLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#createMGraph(org.apache.clerezza.rdf.core.UriRef)
- */
- @Override
- public MGraph createMGraph(UriRef name) throws UnsupportedOperationException,
- EntityAlreadyExistsException {
- if(name == null){
- throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!");
- }
- datasetLock.writeLock().lock();
- try {
- if(isExistingGraphName(name)){
- throw new EntityAlreadyExistsException(name);
- }
- MGraph graph = getModelGraph(name,true,true).getMGraph();
- addToIndex( name, Symbols.MGraph);
- return graph;
- } finally {
- datasetLock.writeLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#createGraph(org.apache.clerezza.rdf.core.UriRef, org.apache.clerezza.rdf.core.TripleCollection)
- */
- @Override
- public Graph createGraph(UriRef name, TripleCollection triples) throws UnsupportedOperationException,
- EntityAlreadyExistsException {
- if(name == null){
- throw new IllegalArgumentException("The parsed Grpah name MUST NOT be NULL!");
- }
- ModelGraph mg;
- datasetLock.writeLock().lock();
- try {
- if(isExistingGraphName(name)){
- throw new EntityAlreadyExistsException(name);
- }
- mg = getModelGraph(name,false,true);
- addToIndex( name, Symbols.Graph);
-
- //add the parsed data!
- if(triples != null) { //load the initial and final set of triples
- mg.getJenaAdapter().addAll(triples);
- mg.sync();
- }
- } finally {
- datasetLock.writeLock().unlock();
- }
- return mg.getGraph();
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#deleteTripleCollection(org.apache.clerezza.rdf.core.UriRef)
- */
- @Override
- public void deleteTripleCollection(UriRef name) throws UnsupportedOperationException,
- NoSuchEntityException,
- EntityUndeletableException {
- if(name == null){
- throw new IllegalArgumentException("The parsed MGrpah name MUST NOT be NULL!");
- }
- datasetLock.writeLock().lock();
- try {
- if(isExistingGraphName(name,Symbols.MGraph)){
- ModelGraph mg = getModelGraph(name, true, false);
- mg.delete();
- removeFromIndex( name, Symbols.MGraph );
- } else if(isExistingGraphName(name,Symbols.Graph)){
- ModelGraph mg = getModelGraph(name, false, false);
- mg.delete();
- removeFromIndex( name, Symbols.Graph );
- } else if (name.equals(defaultGraphName)){
- throw new EntityUndeletableException(defaultGraphName);
- }
- //delete the graph from the initModels list
- syncModels.remove(name);
- } finally {
- datasetLock.writeLock().unlock();
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.TcProvider#getNames(org.apache.clerezza.rdf.core.Graph)
- */
- @Override
- public Set<UriRef> getNames(Graph graph) {
- //TODO: this method would require to compare the triples within the graph
- // because an equals check will not work with BNodes.
- Set<UriRef> graphNames = new HashSet<UriRef>();
- for( Iterator<Triple> iterator = graphNameIndex.getMGraph().iterator(); iterator.hasNext(); ) {
- Triple triple = iterator.next();
- UriRef graphName = new UriRef(triple.getSubject().toString());
- Graph currentGraph = getModelGraph(graphName, false, false).getGraph();
- if(graph.equals(currentGraph)){
- graphNames.add(graphName);
- }
- }
- return graphNames;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.access.WeightedTcProvider#getWeight()
- */
- @Override
- public int getWeight() {
- return weight;
- }
-
- /**
- * Substitutes ${property.name} with the values retrieved via <ul>
- * <li> {@link BundleContext#getProperty(String)} or
- * <li> {@link System#getProperty(String, String)} if the parsed
- * {@link BundleContext} is <code>null</code>
- * </ul>
- * Substitutes with an empty string if the property is not present. If
- * the substitution does not end with {@link File#separatorChar}, than it is
- * appended to allow easily creating paths relative to root directory available
- * as property regardless if the property includes/excludes the final
- * separator char.
- * <p>
- * Nested substitutions are NOT supported. However multiple substitutions are supported.
- * <p>
- * If someone knows a default implementation feel free to replace!
- *
- * @param value
- * the value to substitute
- * @param bundleContext
- * If not <code>null</code> the {@link BundleContext#getProperty(String)} is used instead of
- * the {@link System#getProperty(String)}. By that it is possible to use OSGI only properties
- * for substitution.
- * @return the substituted value
- */
- private static String substituteProperty(String value, BundleContext bundleContext) {
- int prevAt = 0;
- int foundAt = 0;
- StringBuilder substitution = new StringBuilder();
- while ((foundAt = value.indexOf("${", prevAt)) >= prevAt) {
- substitution.append(value.substring(prevAt, foundAt));
- String propertyName = value.substring(foundAt + 2, value.indexOf('}', foundAt));
- String propertyValue = bundleContext == null ? // if no bundleContext is available
- System.getProperty(propertyName) : // use the System properties
- bundleContext.getProperty(propertyName);
- if(propertyValue != null) {
- substitution.append(propertyValue);
- if(propertyValue.charAt(propertyValue.length()-1) != File.separatorChar){
- substitution.append(File.separatorChar);
- }
- } //else nothing to append
- prevAt = foundAt + propertyName.length() + 3; // +3 -> "${}".length
- }
- substitution.append(value.substring(prevAt, value.length()));
- return substitution.toString();
- }
-
- /**
- * Checks whether the given graph name already exists as the specified resource (either graph or mgraph).
- * @param graphName the graph name
- * @param graphType the resource type
- * @return true if a resource with the given name and type already exists, false otherwise.
- */
- private boolean isExistingGraphName(UriRef graphName, UriRef graphType) {
- return graphNameIndex.getMGraph().filter(graphName, RDF.type, graphType).hasNext();
- }
-
- /**
- * Checks whether the given graph name already exists as either a graph or mgraph.
- * @param graphName the graph name
- * @return true if a graph or mgraph with the given name already exists, false otherwise.
- */
- private boolean isExistingGraphName(UriRef graphName) {
- return isExistingGraphName(graphName, null);
- }
-
- /**
- * Adds a new graphname to the index of graphnames
- * @param graphName name of the graph
- * @param graphType resourcetype for the graph to add.
- */
- private void addToIndex(UriRef graphName, UriRef graphType) {
- graphNameIndex.getMGraph().add(new TripleImpl(graphName, RDF.type, graphType));
- graphNameIndex.sync();
- }
-
- /**
- * Removes a graphanem from the index of graphnames
- * @param graphName name of the graph to remove
- * @param graphType resource type of the graph to remove.
- */
- private void removeFromIndex(UriRef graphName, UriRef graphType) {
- MGraph index = graphNameIndex.getMGraph();
- Iterator<Triple> triplesToRemove = index.filter(graphName, RDF.type, graphType);
- for( ; triplesToRemove.hasNext(); ) {
- triplesToRemove.next();
- triplesToRemove.remove();
- }
- graphNameIndex.sync();
- }
-
- private void removeDefaultGraphFromIndex() {
- MGraph index = graphNameIndex.getMGraph();
- Iterator<Triple> triplesToRemove = index.filter(null, RDF.type, Symbols.Default);
- for( ; triplesToRemove.hasNext(); ) {
- Triple triple = triplesToRemove.next();
- triplesToRemove.remove();
- removeFromIndex( UriRef.class.cast(triple.getSubject()), Symbols.Graph );
- }
- graphNameIndex.sync();
- }
-}
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/TdbTcProvider.java
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java b/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
deleted file mode 100644
index f8924fc..0000000
--- a/rdf.jena.tdb.storage/src/main/java/org/apache/clerezza/rdf/jena/tdb/storage/TdbTcProvider.java
+++ /dev/null
@@ -1,434 +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 com.hp.hpl.jena.query.Dataset;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.tdb.TDB;
-import com.hp.hpl.jena.tdb.TDBFactory;
-import com.hp.hpl.jena.tdb.base.block.FileMode;
-import com.hp.hpl.jena.tdb.sys.SystemTDB;
-import java.io.File;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.locks.Lock;
-import java.util.logging.Level;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-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.EntityAlreadyExistsException;
-import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraphWrapper;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.access.TcManager;
-import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.util.PrivilegedMGraphWrapper;
-import org.apache.clerezza.rdf.jena.storage.JenaGraphAdaptor;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Service;
-
-/**
- * A {@link org.apache.clerezza.rdf.core.access.WeightedTcProvider} based on
- * Jena TDB.
- *
- * @see <a href="http://jena.hpl.hp.com/wiki/TDB/JavaAPI">
- * TDB/JavaAPI</a>
- *
- * @author reto, hasan
- *
- *
- */
-@Component(metatype = true, immediate = true)
-@Service(WeightedTcProvider.class)
-@Properties({
- @Property(name = "weight", intValue = 107),
- @Property(name = TcManager.GENERAL_PURPOSE_TC, boolValue = true)})
-public class TdbTcProvider implements WeightedTcProvider {
-
- static {
- //not sure what the perfomance implication of this is
- //it is only needed so that on windows the files of a dataset can be deleteds
- SystemTDB.setFileMode(FileMode.direct);
- }
- @Property(intValue = 6, description = "Specifies the number of seconds to wait "
- + "between synchronizations of the TDB datasets to the filesystem")
- public static final String SYNC_INTERVAL = "sync-interval";
- private int syncInterval = 6;
- /**
- * directory where all graphs are stored
- */
- private static final String DATA_PATH_NAME = "tdb-data/";
- private String dataPathString = DATA_PATH_NAME;
- private Map<UriRef, LockableMGraph> mGraphMap = new HashMap<UriRef, LockableMGraph>();
- private Map<UriRef, Graph> graphMap = new HashMap<UriRef, Graph>();
- private Map<File, com.hp.hpl.jena.graph.Graph> dir2JenaGraphMap = new HashMap<File, com.hp.hpl.jena.graph.Graph>();
- private Map<File, Lock> dir2Lock = new HashMap<File, Lock>();
- private final Map<File, Dataset> dir2Dataset = new HashMap<File, Dataset>();
- private static final Logger log = LoggerFactory.getLogger(TdbTcProvider.class);
- private int weight = 107;
-
- class SyncThread extends Thread {
-
- private boolean stopRequested = false;
-
- @Override
- public void run() {
- while (!stopRequested) {
- try {
- Thread.sleep(syncInterval * 1000);
- } catch (InterruptedException ex) {
- interrupt();
- }
- if (!stopRequested) {
- syncWithFileSystem();
- }
- }
- }
-
- public void requestStop() {
- stopRequested = true;
- }
- }
- private SyncThread syncThread;
-
- public TdbTcProvider() {
- }
-
- TdbTcProvider(File directory) {
- dataPathString = directory.getAbsolutePath();
- loadMGraphs();
- loadGraphs();
- }
-
- public void activate(ComponentContext cCtx) {
- log.info("Activating TDB provider");
- if (cCtx != null) {
- weight = (Integer) cCtx.getProperties().get("weight");
- dataPathString = cCtx.getBundleContext().
- getDataFile(DATA_PATH_NAME).getAbsolutePath();
- syncInterval = Integer.parseInt(cCtx.getProperties().get(SYNC_INTERVAL).toString());
- }
- loadMGraphs();
- loadGraphs();
- syncThread = new SyncThread();
- syncThread.start();
- }
-
- public void deactivate(ComponentContext cCtx) {
- syncThread.requestStop();
- syncThread = null;
- for (com.hp.hpl.jena.graph.Graph jenaGraph : dir2JenaGraphMap.values()) {
- jenaGraph.close();
- }
- synchronized (dir2Dataset) {
- for (Dataset dataset : dir2Dataset.values()) {
- dataset.close();
- }
- }
- }
-
- @Override
- public int getWeight() {
- return weight;
- }
-
- @Override
- public Graph getGraph(UriRef name) throws NoSuchEntityException {
- if (!graphMap.containsKey(name)) {
- throw new NoSuchEntityException(name);
- }
- return graphMap.get(name);
- }
-
- @Override
- public synchronized MGraph getMGraph(UriRef name) throws NoSuchEntityException {
- if (!mGraphMap.containsKey(name)) {
- throw new NoSuchEntityException(name);
- }
- return mGraphMap.get(name);
- }
-
- @Override
- public TripleCollection getTriples(UriRef name) throws NoSuchEntityException {
- try {
- return getMGraph(name);
- } catch (NoSuchEntityException e) {
- return getGraph(name);
- }
- }
-
- @Override
- public synchronized MGraph createMGraph(UriRef name)
- throws UnsupportedOperationException, EntityAlreadyExistsException {
- File tcDir = getMGraphDir(name);
- if (tcDir.exists()) {
- throw new EntityAlreadyExistsException(name);
- }
- tcDir.mkdirs();
- File otimizationIndicator = new File(tcDir, "fixed.opt");
- try {
- otimizationIndicator.createNewFile();
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- LockableMGraph result = new LockableMGraphWrapper(getMGraph(tcDir));
- dir2Lock.put(tcDir, result.getLock().writeLock());
- mGraphMap.put(name, result);
- return result;
- }
-
- @Override
- public Graph createGraph(UriRef name, TripleCollection triples)
- throws UnsupportedOperationException, EntityAlreadyExistsException {
- File tcDir = getGraphDir(name);
- if (tcDir.exists()) {
- throw new EntityAlreadyExistsException(name);
- }
-
- if (triples == null) {
- triples = new SimpleMGraph();
- }
- tcDir.mkdirs();
- File otimizationIndicator = new File(tcDir, "fixed.opt");
- try {
- otimizationIndicator.createNewFile();
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- MGraph mGraph = getMGraph(tcDir);
- mGraph.addAll(triples);
- Graph result = mGraph.getGraph();
- TDB.sync(dir2Dataset.get(tcDir));
- graphMap.put(name, result);
- return result;
- }
-
- @Override
- public void deleteTripleCollection(UriRef name)
- throws UnsupportedOperationException, NoSuchEntityException,
- EntityUndeletableException {
- syncWithFileSystem();
- if (deleteTcDir(getGraphDir(name))) {
- graphMap.remove(name);
- return;
- }
- if (deleteTcDir(getMGraphDir(name))) {
- mGraphMap.remove(name);
- return;
- }
- throw new NoSuchEntityException(name);
- }
-
- private boolean deleteTcDir(File tcDir) {
- if (tcDir.exists()) {
- dir2JenaGraphMap.get(tcDir).close();
- dir2JenaGraphMap.remove(tcDir);
- synchronized (dir2Dataset) {
- dir2Dataset.get(tcDir).close();
- dir2Dataset.remove(tcDir);
- }
- try {
- delete(tcDir);
- } catch (IOException ex) {
- for (int i = 0; i < 10; i++) {
- try {
- System.gc();
- delete(tcDir);
- } catch (IOException ex1) {
- try {
- Thread.sleep(10);
- } catch (InterruptedException ex2) {
- Thread.currentThread().interrupt();
- }
- continue;
- }
- return true;
- }
- throw new RuntimeException(ex);
- }
- return true;
- }
- return false;
- }
-
- /**
- * Cleans the content of the specified directory recursively.
- *
- * @param dir Abstract path denoting the directory to clean.
- */
- private static void cleanDirectory(File dir) throws IOException {
- File[] files = dir.listFiles();
- if (files != null && files.length > 0) {
- for (File file : files) {
- delete(file);
- }
- }
- }
-
- /**
- * Deletes the specified file or directory.
- *
- * @param file Abstract path denoting the file or directory to clean.
- */
- protected static void delete(File file) throws IOException {
- if (file.isDirectory()) {
- cleanDirectory(file);
- }
- //better but only in java 7
- //java.nio.file.Files.delete(file.toPath());
- if (!file.delete()) {
- throw new IOException("couldn't delete " + file.getAbsolutePath());
- }
- }
-
- @Override
- public Set<UriRef> getNames(Graph graph) {
- //this could be done more efficiently with an index, could be done with
- //a MultiBidiMap (BidiMap allowing multiple keys for the same value)
- Set<UriRef> result = new HashSet<UriRef>();
- for (UriRef name : listGraphs()) {
- if (getGraph(name).equals(graph)) {
- result.add(name);
- }
- }
- return result;
- }
-
- @Override
- public Set<UriRef> listTripleCollections() {
- Set<UriRef> result = new HashSet<UriRef>();
- result.addAll(listGraphs());
- result.addAll(listMGraphs());
- return result;
- }
-
- @Override
- public Set<UriRef> listGraphs() {
- return graphMap.keySet();
- }
-
- @Override
- public Set<UriRef> listMGraphs() {
- return mGraphMap.keySet();
- }
-
- private Graph getGraph(File tcDir) {
- return getMGraph(tcDir).getGraph();
- }
-
- private File getGraphDir(UriRef name) {
- File base = new File(dataPathString);
- return getTcDir(new File(base, "graph"), name);
- }
-
- private MGraph getMGraph(File tcDir) {
- Dataset dataset = TDBFactory.createDataset(tcDir.getAbsolutePath());
- Model model = dataset.getDefaultModel();
- //Model model = TDBFactory.createModel(tcDir.getAbsolutePath());
- final com.hp.hpl.jena.graph.Graph jenaGraph = model.getGraph();
- dir2JenaGraphMap.put(tcDir, jenaGraph);
- //dataset.
- synchronized (dir2Dataset) {
- dir2Dataset.put(tcDir, dataset);
- }
- return new PrivilegedMGraphWrapper(new JenaGraphAdaptor(jenaGraph));
- }
-
- private File getMGraphDir(UriRef name) {
- File base = new File(dataPathString);
- return getTcDir(new File(base, "mgraph"), name);
- }
-
- private File getTcDir(File directory, UriRef name) {
- try {
- String subDirName = URLEncoder.encode(name.getUnicodeString(), "utf-8");
- return new File(directory, subDirName);
- } catch (UnsupportedEncodingException ex) {
- throw new RuntimeException("utf-8 not supported", ex);
- }
- }
-
- private void loadGraphs() {
- File graphsDir = new File(new File(dataPathString), "graph");
- if (graphsDir.exists()) {
- for (String graphDirName : graphsDir.list()) {
- try {
- UriRef uri = new UriRef(URLDecoder.decode(graphDirName, "utf-8"));
- log.info("loading: " + graphDirName);
- graphMap.put(uri, getGraph(new File(graphsDir, graphDirName)));
- } catch (UnsupportedEncodingException ex) {
- throw new RuntimeException("utf-8 not supported", ex);
- } catch (Exception e) {
- log.error("Could not load tdb graph in " + graphDirName, e);
- }
- }
- }
- }
-
- private void loadMGraphs() {
- File mGraphsDir = new File(new File(dataPathString), "mgraph");
- if (mGraphsDir.exists()) {
- for (String mGraphDirName : mGraphsDir.list()) {
- try {
- UriRef uri = new UriRef(URLDecoder.decode(mGraphDirName, "utf-8"));
- log.info("loading: " + mGraphDirName);
- final File tcDir = new File(mGraphsDir, mGraphDirName);
- final LockableMGraphWrapper lockableMGraph = new LockableMGraphWrapper(getMGraph(tcDir));
- mGraphMap.put(uri, lockableMGraph);
- dir2Lock.put(tcDir, lockableMGraph.getLock().writeLock());
- } catch (UnsupportedEncodingException ex) {
- throw new RuntimeException("utf-8 not supported", ex);
- } catch (Exception e) {
- log.error("Could not load tdb graph in " + mGraphDirName, e);
- }
- }
- }
- }
-
- public void syncWithFileSystem() {
- synchronized (dir2Dataset) {
- for (Map.Entry<File, Dataset> entry : dir2Dataset.entrySet()) {
- Lock l = dir2Lock.get(entry.getKey());
- if (l == null) {
- return;
- }
- l.lock();
- try {
- TDB.sync(entry.getValue());
- } finally {
- l.unlock();
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider b/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
deleted file mode 100644
index 5dbaf81..0000000
--- a/rdf.jena.tdb.storage/src/main/resources/META-INF/services/org.apache.clerezza.rdf.core.access.WeightedTcProvider
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.clerezza.rdf.jena.tdb.storage.TdbTcProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/dac431ca/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
----------------------------------------------------------------------
diff --git a/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties b/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
deleted file mode 100644
index b2488eb..0000000
--- a/rdf.jena.tdb.storage/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ /dev/null
@@ -1,47 +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.
-
-# Deactivate properties for component because those are not common for Apache Clerezza
-#org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider.name=Apache Stanbol Clerezza \
-#Single Jena TDB Provider
-#org.apache.clerezza.rdf.jena.tdb.storage.SingleTdbDatasetTcProvider.description=Tc Provider \
-#implementation that stores Clerezza TripleCollections as named graphs in a single Jena \
-#TDB store.
-
-#==============================================================
-#Properties and Options used to configure TDB dataset providers
-#==============================================================
-
-tdb-dir.name=Jena TDB directory
-tdb-dir.description= The directory for Jena the TDB database. This field \
-supports property substitution: '${property}' will be replaced with the value \
-of the 'property' available via the BundleContext or the system properties \
-(e.g. "${myHome}/myRdfStore")
-default-graph-name.name=Default Graph Name
-default-graph-name.description=The URI name of the default graph of the Jena \
-TDB database. Requests to the TcProvider with this URI will return an MGraph \
-that is the union over all the graphs managed by this TcProvider. If empty or \
-not defined the default graph is not exposed.
-weight.name=Weight
-weight.description=The weight of this TcProvider. Set to an low value (e.g. \
-value < 0) if you want to inject this instance by using a Filter. Set to a high \
-value (e.g. values > 1000) if you want this instance to be the default used by \
-Clerezza.
-sync-interval.name=Sync Interval
-sync-interval.description=The interval in seconds until changes are saved to \
-the file system. Sync will always occur if this provider is deactivated. However \
-on crashes all data since the last sync will be lost. The default is 6sec. \
-Higher values will reduce the overhead for periodically writing to the file \
-system.
\ No newline at end of file