├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── changelog
├── pom.xml
├── src
├── main
│ ├── java
│ │ └── edu
│ │ │ └── jhuapl
│ │ │ └── tinkerpop
│ │ │ ├── AccumuloBulkIngester.java
│ │ │ ├── AccumuloByteSerializer.java
│ │ │ ├── AccumuloEdge.java
│ │ │ ├── AccumuloElement.java
│ │ │ ├── AccumuloFeatures.java
│ │ │ ├── AccumuloGraph.java
│ │ │ ├── AccumuloGraphConfiguration.java
│ │ │ ├── AccumuloGraphException.java
│ │ │ ├── AccumuloGraphUtils.java
│ │ │ ├── AccumuloIndex.java
│ │ │ ├── AccumuloRexsterGraphConfiguration.java
│ │ │ ├── AccumuloVertex.java
│ │ │ ├── Constants.java
│ │ │ ├── GlobalInstances.java
│ │ │ ├── ScannerIterable.java
│ │ │ ├── cache
│ │ │ ├── ElementCache.java
│ │ │ ├── ElementCaches.java
│ │ │ └── PropertyCache.java
│ │ │ ├── mapreduce
│ │ │ ├── EdgeInputFormat.java
│ │ │ ├── ElementOutputFormat.java
│ │ │ ├── MapReduceEdge.java
│ │ │ ├── MapReduceElement.java
│ │ │ ├── MapReduceVertex.java
│ │ │ └── VertexInputFormat.java
│ │ │ ├── mutator
│ │ │ ├── Mutator.java
│ │ │ ├── Mutators.java
│ │ │ ├── edge
│ │ │ │ ├── BaseEdgeMutator.java
│ │ │ │ ├── EdgeEndpointsMutator.java
│ │ │ │ └── EdgeMutator.java
│ │ │ ├── index
│ │ │ │ ├── IndexMetadataMutator.java
│ │ │ │ └── IndexValueMutator.java
│ │ │ ├── property
│ │ │ │ ├── BasePropertyMutator.java
│ │ │ │ ├── ClearPropertyMutator.java
│ │ │ │ └── WritePropertyMutator.java
│ │ │ └── vertex
│ │ │ │ └── AddVertexMutator.java
│ │ │ ├── parser
│ │ │ ├── EdgeIndexParser.java
│ │ │ ├── EdgeParser.java
│ │ │ ├── ElementIndexParser.java
│ │ │ ├── ElementParser.java
│ │ │ ├── EntryParser.java
│ │ │ ├── IndexedItem.java
│ │ │ ├── IndexedItemsListParser.java
│ │ │ ├── PropertyParser.java
│ │ │ ├── VertexIndexParser.java
│ │ │ └── VertexParser.java
│ │ │ └── tables
│ │ │ ├── BaseTableWrapper.java
│ │ │ ├── core
│ │ │ ├── EdgeTableWrapper.java
│ │ │ ├── ElementTableWrapper.java
│ │ │ └── VertexTableWrapper.java
│ │ │ └── index
│ │ │ ├── BaseIndexValuesTableWrapper.java
│ │ │ ├── BaseKeyIndexTableWrapper.java
│ │ │ ├── EdgeKeyIndexTableWrapper.java
│ │ │ ├── IndexMetadataTableWrapper.java
│ │ │ ├── NamedIndexTableWrapper.java
│ │ │ └── VertexKeyIndexTableWrapper.java
│ └── resources
│ │ ├── eclipse-codestyle.xml
│ │ └── log4j.properties
└── test
│ └── java
│ └── edu
│ └── jhuapl
│ └── tinkerpop
│ ├── AccumuloBulkIngesterTest.java
│ ├── AccumuloElementTest.java
│ ├── AccumuloGraphConfigurationTest.java
│ ├── AccumuloGraphTest.java
│ ├── AccumuloGraphTestUtils.java
│ ├── AutoIndexTest.java
│ ├── DistributedInstanceTest.java
│ ├── ElementCacheTest.java
│ ├── ElementPropertyCachingTest.java
│ ├── ExtendedAccumuloGraphTest.java
│ ├── ExtendedElementTest.java
│ ├── MockInstanceTest.java
│ ├── PropertyCacheTest.java
│ └── mapreduce
│ ├── ElementOutputFormatTest.java
│ └── InputFormatsTest.java
└── table-structure.md
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .settings/
3 | .classpath
4 | .project
5 | /target/
6 | *.swp
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - openjdk7
4 |
5 |
--------------------------------------------------------------------------------
/changelog:
--------------------------------------------------------------------------------
1 | [2.2 Snapshot]
2 | -- 113 Applied instance name when mock instance is used
3 | -- 114 Made map reduce elements serializable
4 | -- 116 Made MapReduceElement serializable with a tranisent graph
5 | [2.1]
6 | Change Log started
7 | --109,103 Merged Metadata tables
8 | --97 Added range queries
9 | --95 Table structure documentation
10 | --79 All flag for preloading
11 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | edu.jhuapl.tinkerpop
5 | blueprints-accumulo-graph
6 | 0.2.2-SNAPSHOT
7 | blueprints-accumulo-graph
8 | An Accumulo-backed implementation of the Tinkerpop Blueprints graph API.
9 | jar
10 | https://github.com/JHUAPL/AccumuloGraph
11 |
12 |
13 | Apache License, Version 2.0
14 | http://www.apache.org/licenses/LICENSE-2.0.txt
15 | repo
16 |
17 |
18 |
19 |
20 | scm:git:git@github.com:JHUAPL/AccumuloGraph.git
21 | scm:git:git@github.com:JHUAPL/AccumuloGraph.git
22 | git@github.com:JHUAPL/AccumuloGraph.git
23 |
24 |
25 |
26 |
27 | Ryan Webb
28 | webbrl@live.com
29 | https://github.com/webbrl1
30 |
31 |
32 | Sandy Hider
33 | sandy@hider.us
34 | https://github.com/sandyhider
35 |
36 |
37 |
38 |
39 | 1.7
40 | 1.7
41 | UTF-8
42 |
43 |
44 |
45 |
46 | org.apache.accumulo
47 | accumulo-core
48 | 1.5.1
49 |
50 |
51 | org.apache.accumulo
52 | accumulo-minicluster
53 | 1.5.0
54 |
55 |
56 | com.tinkerpop.blueprints
57 | blueprints-core
58 | 2.6.0
59 |
60 |
61 | commons-configuration
62 | commons-configuration
63 | 1.10
64 |
65 |
66 | commons-collections
67 | commons-collections
68 | 3.2.2
69 |
70 |
71 | org.apache.hadoop
72 | hadoop-client
73 | 2.2.0
74 | provided
75 |
76 |
77 | com.tinkerpop.rexster
78 | rexster-server
79 | 2.6.0
80 | provided
81 |
82 |
83 | com.tinkerpop.blueprints
84 | blueprints-test
85 | 2.6.0
86 | test
87 |
88 |
89 | org.apache.hadoop
90 | hadoop-minicluster
91 | 2.2.0
92 | test
93 |
94 |
95 | junit
96 | junit
97 | 4.11
98 | test
99 |
100 |
101 | commons-httpclient
102 | commons-httpclient
103 | 3.1
104 | test
105 |
106 |
107 |
108 |
109 |
110 | ossrh
111 | https://oss.sonatype.org/content/repositories/snapshots
112 |
113 |
114 | ossrh
115 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
116 |
117 |
118 |
119 |
120 |
121 | release
122 |
123 |
124 |
125 | org.apache.maven.plugins
126 | maven-source-plugin
127 | 2.2.1
128 |
129 |
130 | attach-sources
131 |
132 | jar-no-fork
133 |
134 |
135 |
136 |
137 |
138 | org.apache.maven.plugins
139 | maven-javadoc-plugin
140 | 2.9.1
141 |
142 |
143 | attach-javadocs
144 |
145 | jar
146 |
147 |
148 |
149 |
150 |
151 | org.apache.maven.plugins
152 | maven-gpg-plugin
153 | 1.5
154 |
155 |
156 | sign-artifacts
157 | verify
158 |
159 | sign
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 | javadoc
169 |
170 |
171 |
172 | org.apache.maven.plugins
173 | maven-source-plugin
174 | 2.2.1
175 |
176 |
177 | attach-sources
178 |
179 | jar-no-fork
180 |
181 |
182 |
183 |
184 |
185 | org.apache.maven.plugins
186 | maven-javadoc-plugin
187 | 2.9.1
188 |
189 |
190 | attach-javadocs
191 |
192 | jar
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 | fatjar
202 |
203 |
204 |
205 | org.apache.maven.plugins
206 | maven-shade-plugin
207 | 2.3
208 |
209 |
210 | package
211 |
212 | shade
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 | org.sonatype.plugins
226 | nexus-staging-maven-plugin
227 | 1.6.2
228 | true
229 |
230 | ossrh
231 | https://oss.sonatype.org/
232 | true
233 |
234 |
235 |
236 |
237 |
238 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloByteSerializer.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import java.io.ByteArrayInputStream;
18 | import java.io.ByteArrayOutputStream;
19 | import java.io.IOException;
20 | import java.io.ObjectInputStream;
21 | import java.io.ObjectOutputStream;
22 | import java.io.Serializable;
23 | import java.util.Date;
24 |
25 | import javax.xml.namespace.QName;
26 |
27 | public final class AccumuloByteSerializer {
28 |
29 | public static final int NULL = 'n';
30 |
31 | public static final int BYTE = 'b';
32 | public static final int SHORT = 's';
33 | public static final int CHARACTER = 'c';
34 | public static final int INTEGER = 'i';
35 | public static final int LONG = 'l';
36 | public static final int FLOAT = 'f';
37 | public static final int DOUBLE = 'd';
38 | public static final int BOOLEAN = 'o';
39 | public static final int DATE = 't';
40 | public static final int ENUM = 'e';
41 | public static final int STRING = 'a';
42 | public static final int SERIALIZABLE = 'x';
43 | public static final int QNAME = 'q';
44 |
45 | private AccumuloByteSerializer() {
46 |
47 | }
48 |
49 | private static final ThreadLocal BOUTS = new ThreadLocal() {
50 | @Override
51 | public ByteArrayOutputStream initialValue() {
52 | return new ByteArrayOutputStream(32);
53 | }
54 | };
55 |
56 | @SuppressWarnings("unchecked")
57 | public static T deserialize(byte[] target) {
58 | if (target[0] == NULL) {
59 | return null;
60 | }
61 |
62 | switch (target[0]) {
63 | case BYTE:
64 | return (T) (Byte) Byte.parseByte(new String(target, 1, target.length - 1));
65 | case SHORT:
66 | return (T) (Short) Short.parseShort(new String(target, 1, target.length - 1));
67 | case CHARACTER:
68 | return (T) (Character) new String(target, 1, target.length - 1).charAt(0);
69 | case INTEGER:
70 | return (T) (Integer) Integer.parseInt(new String(target, 1, target.length - 1));
71 | case LONG:
72 | return (T) (Long) Long.parseLong(new String(target, 1, target.length - 1));
73 | case FLOAT:
74 | return (T) (Float) Float.parseFloat(new String(target, 1, target.length - 1));
75 | case DOUBLE:
76 | return (T) (Double) Double.parseDouble(new String(target, 1, target.length - 1));
77 | case BOOLEAN:
78 | switch (new String(target, 1, 1)) {
79 | case "t":
80 | return (T) Boolean.TRUE;
81 | case "f":
82 | return (T) Boolean.FALSE;
83 | default:
84 | throw new RuntimeException("Unexpected boolean value: " + target[1]);
85 | }
86 | case DATE:
87 | long millis = Long.parseLong(new String(target, 1, target.length - 1));
88 | return (T) new Date(millis);
89 | case STRING:
90 | return (T) new String(target, 1, target.length - 1);
91 | case QNAME:
92 | return (T) QName.valueOf(new String(target, 1, target.length - 1));
93 | case ENUM:
94 | try {
95 | String[] s = new String(target, 1, target.length - 1).split(":");
96 | @SuppressWarnings("rawtypes")
97 | Class extends Enum> clz = (Class extends Enum>) Class.forName(s[0]);
98 | return (T) Enum.valueOf(clz, s[1]);
99 | } catch (ClassNotFoundException cnfe) {
100 | throw new RuntimeException("Unexpected error deserializing object.", cnfe);
101 | }
102 | case SERIALIZABLE:
103 | try {
104 | ByteArrayInputStream bin = new ByteArrayInputStream(target, 1, target.length);
105 | ObjectInputStream ois = new ObjectInputStream(bin);
106 | return (T) ois.readObject();
107 | } catch (IOException io) {
108 | throw new RuntimeException("Unexpected error deserializing object.", io);
109 | } catch (ClassNotFoundException cnfe) {
110 | throw new RuntimeException("Unexpected error deserializing object.", cnfe);
111 | }
112 | case NULL:
113 | return null;
114 | default:
115 | throw new RuntimeException("Unexpected data type: " + (char) target[0]);
116 | }
117 | }
118 |
119 | public static byte[] serialize(Object o) {
120 | ByteArrayOutputStream bout = BOUTS.get();
121 |
122 | try {
123 | if (o == null) {
124 | bout.write(NULL);
125 | return bout.toByteArray();
126 | }
127 |
128 | String val = o.toString();
129 | int type = -1;
130 | String cls = o.getClass().getSimpleName();
131 | switch (cls) {
132 | case "Byte":
133 | type = BYTE;
134 | break;
135 | case "Short":
136 | type = SHORT;
137 | break;
138 | case "Character":
139 | type = CHARACTER;
140 | break;
141 | case "Integer":
142 | type = INTEGER;
143 | break;
144 | case "Long":
145 | type = LONG;
146 | break;
147 | case "Float":
148 | type = FLOAT;
149 | break;
150 | case "Double":
151 | type = DOUBLE;
152 | break;
153 | case "Boolean":
154 | type = BOOLEAN;
155 | if ((Boolean) o) {
156 | val = "t";
157 | } else {
158 | val = "f";
159 | }
160 | break;
161 | case "Date":
162 | val = Long.toString(((Date) o).getTime());
163 | type = DATE;
164 | break;
165 | case "String":
166 | type = STRING;
167 | break;
168 | case "QName":
169 | type = QNAME;
170 | break;
171 | default:
172 | if (o instanceof Enum) {
173 | type = ENUM;
174 | val = o.getClass().getName() + ":" + val;
175 | } else if (o instanceof Serializable) {
176 | bout.write(SERIALIZABLE);
177 | ObjectOutputStream oos = new ObjectOutputStream(bout);
178 | oos.writeObject(o);
179 | oos.close();
180 | return bout.toByteArray();
181 | } else {
182 | throw new RuntimeException("Unsupported data type: " + o.getClass());
183 | }
184 | }
185 |
186 | bout.write(type);
187 | bout.write(val.getBytes());
188 | return bout.toByteArray();
189 | } catch (IOException io) {
190 | throw new RuntimeException("Unexpected error writing to byte array.", io);
191 | } finally {
192 | bout.reset();
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloEdge.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import java.util.Map;
18 | import java.util.Map.Entry;
19 |
20 | import org.apache.log4j.Logger;
21 |
22 | import com.tinkerpop.blueprints.Direction;
23 | import com.tinkerpop.blueprints.Edge;
24 | import com.tinkerpop.blueprints.Vertex;
25 | import com.tinkerpop.blueprints.util.StringFactory;
26 |
27 | /**
28 | * TODO
29 | */
30 | public class AccumuloEdge extends AccumuloElement implements Edge {
31 |
32 | private static final Logger log = Logger.getLogger(AccumuloEdge.class);
33 |
34 | private String label;
35 | private Vertex inVertex;
36 | private Vertex outVertex;
37 |
38 | public AccumuloEdge(GlobalInstances globals, String id) {
39 | this(globals, id, null, null, null);
40 | }
41 |
42 | public AccumuloEdge(GlobalInstances globals, String id,
43 | Vertex inVertex, Vertex outVertex, String label) {
44 | super(globals, id, Edge.class);
45 | this.label = label;
46 | this.inVertex = inVertex;
47 | this.outVertex = outVertex;
48 | }
49 |
50 | @Override
51 | public Vertex getVertex(Direction direction) throws IllegalArgumentException {
52 | if (!Direction.IN.equals(direction) && !Direction.OUT.equals(direction)) {
53 | throw new IllegalArgumentException("Invalid direction: "+direction);
54 | }
55 |
56 | // The vertex information needs to be loaded.
57 | if (inVertex == null || outVertex == null || label == null) {
58 | log.debug("Loading information for edge: "+this);
59 | globals.getEdgeWrapper().loadEndpointsAndLabel(this);
60 | }
61 |
62 | return Direction.IN.equals(direction) ? inVertex : outVertex;
63 | }
64 |
65 | @Override
66 | public String getLabel() {
67 | // TODO less special treatment for "LABEL" property...
68 | if (label != null) {
69 | return label;
70 | }
71 | return getProperty(StringFactory.LABEL);
72 | }
73 |
74 | @Override
75 | public void remove() {
76 | // Remove from named indexes.
77 | super.removeElementFromNamedIndexes();
78 |
79 | // If edge was removed already, forget it.
80 | // This may happen due to self-loops...
81 | if (!globals.getEdgeWrapper().elementExists(id)) {
82 | return;
83 | }
84 |
85 | // Remove properties from key/value indexes.
86 | Map props = globals.getEdgeWrapper()
87 | .readAllProperties(this);
88 |
89 | for (Entry ents : props.entrySet()) {
90 | globals.getEdgeKeyIndexWrapper().removePropertyFromIndex(this,
91 | ents.getKey(), ents.getValue());
92 | }
93 |
94 | // Get rid of the endpoints and edge themselves.
95 | globals.getVertexWrapper().deleteEdgeEndpoints(this);
96 | globals.getEdgeWrapper().deleteEdge(this);
97 |
98 | // Remove element from cache.
99 | globals.getCaches().remove(id, Edge.class);
100 |
101 | globals.checkedFlush();
102 | }
103 |
104 | public void setVertices(AccumuloVertex inVertex, AccumuloVertex outVertex) {
105 | this.inVertex = inVertex;
106 | this.outVertex = outVertex;
107 | }
108 |
109 | public void setLabel(String label) {
110 | this.label = label;
111 | }
112 |
113 | @Override
114 | public String toString() {
115 | return "[" + getId() + ":" + inVertex + " -> " + label + " -> " + outVertex + "]";
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloElement.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import java.util.Set;
18 |
19 | import com.tinkerpop.blueprints.Element;
20 | import com.tinkerpop.blueprints.Index;
21 | import com.tinkerpop.blueprints.util.StringFactory;
22 |
23 | import edu.jhuapl.tinkerpop.cache.PropertyCache;
24 |
25 | /**
26 | * TODO
27 | */
28 | public abstract class AccumuloElement implements Element {
29 |
30 | protected GlobalInstances globals;
31 | protected String id;
32 |
33 | private Class extends Element> type;
34 |
35 | private PropertyCache propertyCache;
36 |
37 | protected AccumuloElement(GlobalInstances globals,
38 | String id, Class extends Element> type) {
39 | this.globals = globals;
40 | this.id = id;
41 | this.type = type;
42 | }
43 |
44 | /**
45 | * Create properties cache if it doesn't exist,
46 | * and preload any properties.
47 | */
48 | private void makeCache() {
49 | if (propertyCache == null) {
50 | propertyCache = new PropertyCache(globals.getConfig());
51 |
52 | // Preload any keys, if needed.
53 | String[] preloadKeys = globals.getConfig().getPreloadedProperties();
54 | if (preloadKeys != null) {
55 | propertyCache.putAll(globals.getElementWrapper(type)
56 | .readProperties(this, preloadKeys));
57 | }
58 | }
59 | }
60 |
61 | @Override
62 | public T getProperty(String key) {
63 | makeCache();
64 |
65 | // Get from property cache.
66 | T value = propertyCache.get(key);
67 |
68 | // If not cached, get it from the backing table.
69 | if (value == null) {
70 | value = globals.getElementWrapper(type).readProperty(this, key);
71 | }
72 |
73 | // Cache the new value.
74 | if (value != null) {
75 | propertyCache.put(key, value);
76 | }
77 |
78 | return value;
79 | }
80 |
81 | @Override
82 | public Set getPropertyKeys() {
83 | return globals.getElementWrapper(type).readPropertyKeys(this);
84 | }
85 |
86 | @Override
87 | public void setProperty(String key, Object value) {
88 | makeCache();
89 | globals.getKeyIndexTableWrapper(type).setPropertyForIndex(this, key, value);
90 | // MDL 31 Dec 2014: The above calls getProperty, so this
91 | // order is important (for now).
92 | globals.getElementWrapper(type).writeProperty(this, key, value);
93 | globals.checkedFlush();
94 | setPropertyInMemory(key, value);
95 | }
96 |
97 | /**
98 | * Set a property but only in the instantiated object,
99 | * not in the backing store.
100 | * @param key
101 | * @param value
102 | */
103 | public void setPropertyInMemory(String key, Object value) {
104 | makeCache();
105 | propertyCache.put(key, value);
106 | }
107 |
108 | @Override
109 | public T removeProperty(String key) {
110 | if (StringFactory.LABEL.equals(key) ||
111 | Constants.LABEL.equals(key)) {
112 | throw new AccumuloGraphException("Cannot remove the " + StringFactory.LABEL + " property.");
113 | }
114 |
115 | makeCache();
116 | T value = getProperty(key);
117 | if (value != null) {
118 | globals.getElementWrapper(type).clearProperty(this, key);
119 | globals.checkedFlush();
120 | }
121 | globals.getKeyIndexTableWrapper(type).removePropertyFromIndex(this, key, value);
122 | // MDL 31 Dec 2014: AccumuloGraph.removeProperty
123 | // calls getProperty which populates the cache.
124 | // So the order here is important (for now).
125 | removePropertyInMemory(key);
126 | return value;
127 | }
128 |
129 | /**
130 | * Remove element from all named indexes.
131 | * @param element
132 | */
133 | protected void removeElementFromNamedIndexes() {
134 | for (Index extends Element> index : globals.getIndexMetadataWrapper().getIndices()) {
135 | ((AccumuloIndex extends Element>) index).getWrapper().removeElementFromIndex(this);
136 | }
137 | }
138 |
139 | /**
140 | * Remove a property but only in the instantiated
141 | * object, not the backing store.
142 | * @param key
143 | */
144 | public void removePropertyInMemory(String key) {
145 | makeCache();
146 | propertyCache.remove(key);
147 | }
148 |
149 | /**
150 | * Return the properties currently cached in memory.
151 | * @return
152 | */
153 | public Iterable getPropertyKeysInMemory() {
154 | makeCache();
155 | return propertyCache.keySet();
156 | }
157 |
158 | /**
159 | * Retrieve a property from memory.
160 | * @param key
161 | * @return
162 | */
163 | public Object getPropertyInMemory(String key) {
164 | makeCache();
165 | return propertyCache.get(key);
166 | }
167 |
168 | @Override
169 | public Object getId() {
170 | return id;
171 | }
172 |
173 | @Override
174 | public boolean equals(Object obj) {
175 | if (obj == null) {
176 | return false;
177 | } else if (obj == this) {
178 | return true;
179 | } else if (!obj.getClass().equals(getClass())) {
180 | return false;
181 | } else {
182 | return id.equals(((AccumuloElement) obj).id);
183 | }
184 | }
185 |
186 | @Override
187 | public int hashCode() {
188 | return getClass().hashCode() ^ id.hashCode();
189 | }
190 |
191 | /**
192 | * Internal method for unit tests.
193 | * @return
194 | */
195 | PropertyCache getPropertyCache() {
196 | return propertyCache;
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloFeatures.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import com.tinkerpop.blueprints.Features;
18 |
19 | /**
20 | * {@link Features} creator.
21 | */
22 | public class AccumuloFeatures {
23 |
24 | public static Features get() {
25 | Features f = new Features();
26 |
27 | // For simplicity, I accept all property types. They are handled in not the
28 | // best way. To be fixed later.
29 | f.ignoresSuppliedIds = true;
30 | f.isPersistent = true;
31 | f.isWrapper = false;
32 | f.supportsBooleanProperty = true;
33 | f.supportsDoubleProperty = true;
34 | f.supportsDuplicateEdges = true;
35 | f.supportsEdgeIndex = true;
36 | f.supportsEdgeIteration = true;
37 | f.supportsEdgeRetrieval = true;
38 | f.supportsEdgeKeyIndex = true;
39 | f.supportsEdgeProperties = true;
40 | f.supportsFloatProperty = true;
41 | f.supportsIndices = true;
42 | f.supportsIntegerProperty = true;
43 | f.supportsKeyIndices = true;
44 | f.supportsLongProperty = true;
45 | f.supportsMapProperty = true;
46 | f.supportsMixedListProperty = true;
47 | f.supportsPrimitiveArrayProperty = true;
48 | f.supportsSelfLoops = true;
49 | f.supportsSerializableObjectProperty = true;
50 | f.supportsStringProperty = true;
51 | f.supportsThreadedTransactions = false;
52 | f.supportsTransactions = false;
53 | f.supportsUniformListProperty = true;
54 | f.supportsVertexIndex = true;
55 | f.supportsVertexIteration = true;
56 | f.supportsVertexKeyIndex = true;
57 | f.supportsVertexProperties = true;
58 | f.supportsThreadIsolatedTransactions = false;
59 |
60 | return f;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloGraphException.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | public class AccumuloGraphException extends RuntimeException {
18 |
19 | private static final long serialVersionUID = 2179662107592532517L;
20 |
21 | public AccumuloGraphException() {
22 |
23 | }
24 |
25 | public AccumuloGraphException(String reason) {
26 | super(reason);
27 | }
28 |
29 | public AccumuloGraphException(Throwable cause) {
30 | super(cause);
31 | }
32 |
33 | public AccumuloGraphException(String reason, Throwable cause) {
34 | super(reason, cause);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloGraphUtils.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import java.util.SortedSet;
18 | import java.util.UUID;
19 |
20 | import org.apache.accumulo.core.client.admin.TableOperations;
21 | import org.apache.hadoop.io.Text;
22 |
23 | import com.tinkerpop.blueprints.util.ExceptionFactory;
24 | import com.tinkerpop.blueprints.util.StringFactory;
25 |
26 | public final class AccumuloGraphUtils {
27 |
28 | /**
29 | * Create and/or clear existing graph tables for the given configuration.
30 | *
31 | * @param cfg
32 | */
33 | static void handleCreateAndClear(AccumuloGraphConfiguration cfg) {
34 | try {
35 | TableOperations tableOps = cfg.getConnector().tableOperations();
36 |
37 | // Track whether tables existed before we do anything.
38 | boolean existedBeforeClear = false;
39 | for (String table : cfg.getTableNames()) {
40 | if (tableOps.exists(table)) {
41 | existedBeforeClear = true;
42 | break;
43 | }
44 | }
45 |
46 | // Check edge cases.
47 | // No tables exist, and we are not allowed to create.
48 | if (!existedBeforeClear && !cfg.getCreate()) {
49 | throw new IllegalArgumentException("Graph does not exist, and create option is disabled");
50 | }
51 | // Tables exist, and we are not clearing them.
52 | else if (existedBeforeClear && !cfg.getClear()) {
53 | // Do nothing.
54 | return;
55 | }
56 |
57 | // We want to clear tables, so do it.
58 | if (cfg.getClear()) {
59 | for (String table : cfg.getTableNames()) {
60 | if (tableOps.exists(table)) {
61 | tableOps.delete(table);
62 | }
63 | }
64 | }
65 |
66 | // Tables existed, or we want to create them. So do it.
67 | if (existedBeforeClear || cfg.getCreate()) {
68 | for (String table : cfg.getTableNames()) {
69 | if (!tableOps.exists(table)) {
70 | tableOps.create(table);
71 | SortedSet splits = cfg.getSplits();
72 | if (splits != null) {
73 | tableOps.addSplits(table, splits);
74 | }
75 | }
76 | }
77 | }
78 |
79 | } catch (Exception e) {
80 | throw new IllegalArgumentException(e);
81 | }
82 | }
83 |
84 | /**
85 | * Generate an element id.
86 | * @return
87 | */
88 | public static String generateId() {
89 | return UUID.randomUUID().toString();
90 | }
91 |
92 | /**
93 | * Ensure that the given key/value don't conflict with
94 | * Blueprints reserved words.
95 | * @param key
96 | * @param value
97 | */
98 | public static void validateProperty(String key, Object value) {
99 | nullCheckProperty(key, value);
100 | if (key.equals(StringFactory.ID)) {
101 | throw ExceptionFactory.propertyKeyIdIsReserved();
102 | } else if (key.equals(StringFactory.LABEL)) {
103 | throw ExceptionFactory.propertyKeyLabelIsReservedForEdges();
104 | } else if (value == null) {
105 | throw ExceptionFactory.propertyValueCanNotBeNull();
106 | }
107 | }
108 |
109 | /**
110 | * Disallow null keys/values and throw appropriate
111 | * Blueprints exceptions.
112 | * @param key
113 | * @param value
114 | */
115 | public static void nullCheckProperty(String key, Object value) {
116 | if (key == null) {
117 | throw ExceptionFactory.propertyKeyCanNotBeNull();
118 | } else if (value == null) {
119 | throw ExceptionFactory.propertyValueCanNotBeNull();
120 | } else if (key.trim().equals(StringFactory.EMPTY_STRING)) {
121 | throw ExceptionFactory.propertyKeyCanNotBeEmpty();
122 | }
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloIndex.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import java.util.Iterator;
18 |
19 | import com.tinkerpop.blueprints.CloseableIterable;
20 | import com.tinkerpop.blueprints.Element;
21 | import com.tinkerpop.blueprints.Index;
22 | import com.tinkerpop.blueprints.IndexableGraph;
23 |
24 | import edu.jhuapl.tinkerpop.tables.index.NamedIndexTableWrapper;
25 |
26 | /**
27 | * Accumulo-based implementation for {@link IndexableGraph}.
28 | * @param
29 | */
30 | public class AccumuloIndex implements Index {
31 | private final GlobalInstances globals;
32 | private final Class indexedType;
33 | private final String indexName;
34 | private final NamedIndexTableWrapper indexWrapper;
35 |
36 | public AccumuloIndex(GlobalInstances globals, String indexName, Class indexedType) {
37 | this.globals = globals;
38 | this.indexName = indexName;
39 | this.indexedType = indexedType;
40 |
41 | try {
42 | if (!globals.getConfig().getConnector()
43 | .tableOperations().exists(getTableName())) {
44 | globals.getConfig().getConnector()
45 | .tableOperations().create(getTableName());
46 | }
47 | } catch (Exception e) {
48 | throw new AccumuloGraphException(e);
49 | }
50 |
51 | indexWrapper = new NamedIndexTableWrapper(globals, indexedType, indexName);
52 | }
53 |
54 | @Override
55 | public String getIndexName() {
56 | return indexName;
57 | }
58 |
59 | public String getTableName() {
60 | return globals.getConfig().getNamedIndexTableName(indexName);
61 | }
62 |
63 | public NamedIndexTableWrapper getWrapper() {
64 | return indexWrapper;
65 | }
66 |
67 | @Override
68 | public Class getIndexClass() {
69 | return indexedType;
70 | }
71 |
72 | @Override
73 | public void put(String key, Object value, Element element) {
74 | indexWrapper.setPropertyForIndex(element, key, value, true);
75 | }
76 |
77 | @Override
78 | public CloseableIterable get(String key, Object value) {
79 | return indexWrapper.readElementsFromIndex(key, value);
80 | }
81 |
82 | @Override
83 | public CloseableIterable query(String key, Object query) {
84 | throw new UnsupportedOperationException();
85 | }
86 |
87 | @Override
88 | public long count(String key, Object value) {
89 | CloseableIterable iterable = get(key, value);
90 | Iterator iter = iterable.iterator();
91 | int count = 0;
92 | while (iter.hasNext()) {
93 | count++;
94 | iter.next();
95 | }
96 | iterable.close();
97 | return count;
98 | }
99 |
100 | @Override
101 | public void remove(String key, Object value, Element element) {
102 | indexWrapper.removePropertyFromIndex(element, key, value);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloRexsterGraphConfiguration.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import org.apache.commons.configuration.Configuration;
18 | import org.apache.commons.configuration.HierarchicalConfiguration;
19 |
20 | import com.tinkerpop.blueprints.Graph;
21 | import com.tinkerpop.blueprints.GraphFactory;
22 | import com.tinkerpop.rexster.Tokens;
23 | import com.tinkerpop.rexster.config.GraphConfiguration;
24 | import com.tinkerpop.rexster.config.GraphConfigurationContext;
25 | import com.tinkerpop.rexster.config.GraphConfigurationException;
26 |
27 | import edu.jhuapl.tinkerpop.AccumuloGraphConfiguration.InstanceType;
28 |
29 | public class AccumuloRexsterGraphConfiguration implements GraphConfiguration {
30 |
31 | @Override
32 | public Graph configureGraphInstance(GraphConfigurationContext context) throws GraphConfigurationException {
33 |
34 | Configuration conf = context.getProperties();
35 | try {
36 | conf = ((HierarchicalConfiguration) conf).configurationAt(Tokens.REXSTER_GRAPH_PROPERTIES);
37 | } catch (IllegalArgumentException iae) {
38 | throw new GraphConfigurationException("Check graph configuration. Missing or empty configuration element: " + Tokens.REXSTER_GRAPH_PROPERTIES);
39 | }
40 |
41 | AccumuloGraphConfiguration cfg = new AccumuloGraphConfiguration(conf);
42 | if (cfg.getInstanceType().equals(InstanceType.Mock)) {
43 | cfg.setPassword("".getBytes());
44 | cfg.setUser("root");
45 | }
46 | cfg.setGraphName(context.getProperties().getString(Tokens.REXSTER_GRAPH_NAME));
47 | return GraphFactory.open(cfg.getConfiguration());
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/AccumuloVertex.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import java.util.Map;
18 | import java.util.Map.Entry;
19 |
20 | import com.tinkerpop.blueprints.CloseableIterable;
21 | import com.tinkerpop.blueprints.Direction;
22 | import com.tinkerpop.blueprints.Edge;
23 | import com.tinkerpop.blueprints.Vertex;
24 | import com.tinkerpop.blueprints.VertexQuery;
25 | import com.tinkerpop.blueprints.util.DefaultVertexQuery;
26 | import com.tinkerpop.blueprints.util.ExceptionFactory;
27 |
28 | /**
29 | * TODO
30 | */
31 | public class AccumuloVertex extends AccumuloElement implements Vertex {
32 |
33 | public AccumuloVertex(GlobalInstances globals, String id) {
34 | super(globals, id, Vertex.class);
35 | }
36 |
37 | @Override
38 | public Iterable getEdges(Direction direction, String... labels) {
39 | return globals.getVertexWrapper().getEdges(this, direction, labels);
40 | }
41 |
42 | @Override
43 | public Iterable getVertices(Direction direction, String... labels) {
44 | return globals.getVertexWrapper().getVertices(this, direction, labels);
45 | }
46 |
47 | @Override
48 | public VertexQuery query() {
49 | return new DefaultVertexQuery(this);
50 | }
51 |
52 | @Override
53 | public Edge addEdge(String label, Vertex inVertex) {
54 | return addEdge(null, label, inVertex);
55 | }
56 |
57 | /**
58 | * Add an edge as with {@link #addEdge(String, Vertex)},
59 | * but with a specified edge id.
60 | * @param id
61 | * @param label
62 | * @param inVertex
63 | * @return
64 | */
65 | public Edge addEdge(Object id, String label, Vertex inVertex) {
66 | if (label == null) {
67 | throw ExceptionFactory.edgeLabelCanNotBeNull();
68 | }
69 | if (id == null) {
70 | id = AccumuloGraphUtils.generateId();
71 | }
72 |
73 | String myID = id.toString();
74 |
75 | AccumuloEdge edge = new AccumuloEdge(globals, myID, inVertex, this, label);
76 |
77 | // TODO we arent suppose to make sure the given edge ID doesn't already
78 | // exist?
79 |
80 | globals.getEdgeWrapper().writeEdge(edge);
81 | globals.getVertexWrapper().writeEdgeEndpoints(edge);
82 |
83 | globals.checkedFlush();
84 |
85 | globals.getCaches().cache(edge, Edge.class);
86 |
87 | return edge;
88 | }
89 |
90 | @Override
91 | public void remove() {
92 | globals.getCaches().remove(getId(), Vertex.class);
93 |
94 | super.removeElementFromNamedIndexes();
95 |
96 | // Throw exception if the element does not exist.
97 | if (!globals.getVertexWrapper().elementExists(id)) {
98 | throw ExceptionFactory.vertexWithIdDoesNotExist(getId());
99 | }
100 |
101 | // Remove properties from key/value indexes.
102 | Map props = globals.getVertexWrapper()
103 | .readAllProperties(this);
104 |
105 | for (Entry ent : props.entrySet()) {
106 | globals.getVertexKeyIndexWrapper().removePropertyFromIndex(this,
107 | ent.getKey(), ent.getValue());
108 | }
109 |
110 | // Remove edges incident to this vertex.
111 | CloseableIterable iter = (CloseableIterable)getEdges(Direction.BOTH);
112 | for (Edge edge : iter) {
113 | edge.remove();
114 | }
115 | iter.close();
116 |
117 | globals.checkedFlush();
118 |
119 | // Get rid of the vertex.
120 | globals.getVertexWrapper().deleteVertex(this);
121 | globals.checkedFlush();
122 | }
123 |
124 | @Override
125 | public String toString() {
126 | return "[" + getId() + "]";
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/Constants.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | /**
18 | * Collect up various constants here.
19 | * @author Michael Lieberman
20 | *
21 | */
22 | public class Constants {
23 |
24 | private Constants() { }
25 |
26 | /**
27 | * Separate element ids in Accumulo entries.
28 | */
29 | public static final String ID_DELIM = "__DELIM__";
30 |
31 | public static final byte[] EMPTY = new byte[0];
32 |
33 | /**
34 | * Prefixes for various Accumulo entries.
35 | */
36 | public static final String LABEL = "__LABEL__";
37 | public static final String IN_EDGE = "__IN_EDGE__";
38 | public static final String OUT_EDGE = "__OUT_EDGE__";
39 | public static final String EXISTS = "__EXISTS__";
40 |
41 | /**
42 | * Type of metadata to distinguish between
43 | * entries in the metadata table.
44 | */
45 | public static enum IndexMetadataEntryType {__INDEX_KEY__, __INDEX_NAME__};
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/GlobalInstances.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import org.apache.accumulo.core.client.MultiTableBatchWriter;
18 | import org.apache.accumulo.core.client.MutationsRejectedException;
19 |
20 | import com.tinkerpop.blueprints.Edge;
21 | import com.tinkerpop.blueprints.Element;
22 | import com.tinkerpop.blueprints.Vertex;
23 |
24 | import edu.jhuapl.tinkerpop.cache.ElementCaches;
25 | import edu.jhuapl.tinkerpop.tables.core.EdgeTableWrapper;
26 | import edu.jhuapl.tinkerpop.tables.core.ElementTableWrapper;
27 | import edu.jhuapl.tinkerpop.tables.core.VertexTableWrapper;
28 | import edu.jhuapl.tinkerpop.tables.index.BaseKeyIndexTableWrapper;
29 | import edu.jhuapl.tinkerpop.tables.index.EdgeKeyIndexTableWrapper;
30 | import edu.jhuapl.tinkerpop.tables.index.IndexMetadataTableWrapper;
31 | import edu.jhuapl.tinkerpop.tables.index.VertexKeyIndexTableWrapper;
32 |
33 | /**
34 | * Internal class gathering together instances of
35 | * objects needed for various AccumuloGraph components.
36 | */
37 | public class GlobalInstances {
38 |
39 | private final AccumuloGraphConfiguration config;
40 | private final MultiTableBatchWriter mtbw;
41 | private final ElementCaches caches;
42 |
43 | public GlobalInstances(AccumuloGraphConfiguration config,
44 | MultiTableBatchWriter mtbw, ElementCaches caches) {
45 | this.config = config;
46 | this.mtbw = mtbw;
47 | this.caches = caches;
48 | }
49 |
50 | public AccumuloGraphConfiguration getConfig() {
51 | return config;
52 | }
53 |
54 | public MultiTableBatchWriter getMtbw() {
55 | return mtbw;
56 | }
57 |
58 | public VertexTableWrapper getVertexWrapper() {
59 | return new VertexTableWrapper(this);
60 | }
61 |
62 | public EdgeTableWrapper getEdgeWrapper() {
63 | return new EdgeTableWrapper(this);
64 | }
65 |
66 | public VertexKeyIndexTableWrapper getVertexKeyIndexWrapper() {
67 | return new VertexKeyIndexTableWrapper(this);
68 | }
69 |
70 | public EdgeKeyIndexTableWrapper getEdgeKeyIndexWrapper() {
71 | return new EdgeKeyIndexTableWrapper(this);
72 | }
73 |
74 | public IndexMetadataTableWrapper getIndexMetadataWrapper() {
75 | return new IndexMetadataTableWrapper(this);
76 | }
77 |
78 | public ElementTableWrapper getElementWrapper(Class clazz) {
79 | if (Vertex.class.equals(clazz)) {
80 | return getVertexWrapper();
81 | } else if (Edge.class.equals(clazz)) {
82 | return getEdgeWrapper();
83 | } else {
84 | throw new AccumuloGraphException("Unrecognized class: "+clazz);
85 | }
86 | }
87 |
88 | public BaseKeyIndexTableWrapper getKeyIndexTableWrapper(Class clazz) {
89 | if (Vertex.class.equals(clazz)) {
90 | return getVertexKeyIndexWrapper();
91 | } else if (Edge.class.equals(clazz)) {
92 | return getEdgeKeyIndexWrapper();
93 | } else {
94 | throw new AccumuloGraphException("Unrecognized class: "+clazz);
95 | }
96 | }
97 |
98 | public ElementCaches getCaches() {
99 | return caches;
100 | }
101 |
102 | /**
103 | * Flush the writer, if autoflush is enabled.
104 | */
105 | public void checkedFlush() {
106 | if (config.getAutoFlush()) {
107 | try {
108 | mtbw.flush();
109 | } catch (MutationsRejectedException e) {
110 | throw new AccumuloGraphException(e);
111 | }
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/ScannerIterable.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop;
16 |
17 | import java.util.Iterator;
18 | import java.util.Map.Entry;
19 |
20 | import org.apache.accumulo.core.client.ScannerBase;
21 | import org.apache.accumulo.core.data.Key;
22 | import org.apache.accumulo.core.data.Value;
23 | import org.apache.accumulo.core.util.PeekingIterator;
24 |
25 | import com.tinkerpop.blueprints.CloseableIterable;
26 | import com.tinkerpop.blueprints.Element;
27 |
28 | /**
29 | * TODO
30 | */
31 | public abstract class ScannerIterable implements CloseableIterable {
32 |
33 | private ScannerBase scanner;
34 |
35 | public ScannerIterable(ScannerBase scanner) {
36 | this.scanner = scanner;
37 | }
38 |
39 | @Override
40 | public Iterator iterator() {
41 | return new ScannerIterator(new PeekingIterator>(scanner.iterator()));
42 | }
43 |
44 | public abstract T next(PeekingIterator> iterator);
45 |
46 | @Override
47 | public void close() {
48 | if (scanner != null) {
49 | scanner.close();
50 | scanner = null;
51 | }
52 | }
53 |
54 | @Override
55 | protected void finalize() {
56 | close();
57 | }
58 |
59 | private class ScannerIterator implements Iterator {
60 | private PeekingIterator> iterator;
61 |
62 | private ScannerIterator(PeekingIterator> iterator) {
63 | this.iterator = iterator;
64 | }
65 |
66 | @Override
67 | public boolean hasNext() {
68 | return iterator.hasNext();
69 | }
70 |
71 | @Override
72 | public T next() {
73 | return ScannerIterable.this.next(iterator);
74 | }
75 |
76 | @Override
77 | public void remove() {
78 | throw new UnsupportedOperationException();
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/edu/jhuapl/tinkerpop/cache/ElementCache.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2014 The Johns Hopkins University Applied Physics Laboratory
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | package edu.jhuapl.tinkerpop.cache;
16 |
17 | import java.util.concurrent.TimeUnit;
18 |
19 | import com.google.common.cache.Cache;
20 | import com.google.common.cache.CacheBuilder;
21 | import com.tinkerpop.blueprints.Element;
22 |
23 | /**
24 | * Simple cache for retrieved graph elements,
25 | * backed by Guava's cache implementation.
26 | */
27 | public class ElementCache {
28 |
29 | private Cache