Interface Entity
- All Known Subinterfaces:
Node
,Relationship
Entity
that is persisted in the database, and identified by an getElementId()
element id}.
Nodes
and Relationships
are Entities.
Entities are attached to transaction in which they were accessed. Outside of transaction it's possible only to access an entity's element id.
All other methods should be called only in the scope of the owning transaction.
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.String
s, the Spatial
and Temporal types and arrays of any of these.
The complete list of currently supported property types is:
boolean
byte
short
int
long
float
double
char
java.lang.String
org.neo4j.graphdb.spatial.Point
java.time.LocalDate
java.time.OffsetTime
java.time.LocalTime
java.time.ZonedDateTime
It is also possible to usejava.time.OffsetDateTime
and it will be converted to aZonedDateTime
internally.java.time.LocalDateTime
java.time.temporal.TemporalAmount
There are two concrete implementations of this interface,java.time.Duration
andjava.time.Period
which will be converted to a single Neo4jDuration
type. This means loss of type information, so properties of this type, when read back usinggetProperty
will be only of typejava.time.temporal.TemporalAmount
.- Arrays of any of the above types, for example
int[]
,String[]
orLocalTime[]
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
Modifier and TypeMethodDescriptionvoid
delete()
Deletes this entity.Returns all existing properties.Returns the unique element id of this entity.long
getId()
Deprecated, for removal: This API element is subject to removal in a future version.getProperties
(String... keys) Returns specified existing properties.getProperty
(String key) Returns the property value associated with the given key.getProperty
(String key, Object defaultValue) Returns the property value associated with the given key, or a default value.Returns all existing property keys, or an empty iterable if this property container has no properties.boolean
hasProperty
(String key) Returnstrue
if this property container has a property accessible through the given key,false
otherwise.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 tovalue
.
-
Method Details
-
getId
Deprecated, for removal: This API element is subject to removal in a future version.in favor ofgetElementId()
.Returns the unique id of this entity. Id's are reused over time so they are only guaranteed to be unique during a specific transaction: if the entity is deleted, it is likely that some new entity will reuse this id at some point.- Returns:
- The id of this Entity.
-
getElementId
String getElementId()Returns the unique element id of this entity. Id's are reused over time so they are only guaranteed to be unique during a specific transaction: if the entity is deleted, it is likely that some new entity will reuse this id at some point.- Returns:
- The element id of this Entity.
-
hasProperty
Returnstrue
if this property container has a property accessible through the given key,false
otherwise. If key isnull
, this method returnsfalse
.- Parameters:
key
- the property key- Returns:
true
if this property container has a property accessible through the given key,false
otherwise
-
getProperty
Returns the property value associated with the given key. The value is of one of the valid property types, i.e. a Java primitive, aString
, aPoint
, a valid temporal type, or an array of any of the valid types. See thethe class description
for a full list of known 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 getnull
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 withkey
-
getProperty
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, aString
, aPoint
, a valid temporal type, or an array of any of the valid types. See thethe class description
for a full list of known types.- Parameters:
key
- the property keydefaultValue
- 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
Sets the property value for the given key tovalue
. The property value must be one of the valid property types, i.e. a Java primitive, aString
, aPoint
, a valid temporal type, or an array of any of the valid types. See thethe class description
for a full list of known types.This means that
null
is not an accepted property value.- Parameters:
key
- the key with which the new property value will be associatedvalue
- the new property value, of one of the valid property types- Throws:
IllegalArgumentException
- ifvalue
is of an unsupported type (includingnull
)
-
removeProperty
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
Returns all existing property keys, or an empty iterable if this property container has no properties.- Returns:
- all property keys on this property container
-
getProperties
Returns specified existing properties. The collection is mutable, but changing it has no impact on the graph as the data is detached.- Parameters:
keys
- the property keys to return- Returns:
- specified properties on this property container
- Throws:
NullPointerException
- if the array of keys or any key is null
-
getAllProperties
Returns all existing properties.- Returns:
- all properties on this property container
-
delete
void delete()Deletes this entity.- Throws:
NotFoundException
- if any methods are invoked on this entity afterdelete()
-
getElementId()
.