Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Node


   * </ol>
   * So the same RowKey cannot be created for two different associations at the same time from within the same
   * transaction.
   */
  private PropertyContainer createRelationshipToEntityOrToTempNode(AssociationKey associationKey, RowKey rowKey) {
    Node rowKeyNode = neo4jCRUD.findNode( rowKey );
    // Check if there is an entity or a temporary node representing the RowKey
    if ( rowKeyNode == null ) {
      if ( associationKey.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) {
        return createNodeAndAddRelationship( associationKey, rowKey, NodeLabel.EMBEDDED );
      }
      else {
        // We look for the entity at the end of the association, if we cannot find it
        // we save the RowKey in a temporary node.
        return findEntityOrCreateTempNode( associationKey, rowKey );
      }
    }
    else if ( rowKeyNode.hasLabel( ENTITY ) ) {
      // The RowKey represents an entity and we are going to create the relationship to it
      return createRelationshipWithEntity( associationKey, rowKey, rowKeyNode );
    }
    else if ( rowKeyNode.hasLabel( TEMP_NODE ) ) {
      // We have found a temporary node related to this association, we are going to delete it and connect the
      // entity pointing to the temporary node and the owner of this association.
      return deleteTempNodeAndCreateRelationshipWithEntity( associationKey, rowKey, rowKeyNode );
    }
    else {
View Full Code Here


    }
  }

  private PropertyContainer findEntityOrCreateTempNode(AssociationKey associationKey, RowKey rowKey) {
    EntityKey endNodeKey = endNodeKey( associationKey, rowKey );
    Node endNode = neo4jCRUD.findNode( endNodeKey, ENTITY );
    if ( endNode == null ) {
      // We cannot find the entity on the other side of the relationship, we store the information related to
      // the RowKey in a temporary node and we create a relationship to it
      return createNodeAndAddRelationship( associationKey, rowKey, TEMP_NODE );
    }
View Full Code Here

    return new EntityKey( new EntityKeyMetadata( associationKey.getTable(), keyColumnNames.toArray( new String[keyColumnNames.size()] ) ),
        keyColumnValues.toArray( new Object[keyColumnValues.size()] ) );
  }

  private Relationship deleteTempNodeAndCreateRelationshipWithEntity(AssociationKey associationKey, RowKey rowKey, Node tempNode) {
    Node ownerNode = neo4jCRUD.findNode( associationKey.getEntityKey(), ENTITY );
    Iterator<Relationship> iterator = tempNode.getRelationships( Direction.INCOMING ).iterator();
    Relationship tempRelationship = iterator.next();
    Relationship relationship = ownerNode.createRelationshipTo( tempRelationship.getStartNode(), relationshipType( associationKey ) );
    applyColumnValues( rowKey, relationship );
    tempRelationship.delete();
    tempNode.delete();
    return relationship;
  }
View Full Code Here

    tempNode.delete();
    return relationship;
  }

  private PropertyContainer createRelationshipWithEntity(AssociationKey associationKey, RowKey rowKey, Node node) {
    Node ownerNode = neo4jCRUD.findNode( associationKey.getEntityKey(), ENTITY );
    Relationship relationship = ownerNode.createRelationshipTo( node, relationshipType( associationKey ) );
    applyColumnValues( rowKey, relationship );
    return relationship;
  }
View Full Code Here

    applyColumnValues( rowKey, relationship );
    return relationship;
  }

  private PropertyContainer createNodeAndAddRelationship(AssociationKey associationKey, RowKey rowKey, NodeLabel label) {
    Node rowKeyNode = neo4jCRUD.createNodeUnlessExists( rowKey, label );
    return createRelationshipWithEntity( associationKey, rowKey, rowKeyNode );
  }
View Full Code Here

    }
  }

  @Override
  public Association getAssociation(AssociationKey associationKey, AssociationContext associationContext) {
    Node entityNode = neo4jCRUD.findNode( associationKey.getEntityKey(), ENTITY );
    if ( entityNode == null ) {
      return null;
    }
    return new Association( new Neo4jAssociationSnapshot( entityNode, associationKey ) );
  }
View Full Code Here

  public void forEachTuple(Consumer consumer, EntityKeyMetadata... entityKeyMetadatas) {
    for ( EntityKeyMetadata entityKeyMetadata : entityKeyMetadatas ) {
      ResourceIterator<Node> queryNodes = neo4jCRUD.findNodes( entityKeyMetadata.getTable() );
      try {
        while ( queryNodes.hasNext() ) {
          Node next = queryNodes.next();
          Tuple tuple = createTuple( next );
          consumer.consume( tuple );
        }
      }
      finally {
View Full Code Here

    StringBuilder query = new StringBuilder( "MATCH" );
    appendNodePattern( key, parameters, query, label );
    query.append( " RETURN n" );
    ExecutionResult result = engine.execute( query.toString(), parameters );
    ResourceIterator<Node> column = result.columnAs( "n" );
    Node node = null;
    if ( column.hasNext() ) {
      node = column.next();
    }
    column.close();
    return node;
View Full Code Here

    StringBuilder query = new StringBuilder( "MERGE" );
    appendNodePattern( key, parameters, query, label );
    query.append( " RETURN n" );
    ExecutionResult result = engine.execute( query.toString(), parameters );
    ResourceIterator<Node> column = result.columnAs( "n" );
    Node node = null;
    if ( column.hasNext() ) {
      node = column.next();
    }
    column.close();
    return node;
View Full Code Here


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


        query = parser.parse("start v=(vehicles, 'vehicleId:" + vehicle.getId() + "')  match (v) <-[USE]- (w)    return w");
       
        //query = parser.parse("start s=(procedures, 'procedureId:" + procedure.getId() + "')  match (s) <-[SUB]- (p)    return p");

        result = engine.execute(query);
        n_column = result.columnAs("w");
       
        assertEquals(1, result.size());
       
         while (n_column.hasNext()) {
            Node currentNode = n_column.next();
            for (String key : currentNode.getPropertyKeys()) {
                System.out.println("Property (" + key + "): " + currentNode.getProperty(key));
            }
        }
       
    }
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.