|
16 | 16 | import org.neo4j.graphdb.DynamicLabel; |
17 | 17 | import org.neo4j.graphdb.DynamicRelationshipType; |
18 | 18 | import org.neo4j.graphdb.GraphDatabaseService; |
19 | | -import org.neo4j.graphdb.Label; |
20 | 19 | import org.neo4j.graphdb.Node; |
21 | 20 | import org.neo4j.graphdb.NotFoundException; |
22 | 21 | import org.neo4j.graphdb.PropertyContainer; |
23 | 22 | import org.neo4j.graphdb.Relationship; |
24 | | -import org.neo4j.graphdb.ResourceIterable; |
25 | | -import org.neo4j.graphdb.ResourceIterator; |
26 | 23 | import org.neo4j.graphdb.Transaction; |
27 | 24 | import org.neo4j.graphdb.TransactionFailureException; |
28 | 25 | import org.neo4j.graphdb.factory.GraphDatabaseBuilder; |
|
45 | 42 | import com.tinkerpop.blueprints.Parameter; |
46 | 43 | import com.tinkerpop.blueprints.TransactionalGraph; |
47 | 44 | import com.tinkerpop.blueprints.Vertex; |
| 45 | +import com.tinkerpop.blueprints.impls.neo4j2.index.Neo4j2EdgeIndex; |
| 46 | +import com.tinkerpop.blueprints.impls.neo4j2.index.Neo4j2VertexIndex; |
| 47 | +import com.tinkerpop.blueprints.impls.neo4j2.iterate.Neo4j2EdgeIterable; |
| 48 | +import com.tinkerpop.blueprints.impls.neo4j2.iterate.Neo4j2VertexIterable; |
48 | 49 | import com.tinkerpop.blueprints.util.DefaultGraphQuery; |
49 | 50 | import com.tinkerpop.blueprints.util.ExceptionFactory; |
50 | 51 | import com.tinkerpop.blueprints.util.KeyIndexableGraphHelper; |
@@ -262,28 +263,41 @@ private void logNotGraphDatabaseAPI() { |
262 | 263 | " Current graph class is " + rawGraph.getClass().getName()); |
263 | 264 | } |
264 | 265 | } |
| 266 | + |
| 267 | + |
| 268 | + /** |
| 269 | + * Helper method, here only to support the existing methods that pass that Class<T> as an argument. |
| 270 | + */ |
| 271 | + private <T extends Element> Index<T> _createIndex(final String indexName, final Class<T> indexClass, final Parameter... indexParameters) { |
| 272 | + if (Vertex.class.isAssignableFrom(indexClass)) { |
| 273 | + return (Index<T>) new Neo4j2VertexIndex(indexName, this, indexParameters); |
| 274 | + } else { |
| 275 | + return (Index<T>) new Neo4j2EdgeIndex(indexName, this, indexParameters); |
| 276 | + } |
| 277 | + } |
| 278 | + |
265 | 279 |
|
266 | 280 | public synchronized <T extends Element> Index<T> createIndex(final String indexName, final Class<T> indexClass, final Parameter... indexParameters) { |
267 | 281 | this.autoStartTransaction(true); |
268 | 282 | if (this.rawGraph.index().existsForNodes(indexName) || this.rawGraph.index().existsForRelationships(indexName)) { |
269 | 283 | throw ExceptionFactory.indexAlreadyExists(indexName); |
270 | 284 | } |
271 | | - return new Neo4j2Index(indexName, indexClass, this, indexParameters); |
| 285 | + return _createIndex(indexName, indexClass, indexParameters); |
272 | 286 | } |
273 | 287 |
|
274 | 288 | public <T extends Element> Index<T> getIndex(final String indexName, final Class<T> indexClass) { |
275 | 289 | this.autoStartTransaction(false); |
276 | 290 | if (Vertex.class.isAssignableFrom(indexClass)) { |
277 | 291 | if (this.rawGraph.index().existsForNodes(indexName)) { |
278 | | - return new Neo4j2Index(indexName, indexClass, this); |
| 292 | + return _createIndex(indexName, indexClass); |
279 | 293 | } else if (this.rawGraph.index().existsForRelationships(indexName)) { |
280 | 294 | throw ExceptionFactory.indexDoesNotSupportClass(indexName, indexClass); |
281 | 295 | } else { |
282 | 296 | return null; |
283 | 297 | } |
284 | 298 | } else if (Edge.class.isAssignableFrom(indexClass)) { |
285 | 299 | if (this.rawGraph.index().existsForRelationships(indexName)) { |
286 | | - return new Neo4j2Index(indexName, indexClass, this); |
| 300 | + return _createIndex(indexName, indexClass); |
287 | 301 | } else if (this.rawGraph.index().existsForNodes(indexName)) { |
288 | 302 | throw ExceptionFactory.indexDoesNotSupportClass(indexName, indexClass); |
289 | 303 | } else { |
@@ -324,11 +338,11 @@ public Iterable<Index<? extends Element>> getIndices() { |
324 | 338 | final List<Index<? extends Element>> indices = new ArrayList<Index<? extends Element>>(); |
325 | 339 | for (final String name : this.rawGraph.index().nodeIndexNames()) { |
326 | 340 | if (!name.equals(Neo4j2Tokens.NODE_AUTO_INDEX)) |
327 | | - indices.add(new Neo4j2Index(name, Vertex.class, this)); |
| 341 | + indices.add(new Neo4j2VertexIndex(name, this)); |
328 | 342 | } |
329 | 343 | for (final String name : this.rawGraph.index().relationshipIndexNames()) { |
330 | 344 | if (!name.equals(Neo4j2Tokens.RELATIONSHIP_AUTO_INDEX)) |
331 | | - indices.add(new Neo4j2Index(name, Edge.class, this)); |
| 345 | + indices.add(new Neo4j2EdgeIndex(name, this)); |
332 | 346 | } |
333 | 347 | return indices; |
334 | 348 | } |
|
0 commit comments