Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Node


    @Override
    public Relation add(Identifiable source, final String type, Identifiable target) {

        Transaction tx = graph.beginTx();
        try {
            Node root =graph.getNodeById(0);
            String sourceTypeName = source.getClass().getSimpleName();
            String targetTypeName = target.getClass().getSimpleName();
            Node sourceTypeNode = getOrCreateNodeType(sourceTypeName);
            Node targetTypeNode = getOrCreateNodeType(targetTypeName);
            getOrCreateRelationship(root, sourceTypeNode, Named.relation(sourceTypeName));
            getOrCreateRelationship(root, targetTypeNode, Named.relation(targetTypeName));

            Node sourceNode = getOrCreateNode(source, sourceTypeName);
            getOrCreateRelationship(sourceTypeNode, sourceNode, Named.relation(REL_TYPE_ALL));
            Node targetNode = getOrCreateNode(target, targetTypeName);
            getOrCreateRelationship(targetTypeNode, targetNode, Named.relation(REL_TYPE_ALL));

            getOrCreateRelationship(sourceNode, targetNode, Named.relation(type));

            tx.success();
View Full Code Here


        Transaction tx = graph.beginTx();
        try {
            Index<Node> nodeIndex = graph.index().forNodes(PROP_INDEX_NODE);
            Index<Relationship> relationIndex = graph.index().forRelationships(PROP_INDEX_REL);

            Node sourceNode = nodeIndex.get(PROP_ID, source.getId()).getSingle();
            Node targetNode = nodeIndex.get(PROP_ID, target.getId()).getSingle();
            for(Relationship rel : sourceNode.getRelationships(Named.relation(type))) {
                if(rel.getEndNode().equals(targetNode)) {
                    rel.delete();
                    relationIndex.remove(rel);
                }
View Full Code Here

            throw new RuntimeException("Could not locate a " + Repository.class.getName() + " instance for Type " + targetType.getName());
        }

        List<T> targets = new ArrayList<T>();
        Index<Node> index = graph.index().forNodes(PROP_INDEX_NODE);
        Node node = index.get(PROP_ID, source.getId()).getSingle();
        if(node == null) {
            return targets;
        }
        Transaction tx = graph.beginTx();

        try {
            Iterable<Relationship> relationships = node.getRelationships(Named.relation(type));
            for(Relationship relation : relationships) {
                String targetId = relation.getOtherNode(node).getProperty(PROP_ID).toString();
                T target = repo.get(targetId);
                if(target == null) {
                    // Do some auto clean up if target node not found in Target repo
View Full Code Here

        Iterator<Node> n_column = result.columnAs("n");


        System.out.println("results: " + result);
        while (n_column.hasNext()) {
            Node currentNode = n_column.next();
            for (String key : currentNode.getPropertyKeys()) {
                System.out.println("Property (" + key + "): " + currentNode.getProperty(key));
            }
        }
        assertEquals(1, result.size());
       
        query = parser.parse("start n=(procedures, 'procedureId:*')  return n");

        result = engine.execute(query);
        n_column = result.columnAs("n");


        System.out.println("results: " + result);
        while (n_column.hasNext()) {
            Node currentNode = n_column.next();
            for (String key : currentNode.getPropertyKeys()) {
                System.out.println("Property (" + key + "): " + currentNode.getProperty(key));
            }
        }
        assertEquals(1, result.size());

    }
View Full Code Here

        Iterator<Node> n_column = result.columnAs("n");


        System.out.println("results: " + result);
        while (n_column.hasNext()) {
            Node currentNode = n_column.next();
            for (String key : currentNode.getPropertyKeys()) {
                System.out.println("Property (" + key + "): " + currentNode.getProperty(key));
            }
        }
        assertEquals(1, result.size());
       
        query = parser.parse("start n=(procedures, 'procedureId:*')  return n");

        result = engine.execute(query);
        n_column = result.columnAs("n");


        System.out.println("results: " + result);
        while (n_column.hasNext()) {
            Node currentNode = n_column.next();
            for (String key : currentNode.getPropertyKeys()) {
                System.out.println("Property (" + key + "): " + currentNode.getProperty(key));
            }
        }
        assertEquals(1, result.size());
    }
View Full Code Here

   * @param initialValue
   *            the first value returned when a new sequence is created
   * @return the next value in a sequence
   */
  public int nextValue(RowKey rowKey, int increment, final int initialValue) {
    Node sequenceNode = getOrCreateSequence( rowKey, initialValue );
    return updateSequence( sequenceNode, increment );
  }
View Full Code Here

  private Node getOrCreateSequence(RowKey key, final int initialValue) {
    Transaction tx = neo4jDb.beginTx();
    try {
      UniqueFactory<Node> factory = nodeFactory( initialValue );
      Node sequenceNode = factory.getOrCreate( ID_SEQUENCE_PROPERTY, generateId( key ) );
      tx.success();
      return sequenceNode;
    }
    finally {
      tx.finish();
View Full Code Here

    throw new UnsupportedOperationException( "LockMode " + lockMode + " is not supported by the Neo4j GridDialect" );
  }

  @Override
  public Tuple getTuple(EntityKey key, TupleContext context) {
    Node entityNode = findNode( key );
    if ( entityNode == null ) {
      return null;
    }
    return createTuple( entityNode );
  }
View Full Code Here

    return new Tuple();
  }

  @Override
  public void updateTuple(Tuple tuple, EntityKey key, TupleContext tupleContext) {
    Node node = createNodeUnlessExists( key );
    applyTupleOperations( node, tuple.getOperations() );
  }
View Full Code Here

    applyTupleOperations( node, tuple.getOperations() );
  }

  @Override
  public void removeTuple(EntityKey key, TupleContext tupleContext) {
    Node entityNode = findNode( key );
    if ( entityNode != null ) {
      removeRelationships( entityNode );
      removeNode( entityNode );
    }
  }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.Node

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.