Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Node


    return createTuple( neo4jCRUD.createNodeUnlessExists( key, ENTITY ) );
  }

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


   * </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 ) {
      // 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 deleteTempNodeAndUpdateRelationshipWithEntity( 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 createRelationshipToTempNode( associationKey, rowKey );
    }
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 deleteTempNodeAndUpdateRelationshipWithEntity(AssociationKey associationKey, RowKey rowKey, Node rowKeyNode) {
    Node ownerNode = neo4jCRUD.findNode( associationKey.getEntityKey(), ENTITY );
    Relationship inverseRelationship = updateInverseRelationship( rowKey, rowKeyNode, ownerNode );

    RelationshipType associationType = relationshipType( associationKey );
    Relationship relationship = null;
    if ( !associationKey.getCollectionRole().equals( associationKey.getTable() ) ) {
      relationship = ownerNode.createRelationshipTo( inverseRelationship.getStartNode(), associationType );
      applyColumnValues( rowKey, relationship );
    }
    return relationship;
  }
View Full Code Here

    return newInverseRelationship;
  }

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

    applyColumnValues( rowKey, relationship );
    return relationship;
  }

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

  private int sequence(RowKey rowKey, int increment) {
    Transaction tx = neo4jDb.beginTx();
    Lock lock = null;
    try {
      Node sequence = getSequence( rowKey );
      lock = tx.acquireWriteLock( sequence );
      int nextValue = updateSequenceValue( sequence, increment );
      tx.success();
      lock.release();
      return nextValue;
View Full Code Here

   */
  private Node getSequence(RowKey rowKey) {
    String updateSequenceQuery = getQuery( rowKey );
    ExecutionResult result = engine.execute( updateSequenceQuery, singletonMap( SEQUENCE_NAME_QUERY_PARAM, (Object) sequenceName( rowKey ) ) );
    ResourceIterator<Node> column = result.columnAs( "n" );
    Node node = null;
    if ( column.hasNext() ) {
      node = column.next();
    }
    column.close();
    return node;
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 = neo4jCRUD.findNode( key, ENTITY );
    if ( entityNode == null ) {
      return null;
    }
    return createTuple( entityNode );
  }
View Full Code Here

    return createTuple( neo4jCRUD.createNodeUnlessExists( key, ENTITY ) );
  }

  @Override
  public void updateTuple(Tuple tuple, EntityKey key, TupleContext tupleContext) {
    Node node = (Node) ( (Neo4jTupleSnapshot) tuple.getSnapshot() ).getPropertyContainer();
    applyTupleOperations( node, tuple.getOperations() );
  }
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.