示例#1
0
  public IndexRepresentation createRelationshipIndex(Map<String, Object> indexSpecification) {
    final String indexName = (String) indexSpecification.get("name");
    if (indexSpecification.containsKey("config")) {

      @SuppressWarnings("unchecked")
      Map<String, String> config = (Map<String, String>) indexSpecification.get("config");
      graphDb.index().forRelationships(indexName, config);

      return new RelationshipIndexRepresentation(indexName, config);
    }

    graphDb.index().forRelationships(indexName);
    return new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap());
  }
示例#2
0
  public ListRepresentation getIndexedRelationshipsByQuery(
      String indexName, String key, String query) {
    if (!graphDb.index().existsForRelationships(indexName)) throw new NotFoundException();
    List<Representation> representations = new ArrayList<Representation>();
    Index<Relationship> index = graphDb.index().forRelationships(indexName);

    Transaction tx = graphDb.beginTx();
    try {
      for (Relationship rel : index.query(key, query)) {
        representations.add(new RelationshipRepresentation(rel));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
    } finally {
      tx.finish();
    }
  }
示例#3
0
  public ListRepresentation getIndexedNodesByQuery(String indexName, String key, String query) {
    if (!graphDb.index().existsForNodes(indexName)) throw new NotFoundException();
    Index<Node> index = graphDb.index().forNodes(indexName);
    List<Representation> representations = new ArrayList<Representation>();

    Transaction tx = graphDb.beginTx();
    try {
      if (query != null) {
        for (Node node : index.query(key, query)) {
          representations.add(new NodeRepresentation(node));
        }
      }
      tx.success();
      return new ListRepresentation(RepresentationType.NODE, representations);
    } finally {
      tx.finish();
    }
  }
示例#4
0
  public ListRepresentation getIndexedRelationships(String indexName, String key, String value) {
    if (!graphDb.index().existsForRelationships(indexName)) throw new NotFoundException();
    List<IndexedEntityRepresentation> representations =
        new ArrayList<IndexedEntityRepresentation>();
    Index<Relationship> index = graphDb.index().forRelationships(indexName);

    Transaction tx = graphDb.beginTx();
    try {
      IndexRepresentation indexRepresentation = new RelationshipIndexRepresentation(indexName);
      for (Relationship node : index.get(key, value)) {
        representations.add(new IndexedEntityRepresentation(node, key, value, indexRepresentation));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
    } finally {
      tx.finish();
    }
  }
示例#5
0
  public ListRepresentation getIndexedNodes(String indexName, String key, String value) {
    if (!graphDb.index().existsForNodes(indexName)) throw new NotFoundException();
    Index<Node> index = graphDb.index().forNodes(indexName);
    List<IndexedEntityRepresentation> representations =
        new ArrayList<IndexedEntityRepresentation>();

    Transaction tx = graphDb.beginTx();
    try {
      IndexRepresentation indexRepresentation = new NodeIndexRepresentation(indexName);
      IndexHits<Node> indexHits = index.get(key, value);
      for (Node node : indexHits) {
        representations.add(new IndexedEntityRepresentation(node, key, value, indexRepresentation));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.NODE, representations);
    } finally {
      tx.finish();
    }
  }
示例#6
0
 public void removeRelationshipIndex(String indexName) {
   Index<Relationship> index = graphDb.index().forRelationships(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.delete();
     tx.success();
   } finally {
     tx.finish();
   }
 }
示例#7
0
 public void removeNodeIndex(String indexName) {
   Index<Node> index = graphDb.index().forNodes(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.delete();
     tx.success();
   } finally {
     tx.finish();
   }
 }
示例#8
0
 public void removeFromRelationshipIndexNoKeyValue(String indexName, long id) {
   RelationshipIndex index = graphDb.index().forRelationships(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.remove(graphDb.getRelationshipById(id));
     tx.success();
   } finally {
     tx.finish();
   }
 }
示例#9
0
 public void removeFromNodeIndexNoKeyValue(String indexName, long id) {
   Index<Node> index = graphDb.index().forNodes(indexName);
   Transaction tx = graphDb.beginTx();
   try {
     index.remove(graphDb.getNodeById(id));
     tx.success();
   } finally {
     tx.finish();
   }
 }
示例#10
0
  public boolean nodeIsIndexed(String indexName, String key, Object value, long nodeId)
      throws DatabaseBlockedException {

    Index<Node> index = graphDb.index().forNodes(indexName);
    Transaction tx = graphDb.beginTx();
    try {
      Node expectedNode = graphDb.getNodeById(nodeId);
      IndexHits<Node> hits = index.get(key, value);
      boolean contains = iterableContains(hits, expectedNode);
      tx.success();
      return contains;
    } finally {
      tx.finish();
    }
  }
示例#11
0
  public boolean relationshipIsIndexed(
      String indexName, String key, Object value, long relationshipId)
      throws DatabaseBlockedException {

    Index<Relationship> index = graphDb.index().forRelationships(indexName);
    Transaction tx = graphDb.beginTx();
    try {
      Relationship expectedNode = graphDb.getRelationshipById(relationshipId);
      IndexHits<Relationship> hits = index.get(key, value);
      boolean contains = iterableContains(hits, expectedNode);
      tx.success();
      return contains;
    } finally {
      tx.finish();
    }
  }
示例#12
0
  public Representation getAutoIndexedRelationships(String key, String value) {

    List<Representation> representations = new ArrayList<Representation>();
    ReadableRelationshipIndex index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex();

    Transaction tx = graphDb.beginTx();
    try {
      for (Relationship rel : index.get(key, value)) {
        representations.add(new RelationshipRepresentation(rel));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
    } finally {
      tx.finish();
    }
  }
示例#13
0
  public Representation getAutoIndexedNodes(String key, String value) {

    List<Representation> representations = new ArrayList<Representation>();
    ReadableIndex<Node> index = graphDb.index().getNodeAutoIndexer().getAutoIndex();

    Transaction tx = graphDb.beginTx();
    try {
      for (Node node : index.get(key, value)) {
        representations.add(new NodeRepresentation(node));
      }
      tx.success();
      return new ListRepresentation(RepresentationType.NODE, representations);
    } finally {
      tx.finish();
    }
  }
示例#14
0
 public IndexedEntityRepresentation addToNodeIndex(
     String indexName, String key, String value, long nodeId) {
   Transaction tx = graphDb.beginTx();
   try {
     Node node = graphDb.getNodeById(nodeId);
     Index<Node> index = graphDb.index().forNodes(indexName);
     index.add(node, key, value);
     tx.success();
     return new IndexedEntityRepresentation(
         node,
         key,
         value,
         new NodeIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
   } finally {
     tx.finish();
   }
 }
示例#15
0
  public ListRepresentation getAutoIndexedNodesByQuery(String query) {
    ReadableIndex<Node> index = graphDb.index().getNodeAutoIndexer().getAutoIndex();
    List<Representation> representations = new ArrayList<Representation>();

    if (query != null) {
      Transaction tx = graphDb.beginTx();
      try {
        for (Node node : index.query(query)) {
          representations.add(new NodeRepresentation(node));
        }
        tx.success();
      } finally {
        tx.finish();
      }
    }
    return new ListRepresentation(RepresentationType.NODE, representations);
  }
示例#16
0
 public IndexedEntityRepresentation addToRelationshipIndex(
     String indexName, String key, String value, long relationshipId) {
   Transaction tx = graphDb.beginTx();
   try {
     Relationship relationship = graphDb.getRelationshipById(relationshipId);
     Index<Relationship> index = graphDb.index().forRelationships(indexName);
     index.add(relationship, key, value);
     tx.success();
     return new IndexedEntityRepresentation(
         relationship,
         key,
         value,
         new RelationshipIndexRepresentation(indexName, Collections.<String, String>emptyMap()));
   } finally {
     tx.finish();
   }
 }
示例#17
0
  public ListRepresentation getAutoIndexedRelationshipsByQuery(String query) {
    ReadableRelationshipIndex index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex();
    List<Representation> representations = new ArrayList<Representation>();

    if (query != null) {
      Transaction tx = graphDb.beginTx();
      try {
        for (Relationship rel : index.query(query)) {
          representations.add(new RelationshipRepresentation(rel));
        }
        tx.success();
      } finally {
        tx.finish();
      }
    }
    return new ListRepresentation(RepresentationType.RELATIONSHIP, representations);
  }
示例#18
0
 public Representation nodeIndexRoot() {
   return new NodeIndexRootRepresentation(graphDb.index());
 }
示例#19
0
 public Representation relationshipIndexRoot() {
   return new RelationshipIndexRootRepresentation(graphDb.index());
 }
示例#20
0
 public String[] getRelationshipIndexNames() {
   return graphDb.index().relationshipIndexNames();
 }
 private void index(Node n) {
   db.index().forNodes("people").add(n, "name", n.getProperty("name"));
 }
示例#22
0
 public String[] getNodeIndexNames() {
   return graphDb.index().nodeIndexNames();
 }