Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.Relationship


     *
     * @return the relationship that was created between the indexedNode and the end node..
     */
    public Relationship createRelationshipTo( Node node )
    {
        Relationship keyValueRelationship = nodeCollection.addNode( node );
        if ( !keyValueRelationship.hasProperty( RELATIONSHIP_DIRECTION ) )
        {
            keyValueRelationship.setProperty( RELATIONSHIP_DIRECTION, direction.name() );
        }
        if ( !keyValueRelationship.hasProperty( RELATIONSHIP_TYPE ) )
        {
            keyValueRelationship.setProperty( RELATIONSHIP_TYPE, relType.name() );
        }
        return getRelationship( keyValueRelationship );
    }
View Full Code Here


        return new RelationshipIterator();
    }

    private NodeCollection getNodeCollection()
    {
        Relationship indexRelationship = null;
        for ( Relationship candidateRelationship : this.indexedNode.getRelationships( RelationshipTypes.NODE_COLLECTION, Direction.OUTGOING ) )
        {
            String relName = (String) candidateRelationship.getProperty( RELATIONSHIP_TYPE, null );
            if ( relType.name().equals( relName ) )
            {
                String dir = (String) candidateRelationship.getProperty( RELATIONSHIP_DIRECTION, null );
                if ( direction.name().equals( dir ) )
                {
                    if ( indexRelationship != null ) {
                        throw new IllegalStateException(
                            "Multiple IndexedRelationship's on the given node with relationship type: "  +
                                relType.name() + " and direction: " + direction.name());
                    }
                   
                    indexRelationship = candidateRelationship;
                }
            }
        }

        if ( indexRelationship != null )
        {
            return NodeCollectionLoader.load(indexRelationship.getEndNode());
        }

        return null;
    }
View Full Code Here

            public Neo4jEdge next() {
                if (!checkTransaction) {
                    return new Neo4jEdge(this.itty.next(), graph);
                } else {
                    if (null != this.nextRelationship) {
                        final Relationship temp = this.nextRelationship;
                        this.nextRelationship = null;
                        return new Neo4jEdge(temp, graph);
                    } else {
                        while (true) {
                            final Relationship relationship = this.itty.next();
                            try {
                                relationship.hasProperty(DUMMY_PROPERTY);
                                return new Neo4jEdge(relationship, graph);
                            } catch (final IllegalStateException e) {
                                // tried to access a relationship not available to the transaction
                            }
                        }
                    }
                }
            }

            public boolean hasNext() {
                if (!checkTransaction)
                    return this.itty.hasNext();
                else {
                    if (null != this.nextRelationship)
                        return true;
                    else {
                        while (this.itty.hasNext()) {
                            final Relationship relationship = this.itty.next();
                            try {
                                relationship.hasProperty(DUMMY_PROPERTY);
                                this.nextRelationship = relationship;
                                return true;
                            } catch (final IllegalStateException e) {
                            }
                        }
View Full Code Here

                graph.autoStartTransaction(false);
                if (!checkTransaction) {
                    return new Neo4j2Edge(this.itty.next(), graph);
                } else {
                    if (null != this.nextRelationship) {
                        final Relationship temp = this.nextRelationship;
                        this.nextRelationship = null;
                        return new Neo4j2Edge(temp, graph);
                    } else {
                        while (true) {
                            final Relationship relationship = this.itty.next();
                            try {
                                if (!graph.relationshipIsDeleted(relationship.getId())) {
                                    return new Neo4j2Edge(relationship, graph);
                                }
                            } catch (final IllegalStateException e) {
                                // tried to access a relationship not available to the transaction
                            }
                        }
                    }
                }
            }

            public boolean hasNext() {
                graph.autoStartTransaction(false);
                if (!checkTransaction)
                    return this.itty.hasNext();
                else {
                    if (null != this.nextRelationship)
                        return true;
                    else {
                        while (this.itty.hasNext()) {
                            final Relationship relationship = this.itty.next();
                            try {
                                if (!graph.relationshipIsDeleted(relationship.getId())) {
                                    this.nextRelationship = relationship;
                                    return true;
                                }
                            } catch (final IllegalStateException e) {
                            }
View Full Code Here

            if( rel.getEndNode().equals( entityNode ) )
            {
                return false;
            }
        }
        Relationship rel = underlyingNode.createRelationshipTo( entityNode,
                                                                RelTypes.MANY_ASSOCIATION );
        setRelationshipIndex( rel, index );
        incrementCount();
        entity.setUpdated();
        return true;
View Full Code Here

    @Override
    public NamedAssociationState namedAssociationValueOf( QualifiedName stateName )
    {
        RelationshipType namedAssociation = namedAssociation( stateName );
        Relationship rel = underlyingNode.getSingleRelationship( namedAssociation, Direction.OUTGOING );
        if( rel != null )
        {
            return new NeoNamedAssociationState( uow, this, rel.getEndNode() );
        }
        Node node = uow.getNeo().createNode();
        node.setProperty( NeoNamedAssociationState.COUNT, 0 );
        underlyingNode.createRelationshipTo( node, namedAssociation );
        return new NeoNamedAssociationState( uow, this, node );
View Full Code Here

   
    @Override
    public ManyAssociationState manyAssociationValueOf( QualifiedName stateName )
    {
        RelationshipType manyAssociation = manyAssociation( stateName );
        Relationship rel = underlyingNode.getSingleRelationship( manyAssociation, Direction.OUTGOING );
        if( rel != null )
        {
            return new NeoManyAssociationState( uow, this, rel.getEndNode() );
        }
        Node node = uow.getNeo().createNode();
        node.setProperty( NeoManyAssociationState.COUNT, 0 );
        underlyingNode.createRelationshipTo( node, manyAssociation );
        return new NeoManyAssociationState( uow, this, node );
View Full Code Here

    }

    @Override
    public EntityReference associationValueOf( QualifiedName stateName )
    {
        Relationship rel = underlyingNode.getSingleRelationship( association( stateName ), Direction.OUTGOING );
        if( rel != null )
        {
            String entityId = (String) rel.getEndNode().getProperty( ENTITY_ID );
            return new EntityReference( entityId );
        }
        return null;
    }
View Full Code Here

    @Override
    public void setAssociationValue( QualifiedName stateName, EntityReference newEntity )
    {
        RelationshipType association = association( stateName );
        Relationship rel = underlyingNode.getSingleRelationship( association, Direction.OUTGOING );
        if( rel != null )
        {
            Node otherNode = rel.getEndNode();
            if( otherNode.getProperty( ENTITY_ID ).equals( identity().identity() ) )
            {
                otherNode.delete();
            }
            rel.delete();
        }
        if( newEntity != null )
        {
            Node otherNode = uow.getEntityStateNode( newEntity );
            if( otherNode.equals( underlyingNode ) )
View Full Code Here

                rel.delete();
                decrementCount();
                break;
            }
        }
        Relationship rel = underlyingNode.createRelationshipTo( entityNode, RelTypes.NAMED_ASSOCIATION );
        setRelationshipName( rel, name );
        incrementCount();
        entity.setUpdated();
        return true;
    }
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.