Class DetachedEntity<ID,T extends Entity>
- java.lang.Object
-
- com.graphaware.common.representation.DetachedEntity<ID,T>
-
- Type Parameters:
T
- type of theEntity
this class represents.
- All Implemented Interfaces:
EntityExpressions
,Serializable
- Direct Known Subclasses:
DetachedNode
,DetachedRelationship
public abstract class DetachedEntity<ID,T extends Entity> extends Object implements Serializable, EntityExpressions
Representation of a Neo4j entity.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static long
NEW
-
Constructor Summary
Constructors Modifier Constructor Description protected
DetachedEntity()
No-arg constructor (for Jackson et al).protected
DetachedEntity(long graphId)
Construct a representation of a entity from its internal Neo4j ID.protected
DetachedEntity(long graphId, Map<String,Object> properties)
Construct a new representation of a entity from its internal Neo4j ID and a map of properties.protected
DetachedEntity(Map<String,Object> properties)
Construct a new representation of a entity from a map of properties.protected
DetachedEntity(T entity, String[] properties)
Construct a new representation from a entity.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkCanCreate()
Check that this instance of entity representation can be created in the db.protected void
checkCanFetch()
Check that this instance of entity representation can be fetched from the db.protected abstract T
create(Transaction tx)
Create a new entity from this representation in the given database.boolean
equals(Object o)
protected abstract T
fetch(Transaction tx)
Fetch a entity from the given database.long
getGraphId()
protected abstract ID
getId()
Map<String,Object>
getProperties()
int
hashCode()
protected void
populate(T t)
Populate this instance of a entity representation with data from the givenEntity
.T
produceEntity(Transaction tx)
Produce aEntity
from this representation.protected String[]
propertyKeySetAsStringArray(Iterable<String> keySet)
Returns a properties keyset from a graph object to a string arrayvoid
putProperty(String key, Object value)
Add a property.void
setGraphId(long graphId)
void
setProperties(Map<String,Object> properties)
Set properties.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.graphaware.common.expression.EntityExpressions
getProperty, getProperty, hasProperty
-
-
-
-
Field Detail
-
NEW
public static final long NEW
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DetachedEntity
protected DetachedEntity()
No-arg constructor (for Jackson et al).
-
DetachedEntity
protected DetachedEntity(T entity, String[] properties)
Construct a new representation from a entity.- Parameters:
entity
- to construct a representation from. Must not benull
.properties
- keys of properties to be included in the representation. Can benull
, which represents all. Empty array represents none.
-
DetachedEntity
protected DetachedEntity(long graphId)
Construct a representation of a entity from its internal Neo4j ID.- Parameters:
graphId
- ID.
-
DetachedEntity
protected DetachedEntity(Map<String,Object> properties)
Construct a new representation of a entity from a map of properties.- Parameters:
properties
- of the new entity. Must not benull
, but can be empty.
-
DetachedEntity
protected DetachedEntity(long graphId, Map<String,Object> properties)
Construct a new representation of a entity from its internal Neo4j ID and a map of properties.Note that this constructor is only intended for testing.
- Parameters:
graphId
- ID.properties
- of the new entity. Must not benull
, but can be empty.
-
-
Method Detail
-
getId
protected abstract ID getId()
-
putProperty
public void putProperty(String key, Object value)
Add a property.- Parameters:
key
- key. Must not benull
.value
- value. Must not benull
.
-
produceEntity
public T produceEntity(Transaction tx)
Produce aEntity
from this representation. This means either fetch the entity from the given tx (iff id is set), or create it.- Parameters:
tx
- to create/fetch entity in.- Returns:
- entity.
-
create
protected abstract T create(Transaction tx)
Create a new entity from this representation in the given database.- Parameters:
tx
- to create the entity in.- Returns:
- entity.
-
fetch
protected abstract T fetch(Transaction tx)
Fetch a entity from the given database.- Parameters:
tx
- to fetch in.- Returns:
- entity.
-
populate
protected void populate(T t)
Populate this instance of a entity representation with data from the givenEntity
.- Parameters:
t
- to populate from.
-
checkCanCreate
protected void checkCanCreate()
Check that this instance of entity representation can be created in the db.- Throws:
IllegalStateException
- if not possible to create.
-
checkCanFetch
protected void checkCanFetch()
Check that this instance of entity representation can be fetched from the db.- Throws:
IllegalStateException
- if not possible to fetch.
-
getGraphId
public long getGraphId()
-
setGraphId
public void setGraphId(long graphId)
-
getProperties
public Map<String,Object> getProperties()
- Specified by:
getProperties
in interfaceEntityExpressions
- Returns:
- properties. Can be
null
.
-
setProperties
public void setProperties(Map<String,Object> properties)
Set properties.- Parameters:
properties
- Must not benull
, but can be empty.
-
propertyKeySetAsStringArray
protected String[] propertyKeySetAsStringArray(Iterable<String> keySet)
Returns a properties keyset from a graph object to a string array- Parameters:
keySet
- properties keyset
-
-