Neo4j

org.neo4j.graphdb
Interface PropertyContainer

All Known Subinterfaces:
Node, Relationship

public interface PropertyContainer

Defines a common API for handling properties on both nodes and relationships.

Properties are key-value pairs. The keys are always strings. Valid property value types are all the Java primitives (int, byte, float, etc), java.lang.Strings and arrays of primitives and Strings.

Please note that Neo4j does NOT accept arbitrary objects as property values. setProperty() takes a java.lang.Object only to avoid an explosion of overloaded setProperty() methods.


Method Summary
 GraphDatabaseService getGraphDatabase()
          Get the GraphDatabaseService that this Node or Relationship belongs to.
 Object getProperty(String key)
          Returns the property value associated with the given key.
 Object getProperty(String key, Object defaultValue)
          Returns the property value associated with the given key, or a default value.
 Iterable<String> getPropertyKeys()
          Returns all existing property keys, or an empty iterable if this property container has no properties.
 Iterable<Object> getPropertyValues()
          Deprecated. in favor of using getPropertyKeys() in combination with getProperty(String).
 boolean hasProperty(String key)
          Returns true if this property container has a property accessible through the given key, false otherwise.
 Object removeProperty(String key)
          Removes the property associated with the given key and returns the old value.
 void setProperty(String key, Object value)
          Sets the property value for the given key to value.
 

Method Detail

getGraphDatabase

GraphDatabaseService getGraphDatabase()
Get the GraphDatabaseService that this Node or Relationship belongs to.

Returns:
The GraphDatabase this Node or Relationship belongs to.

hasProperty

boolean hasProperty(String key)
Returns true if this property container has a property accessible through the given key, false otherwise. If key is null, this method returns false.

Parameters:
key - the property key
Returns:
true if this property container has a property accessible through the given key, false otherwise

getProperty

Object getProperty(String key)
Returns the property value associated with the given key. The value is of one of the valid property types, i.e. a Java primitive, a String or an array of any of the valid types.

If there's no property associated with key an unchecked exception is raised. The idiomatic way to avoid an exception for an unknown key and instead get null back is to use a default value: Object valueOrNull = nodeOrRel.getProperty( key, null )

Parameters:
key - the property key
Returns:
the property value associated with the given key
Throws:
NotFoundException - if there's no property associated with key

getProperty

Object getProperty(String key,
                   Object defaultValue)
Returns the property value associated with the given key, or a default value. The value is of one of the valid property types, i.e. a Java primitive, a String or an array of any of the valid types.

Parameters:
key - the property key
defaultValue - the default value that will be returned if no property value was associated with the given key
Returns:
the property value associated with the given key

setProperty

void setProperty(String key,
                 Object value)
Sets the property value for the given key to value. The property value must be one of the valid property types, i.e:

This means that null is not an accepted property value.

Parameters:
key - the key with which the new property value will be associated
value - the new property value, of one of the valid property types
Throws:
IllegalArgumentException - if value is of an unsupported type (including null)

removeProperty

Object removeProperty(String key)
Removes the property associated with the given key and returns the old value. If there's no property associated with the key, null will be returned.

Parameters:
key - the property key
Returns:
the property value that used to be associated with the given key

getPropertyKeys

Iterable<String> getPropertyKeys()
Returns all existing property keys, or an empty iterable if this property container has no properties.

Returns:
all property keys on this property container

getPropertyValues

@Deprecated
Iterable<Object> getPropertyValues()
Deprecated. in favor of using getPropertyKeys() in combination with getProperty(String).

Returns all currently valid property values, or an empty iterable if this node has no properties. All values are of a supported property type, i.e. a Java primitive, a String or an array of any of the supported types.

Note: This method is deprecated and will be removed in future releases. Use a combination of getPropertyKeys() and getProperty(String) to achieve the same result.

Returns:
all property values

Neo4j

Copyright © 2002-2014 The Neo4j Graph Database Project. All Rights Reserved.