Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Relationship


  @Override
  public void add(int index, Node element) {
    if (index < 0 || index >= size())
      throw new IndexOutOfBoundsException();
    Relationship currentEntryRelation = underlyingNode
        .getSingleRelationship(RelTypes.FIRST_ELEMENT,
            Direction.OUTGOING);
    Node currentEntry = currentEntryRelation.getEndNode();
    if (index == 0) {
      currentEntryRelation.delete();
      Node newEntry = graphDb.createNode();
      underlyingNode.createRelationshipTo(newEntry,
          RelTypes.FIRST_ELEMENT);
      newEntry.createRelationshipTo(currentEntry, RelTypes.NEXT_ELEMENT);
      newEntry.createRelationshipTo(element, RelTypes.LIST_ENTRY);
      underlyingNode.setProperty(INDEX_SIZE, 1);
    } else {
      for (int i = 0; i < index; i++) {
        currentEntryRelation = currentEntry.getSingleRelationship(
            RelTypes.NEXT_ELEMENT, Direction.OUTGOING);
        currentEntry = currentEntryRelation.getEndNode();
      }
      Node prevEntry = currentEntryRelation.getStartNode();
      currentEntryRelation.delete();
      Node newEntry = graphDb.createNode();
      prevEntry.createRelationshipTo(newEntry, RelTypes.NEXT_ELEMENT);
      newEntry.createRelationshipTo(currentEntry, RelTypes.NEXT_ELEMENT);
      newEntry.createRelationshipTo(element, RelTypes.LIST_ENTRY);
      int i = (Integer) underlyingNode.getProperty(INDEX_SIZE);
View Full Code Here


                count++;
            }
            assertTrue( page.hasProperty( UnrolledLinkedList.ITEM_COUNT ) );
            assertEquals( count, page.getProperty( UnrolledLinkedList.ITEM_COUNT ) );

            Relationship next = page.getSingleRelationship(
                DynamicRelationshipType.withName( "NEXT_PAGE" ), Direction.OUTGOING );
            if ( next != null )
            {
                page = next.getEndNode();
            }
            else
            {
                page = null;
            }
View Full Code Here

        Node node1 = graphDb().createNode();
        node1.setProperty( "name", "node 1" );
        Node node2 = graphDb().createNode();
        node2.setProperty( "name", "node 2" );

        Relationship relationship1 = ir.createRelationshipTo( node1 );
        relationship1.setProperty( "rel property", "relationship 1" );
        Relationship relationship2 = ir.createRelationshipTo( node2 );
        relationship2.setProperty( "rel property", "relationship 2" );

        IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.OUTGOING,
            TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP );

        int count = 0;
View Full Code Here

            TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP, Direction.OUTGOING, st2 );

        Node destination = graphDb().createNode();
        destination.setProperty( "name", "node 1" );

        Relationship relationship1 = ir.createRelationshipTo( destination );
        relationship1.setProperty( "rel property", "relationship 1" );
        Relationship relationship2 = ir2.createRelationshipTo( destination );
        relationship2.setProperty( "rel property", "relationship 2" );

        IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.INCOMING,
            TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP );

        int count = 0;
View Full Code Here

        Node node1 = graphDb().createNode();
        node1.setProperty( "name", "node 1" );
        Node node2 = graphDb().createNode();
        node2.setProperty( "name", "node 2" );

        Relationship relationship1 = ir.createRelationshipTo( node1 );
        relationship1.setProperty( "rel property", "relationship 1" );
        Relationship relationship2 = ir.createRelationshipTo( node2 );
        relationship2.setProperty( "rel property", "relationship 2" );

        IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.OUTGOING,
            RelTypes.INDEXED_RELATIONSHIP );

        int count = 0;
View Full Code Here

            Direction.OUTGOING, ull2 );

        Node destination = graphDb().createNode();
        destination.setProperty( "name", "node 1" );

        Relationship relationship1 = ir.createRelationshipTo( destination );
        relationship1.setProperty( "rel property", "relationship 1" );
        Relationship relationship2 = ir2.createRelationshipTo( destination );
        relationship2.setProperty( "rel property", "relationship 2" );

        IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.INCOMING,
            RelTypes.INDEXED_RELATIONSHIP );

        int count = 0;
View Full Code Here

       
        // Nodes are added last first therefore reverse the order of the numbers when adding
        int count = 19;
        for ( Node node : nodes )
        {
            Relationship relationship = list.addNode( node );
            relationship.setProperty( "count", count-- );
        }

        Collections.reverse( nodes );
        UnrolledLinkedList loaded = new UnrolledLinkedList( list.getBaseNode() );
        count = 0;
        for ( Relationship relationship : loaded.getValueRelationships() )
        {
            assertEquals( count, relationship.getProperty( "count" ) );
            assertEquals( nodes.get( count++ ), relationship.getEndNode() );
        }
        assertEquals( nodes.size(), count );
    }
View Full Code Here

            }
            Random random = new Random();
            for (int i = 0; i < max * 2; i++) {
                int from = random.nextInt(max);
                final int to = (from + 1 + random.nextInt(max - 1)) % max;
                final Relationship relationship = nodes[from].createRelationshipTo(nodes[to], DynamicRelationshipType.withName("TEST_" + i));
                final Index<Relationship> index = indexManager.forRelationships("rel_index_" + String.valueOf(i % 5));
                index.add(relationship, "ID", i);
            }
            tx.success();
        } finally {
View Full Code Here

                        if ( path.length() == 0 )
                        {
                            return Evaluation.EXCLUDE_AND_CONTINUE;
                        }

                        Relationship relationship = path.lastRelationship();
                        if ( path.length() == 1 )
                        {
                            if ( relationship.getType().name().equals( NodeCollection.RelationshipTypes.VALUE.name() ) ) {
                                String relationshipType = (String) relationship.getProperty(
                                    IndexedRelationship.RELATIONSHIP_TYPE, null );
                                String relationshipDirection = (String) relationship.getProperty(
                                    IndexedRelationship.RELATIONSHIP_DIRECTION, null );

                                if ( relType.name().equals( relationshipType ) &&
                                    direction.reverse().name().equals( relationshipDirection ) )
                                {
                                    return Evaluation.EXCLUDE_AND_CONTINUE;
                                }
                            }

                            return Evaluation.EXCLUDE_AND_PRUNE;
                        }

                        if ( relationship.getType().name().equals( IndexedRelationship.RelationshipTypes.NODE_COLLECTION.name() ) )
                        {
                            return Evaluation.INCLUDE_AND_PRUNE;
                        }
                       
                        return Evaluation.EXCLUDE_AND_CONTINUE;
View Full Code Here

     *
     * @param nodeCollection the { @link NodeCollection } backing this indexed relationship.
     */
    public void create( NodeCollection nodeCollection )
    {
        Relationship indexRelationship = indexedNode.createRelationshipTo( nodeCollection.getBaseNode(), RelationshipTypes.NODE_COLLECTION );
        indexRelationship.setProperty( RELATIONSHIP_TYPE, relType.name() );
        indexRelationship.setProperty( RELATIONSHIP_DIRECTION, direction.name() );
        this.nodeCollection = nodeCollection;
    }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.Relationship

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.