mirror of
https://github.com/JHUAPL/AccumuloGraph.git
synced 2026-01-09 12:47:56 -05:00
Several updates
Created key index metadata wrapper and moved some functionality there Changed Mutator to an interface rather than abstract class
This commit is contained in:
@@ -59,6 +59,7 @@ import com.tinkerpop.blueprints.util.StringFactory;
|
||||
import edu.jhuapl.tinkerpop.cache.ElementCaches;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutators;
|
||||
import edu.jhuapl.tinkerpop.tables.EdgeTableWrapper;
|
||||
import edu.jhuapl.tinkerpop.tables.KeyMetadataTableWrapper;
|
||||
import edu.jhuapl.tinkerpop.tables.VertexTableWrapper;
|
||||
|
||||
/**
|
||||
@@ -170,6 +171,7 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
|
||||
globals.setVertexWrapper(new VertexTableWrapper(globals));
|
||||
globals.setEdgeWrapper(new EdgeTableWrapper(globals));
|
||||
globals.setKeyMetadataWrapper(new KeyMetadataTableWrapper(globals));
|
||||
|
||||
try {
|
||||
setupWriters();
|
||||
@@ -888,19 +890,17 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
throw ExceptionFactory.classForElementCannotBeNull();
|
||||
}
|
||||
|
||||
globals.getKeyMetadataWrapper().clearKeyMetadataEntry(key, elementClass);
|
||||
|
||||
String table = null;
|
||||
if (elementClass.equals(Vertex.class)) {
|
||||
table = config.getVertexKeyIndexTableName();
|
||||
} else {
|
||||
table = config.getEdgeKeyIndexTableName();
|
||||
}
|
||||
BatchWriter w = getKeyMetadataWriter();
|
||||
BatchDeleter bd = null;
|
||||
Mutation m = new Mutation(key);
|
||||
m.putDelete(elementClass.getSimpleName().getBytes(), Constants.EMPTY);
|
||||
try {
|
||||
bd = config.getConnector().createBatchDeleter(table, config.getAuthorizations(), config.getMaxWriteThreads(), config.getBatchWriterConfig());
|
||||
w.addMutation(m);
|
||||
bd.setRanges(Collections.singleton(new Range()));
|
||||
bd.fetchColumnFamily(new Text(key));
|
||||
bd.delete();
|
||||
@@ -919,16 +919,10 @@ public class AccumuloGraph implements Graph, KeyIndexableGraph, IndexableGraph {
|
||||
if (elementClass == null) {
|
||||
throw ExceptionFactory.classForElementCannotBeNull();
|
||||
}
|
||||
BatchWriter w = getKeyMetadataWriter();
|
||||
|
||||
Mutation m = new Mutation(key);
|
||||
m.put(elementClass.getSimpleName().getBytes(), Constants.EMPTY, Constants.EMPTY);
|
||||
try {
|
||||
w.addMutation(m);
|
||||
} catch (MutationsRejectedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
globals.getKeyMetadataWrapper().writeKeyMetadataEntry(key, elementClass);
|
||||
checkedFlush();
|
||||
|
||||
// Re Index Graph
|
||||
BatchScanner scan = getElementBatchScanner(elementClass);
|
||||
try {
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.tinkerpop.blueprints.Vertex;
|
||||
import edu.jhuapl.tinkerpop.cache.ElementCaches;
|
||||
import edu.jhuapl.tinkerpop.tables.EdgeTableWrapper;
|
||||
import edu.jhuapl.tinkerpop.tables.ElementTableWrapper;
|
||||
import edu.jhuapl.tinkerpop.tables.KeyMetadataTableWrapper;
|
||||
import edu.jhuapl.tinkerpop.tables.VertexTableWrapper;
|
||||
|
||||
/**
|
||||
@@ -37,6 +38,7 @@ public class GlobalInstances {
|
||||
private final MultiTableBatchWriter mtbw;
|
||||
private VertexTableWrapper vertexWrapper;
|
||||
private EdgeTableWrapper edgeWrapper;
|
||||
private KeyMetadataTableWrapper keyMetadataWrapper;
|
||||
private final ElementCaches caches;
|
||||
|
||||
public GlobalInstances(AccumuloGraph graph,
|
||||
@@ -68,6 +70,10 @@ public class GlobalInstances {
|
||||
return edgeWrapper;
|
||||
}
|
||||
|
||||
public KeyMetadataTableWrapper getKeyMetadataWrapper() {
|
||||
return keyMetadataWrapper;
|
||||
}
|
||||
|
||||
public <T extends Element> ElementTableWrapper getElementWrapper(Class<T> clazz) {
|
||||
if (Vertex.class.equals(clazz)) {
|
||||
return vertexWrapper;
|
||||
@@ -97,19 +103,28 @@ public class GlobalInstances {
|
||||
|
||||
/**
|
||||
* TODO: Refactor these away when the {@link #graph} member is gone.
|
||||
* @param vertexWrapper
|
||||
* @param wrapper
|
||||
*/
|
||||
@Deprecated
|
||||
public void setVertexWrapper(VertexTableWrapper vertexWrapper) {
|
||||
this.vertexWrapper = vertexWrapper;
|
||||
public void setVertexWrapper(VertexTableWrapper wrapper) {
|
||||
this.vertexWrapper = wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Refactor these away when the {@link #graph} member is gone.
|
||||
* @param vertexWrapper
|
||||
* @param wrapper
|
||||
*/
|
||||
@Deprecated
|
||||
public void setEdgeWrapper(EdgeTableWrapper edgeWrapper) {
|
||||
this.edgeWrapper = edgeWrapper;
|
||||
public void setEdgeWrapper(EdgeTableWrapper wrapper) {
|
||||
this.edgeWrapper = wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Refactor these away when the {@link #graph} member is gone.
|
||||
* @param wrapper
|
||||
*/
|
||||
@Deprecated
|
||||
public void setKeyMetadataWrapper(KeyMetadataTableWrapper wrapper) {
|
||||
this.keyMetadataWrapper = wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ package edu.jhuapl.tinkerpop.mutator;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
public abstract class BaseMutator {
|
||||
public interface Mutator {
|
||||
|
||||
public abstract Iterable<Mutation> create();
|
||||
public Iterable<Mutation> create();
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
|
||||
public class Mutators {
|
||||
|
||||
public static void apply(BatchWriter writer, BaseMutator mut) {
|
||||
public static void apply(BatchWriter writer, Mutator mut) {
|
||||
try {
|
||||
writer.addMutations(mut.create());
|
||||
} catch (MutationsRejectedException e) {
|
||||
|
||||
@@ -16,9 +16,9 @@ package edu.jhuapl.tinkerpop.mutator.edge;
|
||||
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.mutator.BaseMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutator;
|
||||
|
||||
public abstract class BaseEdgeMutator extends BaseMutator {
|
||||
public abstract class BaseEdgeMutator implements Mutator {
|
||||
|
||||
protected final Edge edge;
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop.mutator.index;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
import edu.jhuapl.tinkerpop.Constants;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutator;
|
||||
|
||||
/**
|
||||
* Add/delete entries for key index metadata.
|
||||
*/
|
||||
public class KeyIndexMetadataMutator {
|
||||
|
||||
private KeyIndexMetadataMutator() { }
|
||||
|
||||
public static class Add implements Mutator {
|
||||
|
||||
private String key;
|
||||
private Class<? extends Element> clazz;
|
||||
|
||||
public Add(String key, Class<? extends Element> clazz) {
|
||||
this.key = key;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Mutation> create() {
|
||||
Mutation m = new Mutation(key);
|
||||
m.put(clazz.getSimpleName().getBytes(),
|
||||
Constants.EMPTY, Constants.EMPTY);
|
||||
return Lists.newArrayList(m);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Delete implements Mutator {
|
||||
|
||||
private String key;
|
||||
private Class<? extends Element> clazz;
|
||||
|
||||
public Delete(String key, Class<? extends Element> clazz) {
|
||||
this.key = key;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Mutation> create() {
|
||||
Mutation m = new Mutation(key);
|
||||
m.putDelete(clazz.getSimpleName().getBytes(), Constants.EMPTY);
|
||||
return Lists.newArrayList(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,9 @@ package edu.jhuapl.tinkerpop.mutator.property;
|
||||
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
import edu.jhuapl.tinkerpop.mutator.BaseMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutator;
|
||||
|
||||
public abstract class BasePropertyMutator extends BaseMutator {
|
||||
public abstract class BasePropertyMutator implements Mutator {
|
||||
|
||||
protected Element element;
|
||||
protected String key;
|
||||
|
||||
@@ -16,9 +16,9 @@ package edu.jhuapl.tinkerpop.mutator.vertex;
|
||||
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.mutator.BaseMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutator;
|
||||
|
||||
public abstract class BaseVertexMutator extends BaseMutator {
|
||||
public abstract class BaseVertexMutator implements Mutator {
|
||||
|
||||
protected final Vertex vertex;
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package edu.jhuapl.tinkerpop.tables;
|
||||
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
import edu.jhuapl.tinkerpop.GlobalInstances;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutators;
|
||||
import edu.jhuapl.tinkerpop.mutator.index.KeyIndexMetadataMutator;
|
||||
|
||||
/**
|
||||
* Wraps the metadata tables which stores information
|
||||
* about which property keys are indexed for different
|
||||
* graph types.
|
||||
*/
|
||||
public class KeyMetadataTableWrapper extends BaseTableWrapper {
|
||||
|
||||
public KeyMetadataTableWrapper(GlobalInstances globals) {
|
||||
super(globals, globals.getConfig().getKeyMetadataTableName());
|
||||
}
|
||||
|
||||
public void writeKeyMetadataEntry(String key, Class<? extends Element> clazz) {
|
||||
Mutators.apply(getWriter(), new KeyIndexMetadataMutator.Add(key, clazz));
|
||||
}
|
||||
|
||||
public void clearKeyMetadataEntry(String key, Class<? extends Element> clazz) {
|
||||
Mutators.apply(getWriter(), new KeyIndexMetadataMutator.Delete(key, clazz));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user