Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Transaction


        }
        return node;
    }
    
     private void deleteNode(Node node){
        Transaction tx = graphDb.beginTx();
        try {           
            node.delete();           
            tx.success();      
        } catch (Exception ex){
            System.out.println(ex.getMessage());           
        } finally {
            tx.finish();
        }
     }
View Full Code Here


            tx.finish();
        }
     }
    
     private void deleteRelationship(Relationship rel){
        Transaction tx = graphDb.beginTx();
        try {           
            rel.delete();           
            tx.success();      
        } catch (Exception ex){
            System.out.println(ex.getMessage());           
        } finally {
            tx.finish();
        }
     }
View Full Code Here

    displayRelationship(r05);

    /* Perform selections on the graph database */
    System.out.println("\n*** MEMBERS RELATIONSHIPS SELECTION ***");
    // Use a transaction for selections because it's required by Neo4J...
    Transaction transaction = graphDatabase.beginTx();

    // Find a node according to a property value (search for Tony member)
    System.out.println("** Find a node according to a property value (search for Tony member)");
    Iterable<Node> members = graphDatabase.getAllNodes();
    long tonyId = -1;
    for (Node member : members) {
      if (member.hasProperty("MemberName") && "Tony".equals(member.getProperty("MemberName"))) {
        System.out.printf("Tony found, is node ID is %s\n", member.getId());
        tonyId = member.getId();
      }
    }

    // Get all relationships of a specific node (of Tony member in this
    // case)
    System.out.println("** Get all relationships of a specific node (of Tony member in this case)");
    // --Get directory access to the node using is unique ID
    Node tonyNode = graphDatabase.getNodeById(tonyId);
    // --Get is relationships in both directions (from this node to another
    // node (OUTGOING direction name) and another node to this node
    // (INCOMING direction name))
    Iterator<Relationship> relationships = tonyNode.getRelationships(Direction.BOTH).iterator();
    while (relationships.hasNext()) {
      displayRelationship(relationships.next());
    }

    // Use a traverser to traverse all specific relationships that ending to
    // a specific node (our goal here is to find all teamate member of
    // Guillaume)
    System.out.println("** Use a traverser to traverse all specific relationships that ending to a specific node (our goal here is to find all teamate member of Guillaume)");
    Node guillaumeNode = graphDatabase.getNodeById(3);
    Traverser teammates = guillaumeNode.traverse(Order.BREADTH_FIRST, StopEvaluator.END_OF_GRAPH, ReturnableEvaluator.ALL_BUT_START_NODE, SocialNetworkRelationship.TEAMMATE, Direction.INCOMING);
    for (Node teammateMember : teammates) {
      System.out.printf("%s (NodeID=%s)\n", teammateMember.getProperty("MemberName"), teammateMember.getId());
    }

    // Finalize transaction
    // If success() method isn't call (it's our case because we only
    // perforrm read operations) the transaction is rolledback on finish()
    // method invocation...
    transaction.finish();
  }
View Full Code Here

   * @throws Exception
   */
  private static Node createNode(GraphDatabaseService graphDb, String memberName) throws Exception {
    Node newNode = null;
    // Create and start a new transaction
    Transaction tx = graphDb.beginTx();
    try {
      // First search in the DB if the node do not already exists...
      Iterable<Node> members = graphDb.getAllNodes();
      for (Node member : members) {
        if (member.hasProperty("MemberName") && memberName.equals(member.getProperty("MemberName"))) {
          newNode = member;
          break;
        }
      }
      // Seconds try only to the create a new node if the node do not
      // exists in the DB
      if (newNode == null) {
        newNode = graphDb.createNode();
        // Set a property on the node representing the member name
        newNode.setProperty("MemberName", memberName);
      }
      // Mark the transaction as succeed
      tx.success();
    } catch (Exception e) {
      // Mark the transaction as failed
      tx.failure();
      throw e;
    } finally {
      // Mark the transactin as ended
      tx.finish();
    }
    return newNode;
  }
