Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.tinkerpop.blueprints.impls.neo4j2;
  
 
 import java.util.Map;


Author(s):
Marko A. Rodriguez (http://markorodriguez.com)
 
 public class Neo4j2Index<T extends Neo4j2Element, S extends PropertyContainerimplements Index<T> {
 
     private final Class<T> indexClass;
     protected final Neo4j2Graph graph;
     private final String indexName;
     protected org.neo4j.graphdb.index.Index<S> rawIndex;
 
     protected Neo4j2Index(final String indexNamefinal Class<T> indexClassfinal Neo4j2Graph graphfinal Parameter... indexParameters) {
         this. = indexClass;
         this. = graph;
         this. = indexName;
         this.generateIndex(indexParameters);
     }
 
     public Class<T> getIndexClass() {
         if (Vertex.class.isAssignableFrom(this.))
             return (ClassVertex.class;
         else
             return (ClassEdge.class;
     }
 
     public String getIndexName() {
         return this.;
     }
 
     public void put(final String keyfinal Object valuefinal T element) {
         try {
             this..autoStartTransaction(true);
             this..add((S) element.getRawElement(), keyvalue);
         } catch (Exception e) {
             throw new RuntimeException(e.getMessage(), e);
         }
     }

    

The underlying Neo4j graph does not natively support this method within a transaction. If the graph is not currently in a transaction, then the operation runs efficiently. If the graph is in a transaction, then, for every element, a try/catch is used to determine if its in the current transaction.

 
     public CloseableIterable<T> get(final String keyfinal Object value) {
         this..autoStartTransaction(false);
         final IndexHits<S> itty = this..get(keyvalue);
         if (this..isAssignableFrom(Neo4j2Vertex.class))
             return new Neo4j2VertexIterable((Iterable<Node>) ittythis.this..checkElementsInTransaction());
         else
             return new Neo4j2EdgeIterable((Iterable<Relationship>) ittythis.this..checkElementsInTransaction());
     }

    

The underlying Neo4j graph does not natively support this method within a transaction. If the graph is not currently in a transaction, then the operation runs efficiently. If the graph is in a transaction, then, for every element, a try/catch is used to determine if its in the current transaction.

 
     public CloseableIterable<T> query(final String keyfinal Object query) {
         this..autoStartTransaction(false);
         final IndexHits<S> itty = this..query(keyquery);
         if (this..isAssignableFrom(Neo4j2Vertex.class))
             return new Neo4j2VertexIterable((Iterable<Node>) ittythis.this..checkElementsInTransaction());
         else
             return new Neo4j2EdgeIterable((Iterable<Relationship>) ittythis.this..checkElementsInTransaction());
     }

    

The underlying Neo4j graph does not natively support this method within a transaction. If the graph is not currently in a transaction, then the operation runs efficiently. If the graph is in a transaction, then, for every element, a try/catch is used to determine if its in the current transaction.

 
     public long count(final String keyfinal Object value) {
         this..autoStartTransaction(false);
         if (!this..checkElementsInTransaction()) {
             final IndexHits hits = this..get(keyvalue);
             final long count = hits.size();
            hits.close();
            return count;
        } else {
            final CloseableIterable<T> hits = this.get(keyvalue);
            long count = 0;
            for (final T t : hits) {
                count++;
            }
            hits.close();
            return count;
        }
    }
    public void remove(final String keyfinal Object valuefinal T element) {
        try {
            this..autoStartTransaction(true);
            this..remove((S) element.getRawElement(), keyvalue);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
    private void generateIndex(final Parameter<ObjectObject>... indexParameters) {
        this..autoStartTransaction(true);
        final IndexManager manager = this..getRawGraph().index();
        if (Vertex.class.isAssignableFrom(this.)) {
            if (indexParameters.length > 0)
                this. = (org.neo4j.graphdb.index.Index<S>) manager.forNodes(this.generateParameterMap(indexParameters));
            else
                this. = (org.neo4j.graphdb.index.Index<S>) manager.forNodes(this.);
        } else {
            if (indexParameters.length > 0)
                this. = (org.neo4j.graphdb.index.Index<S>) manager.forRelationships(this.generateParameterMap(indexParameters));
            else
                this. = (org.neo4j.graphdb.index.Index<S>) manager.forRelationships(this.);
        }
    }
    public String toString() {
        return StringFactory.indexString(this);
    }
    private static Map<StringStringgenerateParameterMap(final Parameter<ObjectObject>... indexParameters) {
        final Map<StringStringmap = new HashMap<StringString>();
        for (final Parameter<ObjectObjectparameter : indexParameters) {
            map.put(parameter.getKey().toString(), parameter.getValue().toString());
        }
        return map;
    }
    public org.neo4j.graphdb.index.Index<S> getRawIndex() {
        return this.;
    }
New to GrepCode? Check out our FAQ X