|
1 | 1 | package com.tinkerpop.blueprints.impls.neo4j2;
|
2 | 2 |
|
3 |
| -import com.tinkerpop.blueprints.Edge; |
4 |
| -import com.tinkerpop.blueprints.Element; |
5 |
| -import com.tinkerpop.blueprints.Features; |
6 |
| -import com.tinkerpop.blueprints.GraphQuery; |
7 |
| -import com.tinkerpop.blueprints.Index; |
8 |
| -import com.tinkerpop.blueprints.IndexableGraph; |
9 |
| -import com.tinkerpop.blueprints.KeyIndexableGraph; |
10 |
| -import com.tinkerpop.blueprints.MetaGraph; |
11 |
| -import com.tinkerpop.blueprints.Parameter; |
12 |
| -import com.tinkerpop.blueprints.TransactionalGraph; |
13 |
| -import com.tinkerpop.blueprints.Vertex; |
14 |
| -import com.tinkerpop.blueprints.util.DefaultGraphQuery; |
15 |
| -import com.tinkerpop.blueprints.util.ExceptionFactory; |
16 |
| -import com.tinkerpop.blueprints.util.KeyIndexableGraphHelper; |
17 |
| -import com.tinkerpop.blueprints.util.PropertyFilteredIterable; |
18 |
| -import com.tinkerpop.blueprints.util.StringFactory; |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Arrays; |
| 5 | +import java.util.Collections; |
| 6 | +import java.util.HashSet; |
| 7 | +import java.util.Iterator; |
| 8 | +import java.util.List; |
| 9 | +import java.util.Map; |
| 10 | +import java.util.Set; |
| 11 | +import java.util.logging.Level; |
| 12 | +import java.util.logging.Logger; |
| 13 | + |
19 | 14 | import org.apache.commons.configuration.Configuration;
|
20 | 15 | import org.apache.commons.configuration.ConfigurationConverter;
|
21 | 16 | import org.neo4j.graphdb.DynamicRelationshipType;
|
|
30 | 25 | import org.neo4j.graphdb.factory.GraphDatabaseFactory;
|
31 | 26 | import org.neo4j.graphdb.index.AutoIndexer;
|
32 | 27 | import org.neo4j.graphdb.index.RelationshipIndex;
|
| 28 | +import org.neo4j.helpers.Settings; |
33 | 29 | import org.neo4j.kernel.GraphDatabaseAPI;
|
34 | 30 | import org.neo4j.kernel.impl.core.NodeManager;
|
35 | 31 | import org.neo4j.tooling.GlobalGraphOperations;
|
36 | 32 |
|
37 |
| -import java.util.*; |
38 |
| -import java.util.logging.Level; |
39 |
| -import java.util.logging.Logger; |
| 33 | +import com.tinkerpop.blueprints.Edge; |
| 34 | +import com.tinkerpop.blueprints.Element; |
| 35 | +import com.tinkerpop.blueprints.Features; |
| 36 | +import com.tinkerpop.blueprints.GraphQuery; |
| 37 | +import com.tinkerpop.blueprints.Index; |
| 38 | +import com.tinkerpop.blueprints.IndexableGraph; |
| 39 | +import com.tinkerpop.blueprints.KeyIndexableGraph; |
| 40 | +import com.tinkerpop.blueprints.MetaGraph; |
| 41 | +import com.tinkerpop.blueprints.Parameter; |
| 42 | +import com.tinkerpop.blueprints.TransactionalGraph; |
| 43 | +import com.tinkerpop.blueprints.Vertex; |
| 44 | +import com.tinkerpop.blueprints.util.DefaultGraphQuery; |
| 45 | +import com.tinkerpop.blueprints.util.ExceptionFactory; |
| 46 | +import com.tinkerpop.blueprints.util.KeyIndexableGraphHelper; |
| 47 | +import com.tinkerpop.blueprints.util.PropertyFilteredIterable; |
| 48 | +import com.tinkerpop.blueprints.util.StringFactory; |
40 | 49 |
|
41 | 50 | /**
|
42 | 51 | * A Blueprints implementation of the graph database Neo4j (http://neo4j.org)
|
43 | 52 | *
|
44 | 53 | * @author Marko A. Rodriguez (http://markorodriguez.com)
|
45 | 54 | */
|
46 | 55 | public class Neo4j2Graph implements TransactionalGraph, IndexableGraph, KeyIndexableGraph, MetaGraph<GraphDatabaseService> {
|
| 56 | + |
47 | 57 | private static final Logger logger = Logger.getLogger(Neo4j2Graph.class.getName());
|
| 58 | + |
| 59 | + |
| 60 | + public static GraphDatabaseBuilder createGraphDatabaseBuilder(String directory, Map<String, String> configuration){ |
| 61 | + GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory); |
| 62 | + if (null != configuration){ |
| 63 | + for(String key: configuration.keySet()){ |
| 64 | + builder.setConfig(Settings.setting(key, Settings.STRING, (String) null), configuration.get(key)); |
| 65 | + } |
| 66 | + } |
| 67 | + return builder; |
| 68 | + } |
48 | 69 |
|
| 70 | + |
49 | 71 | private GraphDatabaseService rawGraph;
|
50 | 72 | private static final String INDEXED_KEYS_POSTFIX = ":indexed_keys";
|
51 | 73 |
|
@@ -131,42 +153,36 @@ public void setCheckElementsInTransaction(final boolean checkElementsInTransacti
|
131 | 153 | this.checkElementsInTransaction.set(checkElementsInTransaction);
|
132 | 154 | }
|
133 | 155 |
|
| 156 | + |
134 | 157 | public Neo4j2Graph(final String directory) {
|
135 | 158 | this(directory, null);
|
136 | 159 | }
|
137 |
| - |
138 |
| - public Neo4j2Graph(final GraphDatabaseService rawGraph) { |
139 |
| - this.rawGraph = rawGraph; |
140 |
| - |
141 |
| - init(); |
| 160 | + |
| 161 | + public Neo4j2Graph(final Configuration configuration) { |
| 162 | + this(configuration.getString("blueprints.neo4j.directory", null), |
| 163 | + ConfigurationConverter.getMap(configuration.subset("blueprints.neo4j.conf"))); |
142 | 164 | }
|
143 |
| - |
| 165 | + |
144 | 166 | public Neo4j2Graph(final String directory, final Map<String, String> configuration) {
|
145 |
| - try { |
146 |
| - GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(directory); |
147 |
| - if (null != configuration) |
148 |
| - this.rawGraph = builder.setConfig(configuration).newGraphDatabase(); |
149 |
| - else |
150 |
| - this.rawGraph = builder.newGraphDatabase(); |
| 167 | + this(createGraphDatabaseBuilder(directory, configuration).newGraphDatabase()); |
| 168 | + } |
151 | 169 |
|
| 170 | + public Neo4j2Graph(final GraphDatabaseService rawGraph) { |
| 171 | + try{ |
| 172 | + this.rawGraph = rawGraph; |
152 | 173 | init();
|
153 |
| - |
154 |
| - } catch (Exception e) { |
155 |
| - if (this.rawGraph != null) |
156 |
| - this.rawGraph.shutdown(); |
157 |
| - throw new RuntimeException(e.getMessage(), e); |
158 |
| - } |
| 174 | + } catch (Exception e) { |
| 175 | + if (this.rawGraph != null) |
| 176 | + this.rawGraph.shutdown(); |
| 177 | + throw new RuntimeException(e.getMessage(), e); |
| 178 | + } |
159 | 179 | }
|
160 | 180 |
|
| 181 | + |
161 | 182 | protected void init() {
|
162 | 183 | this.loadKeyIndices();
|
163 | 184 | }
|
164 | 185 |
|
165 |
| - public Neo4j2Graph(final Configuration configuration) { |
166 |
| - this(configuration.getString("blueprints.neo4j.directory", null), |
167 |
| - ConfigurationConverter.getMap(configuration.subset("blueprints.neo4j.conf"))); |
168 |
| - } |
169 |
| - |
170 | 186 | private void loadKeyIndices() {
|
171 | 187 | this.autoStartTransaction(true);
|
172 | 188 | for (final String key : this.getInternalIndexKeys(Vertex.class)) {
|
|
0 commit comments