Author: rwesten
Date: Mon Aug 20 11:12:27 2012
New Revision: 1374970
URL: http://svn.apache.org/viewvc?rev=1374970&view=rev
Log:
STANBOL-704: Adding initial import for Revision Management to the Clerezza and
Jena TDB store implementations (based on the RevisionManager implementation
provided by Suat)
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml?rev=1374970&r1=1374969&r2=1374970&view=diff
==============================================================================
---
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml
(original)
+++
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml
Mon Aug 20 11:12:27 2012
@@ -93,6 +93,12 @@
<artifactId>org.apache.stanbol.commons.semanticindex.core</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</dependency>
+ <!-- TODO: this module needs to be moved to
commons.semanticindex.revisionmanager -->
+ <dependency><!-- used for managing Store epochs and revisions -->
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.revisionmanager</artifactId>
+ <version>0.10.0-incubating-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java?rev=1374970&r1=1374969&r2=1374970&view=diff
==============================================================================
---
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java
(original)
+++
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java
Mon Aug 20 11:12:27 2012
@@ -34,11 +34,14 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Reference;
import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
import org.apache.stanbol.commons.ldpath.clerezza.ClerezzaBackend;
+import org.apache.stanbol.commons.semanticindex.core.store.ChangeSetImpl;
import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
import org.apache.stanbol.commons.semanticindex.store.EpochException;
import org.apache.stanbol.commons.semanticindex.store.IndexingSource;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
+import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
+import org.apache.stanbol.enhancer.servicesapi.ContentItem;
import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
import org.apache.stanbol.entityhub.servicesapi.model.Representation;
@@ -94,6 +97,9 @@ public class ClerezzaStore extends Clere
public static final String PROPERTY_GRAPH_URI =
"org.apache.stanbol.entityhub.store.clerezza.graphuri";
@Reference
private TcManager tcManager;
+
+ @Reference
+ private RevisionManager revisionManager;
private TripleCollection graph;
@@ -108,9 +114,26 @@ public class ClerezzaStore extends Clere
* method
*/
private Map<String,Object> properties;
+ /**
+ * Default Constructor used by OSGI
+ */
+ public ClerezzaStore(){}
+
+// /**
+// * Constructor intended to be used for unit testing
+// * @param name
+// * @param grpah
+// * @param revManager
+// */
+// protected ClerezzaStore(String name, TripleCollection graph,
RevisionManager revManager){
+// this.name = name;
+// this.description = null;
+// this.graph = graph;
+// this.revisionManager = revManager;
+// }
@Activate
- protected final void activate(ComponentContext context) throws
ConfigurationException {
+ protected final void activate(ComponentContext context) throws
ConfigurationException, StoreException {
Object value = context.getProperties().get(PROPERTY_NAME);
Map<String,Object> properties = new HashMap<String,Object>();
if(value == null || value.toString().isEmpty()){
@@ -173,6 +196,13 @@ public class ClerezzaStore extends Clere
log.info("Activate {} '{}' with grpah URI {}");
properties.put(PROPERTY_ITEM_TYPE, Representation.class);
this.properties = Collections.unmodifiableMap(properties);
+
+ //initialize the Revision manager
+ revisionManager.initializeRevisionTables(this);
+ //TODO: we should sync the revisions with the actual data of the Graph
+ // currently this assumes an empty Graph AND that all
modifications
+ // are done via the Store interface
+
}
@Deactivate
@@ -221,16 +251,19 @@ public class ClerezzaStore extends Clere
}
@Override
- public long getEpoch() {
- // TODO implement
- throw new UnsupportedOperationException("TODO: implement!!");
+ public long getEpoch() throws StoreException {
+ return revisionManager.getEpoch(this);
}
@Override
public ChangeSet<Representation> changes(long epoch, long revision,
int batchSize) throws StoreException, EpochException {
- // TODO implement
- throw new UnsupportedOperationException("TODO: implement!!");
+ if (getEpoch() != epoch) {
+ throw new EpochException(this, getEpoch(), epoch);
+ }
+ ChangeSet<Representation> changesSet = (ChangeSetImpl<Representation>)
+ revisionManager.getChanges(this,revision, batchSize);
+ return changesSet;
}
@Override
@@ -252,7 +285,11 @@ public class ClerezzaStore extends Clere
log.debug("put Representation " + representation.getId());
final Lock writeLock = writeLockGraph();
try {
- return add(representation);
+ //update Revision first to block changes on exceptions in the
+ //revisionManager
+ revisionManager.updateRevision(this,
representation.getId());
+ String id = add(representation);
+ return id;
} finally {
writeLock.unlock();
}
@@ -266,6 +303,12 @@ public class ClerezzaStore extends Clere
try {
//remove all existing
for(Representation item : items){
+ //update Revision first to block changes on exceptions
in the
+ //revisionManager
+ //NOTE: we need also to update the revision if
the item does
+ // not yet exist in the store
(removeResource returns false)
+ // as the new revision will be used for
the added item
+ revisionManager.updateRevision(this,
item.getId());
removeResource(new UriRef(item.getId()));
}
//add all parsed
@@ -296,6 +339,7 @@ public class ClerezzaStore extends Clere
public void removeAll() throws StoreException {
final Lock writeLock = writeLockGraph();
try {
+ revisionManager.updateEpoch(this);
graph.clear();
} finally {
writeLock.unlock();
@@ -331,11 +375,16 @@ public class ClerezzaStore extends Clere
* This method assumes a read lock on {@link #graph}
* @param resource
* @return
+ * @throws StoreException if the {@link #revisionManager} is unable to
+ * update the revision
*/
- private boolean removeResource(UriRef resource) {
+ private boolean removeResource(UriRef resource) throws StoreException {
Iterator<Triple> current = graph.filter(resource, null, null);
Set<BNode> bNodes = new HashSet<BNode>();
boolean contains = current.hasNext();
+ if(contains){
+ revisionManager.updateRevision(this,
resource.getUnicodeString());
+ }
while(current.hasNext()){ //delete current
Triple t = current.next();
current.remove();
@@ -394,7 +443,7 @@ public class ClerezzaStore extends Clere
* adds triples for {@link BNode}s that are {@link Triple#getObject()}s
of
* added triples.
* <p>
- * This method assumes a read lock on {@link #graph}
+ * This method assumes a write lock on {@link #graph}
* @param source the source graph
* @param resource the resource to add
*/
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml?rev=1374970&r1=1374969&r2=1374970&view=diff
==============================================================================
---
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml
(original)
+++
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml
Mon Aug 20 11:12:27 2012
@@ -105,6 +105,12 @@
<artifactId>org.apache.stanbol.commons.semanticindex.core</artifactId>
<version>0.10.0-incubating-SNAPSHOT</version>
</dependency>
+ <!-- TODO: this module needs to be moved to
commons.semanticindex.revisionmanager -->
+ <dependency><!-- used for managing Store epochs and revisions -->
+ <groupId>org.apache.stanbol</groupId>
+ <artifactId>org.apache.stanbol.contenthub.revisionmanager</artifactId>
+ <version>0.10.0-incubating-SNAPSHOT</version>
+ </dependency>
<!-- Stanbol Entityhub internal dependencies -->
<dependency>
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java?rev=1374970&r1=1374969&r2=1374970&view=diff
==============================================================================
---
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java
(original)
+++
incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java
Mon Aug 20 11:12:27 2012
@@ -21,11 +21,13 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
+import org.apache.stanbol.commons.semanticindex.core.store.ChangeSetImpl;
import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
import org.apache.stanbol.commons.semanticindex.store.EpochException;
import org.apache.stanbol.commons.semanticindex.store.IndexingSource;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
+import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
import org.apache.stanbol.entityhub.core.utils.TimeUtils;
import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
@@ -118,6 +120,10 @@ public class JenaTdbStore extends Abstra
* typed literals.
*/
private TypeMapper typeMapper = TypeMapper.getInstance();
+
+ @org.apache.felix.scr.annotations.Reference
+ private RevisionManager revisionManager;
+
private Dataset dataset;
private String name;
private String description;
@@ -130,7 +136,7 @@ public class JenaTdbStore extends Abstra
private Node namedGraphNode;
@Activate
- protected final void activate(ComponentContext context) throws
ConfigurationException {
+ protected final void activate(ComponentContext context) throws
ConfigurationException, StoreException {
Object value = context.getProperties().get(PROPERTY_NAME);
Map<String,Object> properties = new HashMap<String,Object>();
if(value == null || value.toString().isEmpty()){
@@ -223,6 +229,10 @@ public class JenaTdbStore extends Abstra
dataset.getLock().leaveCriticalSection();
}
this.properties = Collections.unmodifiableMap(properties);
+ revisionManager.initializeRevisionTables(this);
+ //TODO: we need to register existing data with the revision
manager
+ // on the first start-up. Currently this works only with an
+ // empty RDF Graph
}
@Deactivate
@@ -294,16 +304,19 @@ public class JenaTdbStore extends Abstra
}
@Override
- public long getEpoch() {
- // TODO not yet implemented
- throw new UnsupportedOperationException("TODO: implement!!");
+ public long getEpoch() throws StoreException {
+ return revisionManager.getEpoch(this);
}
@Override
public ChangeSet<Representation> changes(long epoch, long revision, int
batchSize)
throws StoreException, EpochException {
- // TODO not yet implemented
- throw new UnsupportedOperationException("TODO: implement!!");
+ if (getEpoch() != epoch) {
+ throw new EpochException(this, getEpoch(), epoch);
+ }
+ ChangeSet<Representation> changesSet = (ChangeSetImpl<Representation>)
+ revisionManager.getChanges(this, revision, batchSize);
+ return changesSet;
}
@Override
@@ -311,6 +324,7 @@ public class JenaTdbStore extends Abstra
dataset.getLock().enterCriticalSection(false);
try {
Node node = Node.createURI(item.getId());
+ revisionManager.updateRevision(this, item.getId());
removeResource(node); //remove the old data
addResource(item); //add the new data
} finally {
@@ -345,6 +359,7 @@ public class JenaTdbStore extends Abstra
for(Representation item : items){
try {
Node node =
Node.createURI(item.getId());
+ revisionManager.updateRevision(this,
item.getId());
removeResource(node); //remove the old
data
addResource(item); //add the new data
added.add(item.getId());
@@ -550,10 +565,13 @@ public class JenaTdbStore extends Abstra
* @param resource
* @return
*/
- private boolean removeResource(Node resource) {
+ private boolean removeResource(Node resource) throws StoreException {
ExtendedIterator<Triple> current = graph.find(resource, null,
null);
Set<Node> bNodes = new HashSet<Node>();
boolean contains = current.hasNext();
+ if(contains){
+ revisionManager.updateRevision(this,
resource.toString());
+ }
while(current.hasNext()){ //delete current
Node obj = current.removeNext().getObject();
if(obj.isBlank()){