View Full Code Here

   * @throws Exception
   */
  private static Relationship createRelationship(GraphDatabaseService graphDb, Node ownerNode, Node counterpartNode, RelationshipType relationshipType) throws Exception {
    Relationship newRelationship = null;
    // Create and start a new transaction
    Transaction tx = graphDb.beginTx();
    try {
      // First check if the relationship do not already exists
      Iterator<Relationship> relationships = ownerNode.getRelationships(relationshipType, Direction.OUTGOING).iterator();
      while (relationships.hasNext()) {
        Relationship r = relationships.next();
        if (r.getEndNode().getProperty("MemberName").equals(counterpartNode.getProperty("MemberName"))) {
          newRelationship = r;
          break;
        }
      }
      // Seconds try only to the create a new relationship from the
      // owner node to the
      // target node if the relationships do not already exists in the DB
      if (newRelationship == null) {
        newRelationship = ownerNode.createRelationshipTo(counterpartNode, relationshipType);
      }
      // Mark the transaction as succeed
      tx.success();
    } catch (Exception e) {
      // Mark the transaction as failed
      tx.failure();
      throw e;
    } finally {
      // Mark the transactin as ended
      tx.finish();
    }
    return newRelationship;
  }
View Full Code Here

    @Graph("I know you")
    @TestData.Title( "Get service root" )
    public void assert200OkFromGet() throws Exception
    {
        AbstractGraphDatabase db = (AbstractGraphDatabase)graphdb();
        Transaction tx = db.beginTx();
        db.getConfig().getGraphDbModule().setReferenceNodeId( data.get().get("I").getId() );
        tx.success();
        tx.finish();
        String body = gen.get().expectedStatus( 200 ).get( getDataUri() ).entity();
        Map<String, Object> map = JsonHelper.jsonToMap( body );
        assertEquals( getDataUri() + "node", map.get( "node" ) );
        assertNotNull( map.get( "reference_node" ) );
        assertNotNull( map.get( "node_index" ) );
View Full Code Here

        this.graphDb = graphDb;
    }

    public void execute()
    {
        Transaction tx = graphDb.beginTx();

        try
        {
            unitOfWork.doWork();
            tx.success();
        }
        finally
        {
            tx.finish();
        }

    }
View Full Code Here

      }, indexRoot.getId())
    } finally {
      monitor.done();
    }

    Transaction tx = database.beginTx();
    try {
      // delete index root relationship
      indexRoot.getSingleRelationship(RTreeRelationshipTypes.RTREE_ROOT, Direction.INCOMING).delete();
     
      // delete tree
      deleteRecursivelySubtree(indexRoot);
     
      // delete tree metadata
      Relationship metadataNodeRelationship = getRootNode().getSingleRelationship(RTreeRelationshipTypes.RTREE_METADATA, Direction.OUTGOING);
      Node metadataNode = metadataNodeRelationship.getEndNode();
      metadataNodeRelationship.delete();
      metadataNode.delete();
   
      tx.success();
    } finally {
      tx.finish();
    }   
   
    countSaved = false;
    totalGeometryCount = 0;       
  }
View Full Code Here

      for (Long child : children) {
        visitInTx(visitor, child)
      }
    } else if (indexNode.hasRelationship(RTreeRelationshipTypes.RTREE_REFERENCE, Direction.OUTGOING)) {
      // Node is a leaf
      Transaction tx = database.beginTx();
      try {
        for (Relationship rel : indexNode.getRelationships(RTreeRelationshipTypes.RTREE_REFERENCE, Direction.OUTGOING)) {
          visitor.onIndexReference(rel.getEndNode());
        }
     
        tx.success();
      } finally {
        tx.finish();
      }
    }
  }
View Full Code Here

      totalGeometryCount = counter.getResult();
      countSaved = false;
    }
    
    if (!countSaved) {
      Transaction tx = database.beginTx();
      try {
        getMetadataNode().setProperty("totalGeometryCount", totalGeometryCount);
        countSaved = true;
        tx.success();
      } finally {
        tx.finish();
      }
    }
  } 
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.