Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.neo4j.graphdb
Interface RelationshipType

All Known Implementing Classes:
  DynamicRelationshipType

    public interface RelationshipType

A relationship type is mandatory on all relationships and is used to navigate the node space. RelationshipType is in particular a key part of the `traverser framework` but it's also used in various `relationship operations` on Node.

Relationship types are declared by the client and can be handled either dynamically or statically in a Neo4j-based application. Internally, relationship types are dynamic. This means that every time a client invokes `node.createRelationshipTo(anotherNode, newRelType)` and passes in a new relationship type then the new type will be transparently created. So instantiating a RelationshipType instance will not create it in the underlying storage, it is persisted only when the first relationship of that type is created.

However, in case the application does not need to dynamically create relationship types (most don't), then it's nice to have the compile-time benefits of a static set of relationship types. Fortunately, RelationshipType is designed to work well with Java 5 enums. This means that it's very easy to define a set of valid relationship types by declaring an enum that implements RelationshipType and then reuse that across the application. For example, here's how you would define an enum to hold all your relationship types:

     enum MyRelationshipTypes implements RelationshipType
     {
         CONTAINED_IN, KNOWS
     }

Then later, it's as easy to use as:

     node.createRelationshipTo( anotherNode, MyRelationshipTypes.KNOWS );
     for ( Relationship rel : node.getRelationships( MyRelationshipTypes.KNOWS ) )
     {
            // ...
     }

It's very important to note that a relationship type is uniquely identified by its name, not by any particular instance that implements this interface. This means that the proper way to check if two relationship types are equal is by invoking `equals()` on their `names`, NOT by using Java's identity operator (`==`) or `equals()` on the relationship type instances. A consequence of this is that you can NOT use relationship types in hashed collections such as `HashMap` and `HashSet`.

However, you usually want to check whether a specific relationship instance is of a certain type. That is best achieved with the `Relationship.isType` method, such as: ``

     if ( rel.isType( MyRelationshipTypes.CONTAINED_IN ) )
     {
         ...
     }

Method Summary
`String` | `name()` Returns the name of the relationship type.

Method Detail

### name

    String name()

  Returns the name of the relationship type. The name uniquely identifies a relationship type, i.e. two different RelationshipType instances with different object identifiers (and possibly even different classes) are semantically equivalent if they have `equal` names.

  Returns:
    the name of the relationship type

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2011 The Neo4j Graph Database Project. All Rights Reserved.