mirror of
https://github.com/JHUAPL/AccumuloGraph.git
synced 2026-01-09 12:47:56 -05:00
Initial commits for effort to genericize mutators based on graph operations
This commit is contained in:
19
src/main/java/edu/jhuapl/tinkerpop/mutator/BaseMutator.java
Normal file
19
src/main/java/edu/jhuapl/tinkerpop/mutator/BaseMutator.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/******************************************************************************
|
||||
* COPYRIGHT NOTICE *
|
||||
* Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This material may only be used, modified, or reproduced by or for the *
|
||||
* U.S. Government pursuant to the license rights granted under FAR clause *
|
||||
* 52.227-14 or DFARS clauses 252.227-7013/7014. *
|
||||
* *
|
||||
* For any other permissions, please contact the Legal Office at JHU/APL. *
|
||||
******************************************************************************/
|
||||
package edu.jhuapl.tinkerpop.mutator;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
public abstract class BaseMutator {
|
||||
|
||||
public abstract Iterable<Mutation> create();
|
||||
}
|
||||
28
src/main/java/edu/jhuapl/tinkerpop/mutator/Mutators.java
Normal file
28
src/main/java/edu/jhuapl/tinkerpop/mutator/Mutators.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/******************************************************************************
|
||||
* COPYRIGHT NOTICE *
|
||||
* Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This material may only be used, modified, or reproduced by or for the *
|
||||
* U.S. Government pursuant to the license rights granted under FAR clause *
|
||||
* 52.227-14 or DFARS clauses 252.227-7013/7014. *
|
||||
* *
|
||||
* For any other permissions, please contact the Legal Office at JHU/APL. *
|
||||
******************************************************************************/
|
||||
package edu.jhuapl.tinkerpop.mutator;
|
||||
|
||||
import org.apache.accumulo.core.client.BatchWriter;
|
||||
import org.apache.accumulo.core.client.MutationsRejectedException;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
|
||||
public class Mutators {
|
||||
|
||||
public static void apply(BatchWriter writer, BaseMutator mut) {
|
||||
try {
|
||||
writer.addMutations(mut.create());
|
||||
} catch (MutationsRejectedException e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.edge;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public class AddEdgeEndpointsMutator extends BaseEdgeMutator {
|
||||
|
||||
public AddEdgeEndpointsMutator(Edge edge) {
|
||||
super(edge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Mutation> create() {
|
||||
String inVertexId = edge.getVertex(Direction.IN).getId().toString();
|
||||
String outVertexId = edge.getVertex(Direction.OUT).getId().toString();
|
||||
|
||||
Mutation mIn = new Mutation(inVertexId);
|
||||
mIn.put(AccumuloGraph.INEDGE,
|
||||
(outVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes(),
|
||||
(AccumuloGraph.IDDELIM + edge.getLabel()).getBytes());
|
||||
|
||||
Mutation mOut = new Mutation(outVertexId);
|
||||
mOut.put(AccumuloGraph.OUTEDGE,
|
||||
(inVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes(),
|
||||
(AccumuloGraph.IDDELIM + edge.getLabel()).getBytes());
|
||||
|
||||
return Lists.newArrayList(mIn, mOut);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/******************************************************************************
|
||||
* COPYRIGHT NOTICE *
|
||||
* Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This material may only be used, modified, or reproduced by or for the *
|
||||
* U.S. Government pursuant to the license rights granted under FAR clause *
|
||||
* 52.227-14 or DFARS clauses 252.227-7013/7014. *
|
||||
* *
|
||||
* For any other permissions, please contact the Legal Office at JHU/APL. *
|
||||
******************************************************************************/
|
||||
package edu.jhuapl.tinkerpop.mutator.edge;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public class AddEdgeMutator extends BaseEdgeMutator {
|
||||
|
||||
public AddEdgeMutator(Edge edge) {
|
||||
super(edge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Mutation> create() {
|
||||
String inVertexId = edge.getVertex(Direction.IN).getId().toString();
|
||||
String outVertexId = edge.getVertex(Direction.OUT).getId().toString();
|
||||
|
||||
Mutation m = new Mutation(edge.getId().toString());
|
||||
|
||||
String cq = inVertexId + AccumuloGraph.IDDELIM + outVertexId;
|
||||
m.put(AccumuloGraph.LABEL, cq.getBytes(),
|
||||
AccumuloByteSerializer.serialize(edge.getLabel()));
|
||||
return Lists.newArrayList(m);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.edge;
|
||||
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.mutator.BaseMutator;
|
||||
|
||||
public abstract class BaseEdgeMutator extends BaseMutator {
|
||||
|
||||
protected final Edge edge;
|
||||
|
||||
public BaseEdgeMutator(Edge edge) {
|
||||
this.edge = edge;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.property;
|
||||
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
import edu.jhuapl.tinkerpop.mutator.BaseMutator;
|
||||
|
||||
public abstract class BasePropertyMutator extends BaseMutator {
|
||||
|
||||
protected Element element;
|
||||
protected String key;
|
||||
|
||||
public BasePropertyMutator(Element element, String key) {
|
||||
this.element = element;
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.property;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public class ClearPropertyMutator extends BasePropertyMutator {
|
||||
|
||||
public ClearPropertyMutator(Element element, String key) {
|
||||
super(element, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Mutation> create() {
|
||||
Mutation m = new Mutation(element.getId().toString());
|
||||
m.putDelete(key.getBytes(), AccumuloGraph.EMPTY);
|
||||
return Lists.newArrayList(m);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package edu.jhuapl.tinkerpop.mutator.property;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Element;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public class WritePropertyMutator extends BasePropertyMutator {
|
||||
|
||||
private Object value;
|
||||
|
||||
public WritePropertyMutator(Element element, String key, Object value) {
|
||||
super(element, key);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Mutation> create() {
|
||||
byte[] bytes = AccumuloByteSerializer.serialize(value);
|
||||
Mutation m = new Mutation(element.getId().toString());
|
||||
m.put(key.getBytes(), AccumuloGraph.EMPTY, bytes);
|
||||
return Lists.newArrayList(m);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/******************************************************************************
|
||||
* COPYRIGHT NOTICE *
|
||||
* Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This material may only be used, modified, or reproduced by or for the *
|
||||
* U.S. Government pursuant to the license rights granted under FAR clause *
|
||||
* 52.227-14 or DFARS clauses 252.227-7013/7014. *
|
||||
* *
|
||||
* For any other permissions, please contact the Legal Office at JHU/APL. *
|
||||
******************************************************************************/
|
||||
package edu.jhuapl.tinkerpop.mutator.vertex;
|
||||
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
|
||||
public class AddVertexMutator extends BaseVertexMutator {
|
||||
|
||||
public AddVertexMutator(Vertex vertex) {
|
||||
super(vertex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Mutation> create() {
|
||||
Mutation m = new Mutation((String) vertex.getId());
|
||||
m.put(AccumuloGraph.LABEL, AccumuloGraph.EXISTS, AccumuloGraph.EMPTY);
|
||||
return Lists.newArrayList(m);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/******************************************************************************
|
||||
* COPYRIGHT NOTICE *
|
||||
* Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory *
|
||||
* All rights reserved. *
|
||||
* *
|
||||
* This material may only be used, modified, or reproduced by or for the *
|
||||
* U.S. Government pursuant to the license rights granted under FAR clause *
|
||||
* 52.227-14 or DFARS clauses 252.227-7013/7014. *
|
||||
* *
|
||||
* For any other permissions, please contact the Legal Office at JHU/APL. *
|
||||
******************************************************************************/
|
||||
package edu.jhuapl.tinkerpop.mutator.vertex;
|
||||
|
||||
import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.mutator.BaseMutator;
|
||||
|
||||
public abstract class BaseVertexMutator extends BaseMutator {
|
||||
|
||||
protected final Vertex vertex;
|
||||
|
||||
public BaseVertexMutator(Vertex vertex) {
|
||||
this.vertex = vertex;
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,11 @@
|
||||
******************************************************************************/
|
||||
package edu.jhuapl.tinkerpop.tables;
|
||||
|
||||
import org.apache.accumulo.core.client.MutationsRejectedException;
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
|
||||
import com.tinkerpop.blueprints.Direction;
|
||||
import com.tinkerpop.blueprints.Edge;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
import edu.jhuapl.tinkerpop.GlobalInstances;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutators;
|
||||
import edu.jhuapl.tinkerpop.mutator.edge.AddEdgeMutator;
|
||||
|
||||
|
||||
/**
|
||||
@@ -45,18 +40,6 @@ public class EdgeTableWrapper extends ElementTableWrapper {
|
||||
* @param label
|
||||
*/
|
||||
public void writeEdge(Edge edge) {
|
||||
String inVertexId = edge.getVertex(Direction.IN).getId().toString();
|
||||
String outVertexId = edge.getVertex(Direction.OUT).getId().toString();
|
||||
|
||||
try {
|
||||
Mutation m = new Mutation(edge.getId().toString());
|
||||
|
||||
String cq = inVertexId + AccumuloGraph.IDDELIM + outVertexId;
|
||||
m.put(AccumuloGraph.LABEL, cq.getBytes(),
|
||||
AccumuloByteSerializer.serialize(edge.getLabel()));
|
||||
getWriter().addMutation(m);
|
||||
} catch (MutationsRejectedException e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
Mutators.apply(getWriter(), new AddEdgeMutator(edge));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,8 @@ import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.client.MutationsRejectedException;
|
||||
import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.user.RegExFilter;
|
||||
@@ -33,8 +31,10 @@ import com.tinkerpop.blueprints.util.StringFactory;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloByteSerializer;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
import edu.jhuapl.tinkerpop.GlobalInstances;
|
||||
import edu.jhuapl.tinkerpop.mutator.property.ClearPropertyMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.property.WritePropertyMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutators;
|
||||
|
||||
/**
|
||||
* Wrapper around tables with operations
|
||||
@@ -170,14 +170,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
* @param key
|
||||
*/
|
||||
public void clearProperty(Element element, String key) {
|
||||
try {
|
||||
Mutation m = new Mutation(element.getId().toString());
|
||||
m.putDelete(key.getBytes(), AccumuloGraph.EMPTY);
|
||||
getWriter().addMutation(m);
|
||||
|
||||
} catch (MutationsRejectedException e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
Mutators.apply(getWriter(), new ClearPropertyMutator(element, key));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,14 +180,8 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
* @param value
|
||||
*/
|
||||
public void writeProperty(Element element, String key, Object value) {
|
||||
byte[] bytes = AccumuloByteSerializer.serialize(value);
|
||||
Mutation m = new Mutation(element.getId().toString());
|
||||
m.put(key.getBytes(), AccumuloGraph.EMPTY, bytes);
|
||||
try {
|
||||
getWriter().addMutation(m);
|
||||
} catch (MutationsRejectedException e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
Mutators.apply(getWriter(),
|
||||
new WritePropertyMutator(element, key, value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,8 +199,7 @@ public abstract class ElementTableWrapper extends BaseTableWrapper {
|
||||
}
|
||||
|
||||
IteratorSetting is = new IteratorSetting(10, "edgeValueFilter", RegExFilter.class);
|
||||
RegExFilter.setRegexs(is, null, null, null,
|
||||
regex.toString(), false);
|
||||
RegExFilter.setRegexs(is, null, null, null, regex.toString(), false);
|
||||
scan.addScanIterator(is);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,8 @@ package edu.jhuapl.tinkerpop.tables;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.accumulo.core.client.MutationsRejectedException;
|
||||
import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.util.PeekingIterator;
|
||||
@@ -27,9 +25,11 @@ import com.tinkerpop.blueprints.Vertex;
|
||||
|
||||
import edu.jhuapl.tinkerpop.AccumuloEdge;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraph;
|
||||
import edu.jhuapl.tinkerpop.AccumuloGraphException;
|
||||
import edu.jhuapl.tinkerpop.GlobalInstances;
|
||||
import edu.jhuapl.tinkerpop.ScannerIterable;
|
||||
import edu.jhuapl.tinkerpop.mutator.vertex.AddVertexMutator;
|
||||
import edu.jhuapl.tinkerpop.mutator.Mutators;
|
||||
import edu.jhuapl.tinkerpop.mutator.edge.AddEdgeEndpointsMutator;
|
||||
|
||||
|
||||
/**
|
||||
@@ -47,13 +47,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
|
||||
* @param id
|
||||
*/
|
||||
public void writeVertex(Vertex vertex) {
|
||||
Mutation m = new Mutation((String) vertex.getId());
|
||||
m.put(AccumuloGraph.LABEL, AccumuloGraph.EXISTS, AccumuloGraph.EMPTY);
|
||||
try {
|
||||
getWriter().addMutation(m);
|
||||
} catch (MutationsRejectedException e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
Mutators.apply(getWriter(), new AddVertexMutator(vertex));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,24 +58,7 @@ public class VertexTableWrapper extends ElementTableWrapper {
|
||||
* @param label
|
||||
*/
|
||||
public void writeEdgeEndpoints(Edge edge) {
|
||||
String inVertexId = edge.getVertex(Direction.IN).getId().toString();
|
||||
String outVertexId = edge.getVertex(Direction.OUT).getId().toString();
|
||||
try {
|
||||
Mutation m = new Mutation(inVertexId);
|
||||
m.put(AccumuloGraph.INEDGE,
|
||||
(outVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes(),
|
||||
(AccumuloGraph.IDDELIM + edge.getLabel()).getBytes());
|
||||
getWriter().addMutation(m);
|
||||
|
||||
m = new Mutation(outVertexId);
|
||||
m.put(AccumuloGraph.OUTEDGE,
|
||||
(inVertexId + AccumuloGraph.IDDELIM + edge.getId()).getBytes(),
|
||||
(AccumuloGraph.IDDELIM + edge.getLabel()).getBytes());
|
||||
getWriter().addMutation(m);
|
||||
|
||||
} catch (MutationsRejectedException e) {
|
||||
throw new AccumuloGraphException(e);
|
||||
}
|
||||
Mutators.apply(getWriter(), new AddEdgeEndpointsMutator(edge));
|
||||
}
|
||||
|
||||
public Iterable<Edge> getEdges(String vertexId, Direction direction,
|
||||
|
||||
Reference in New Issue
Block a user