Spring Data Graph

org.springframework.data.neo4j.support.typerepresentation
Class SubReferenceNodeTypeRepresentationStrategy

java.lang.Object
  extended by org.springframework.data.neo4j.support.typerepresentation.SubReferenceNodeTypeRepresentationStrategy
All Implemented Interfaces:
NodeTypeRepresentationStrategy, TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>

public class SubReferenceNodeTypeRepresentationStrategy
extends Object
implements NodeTypeRepresentationStrategy

A TypeRepresentationStrategy that uses a hierarchy of reference nodes to represent the java type of the entity in the graph database. Entity nodes are related to their concrete type via an INSTANCE_OF relationship, the type hierarchy is related to supertypes via SUBCLASS_OF relationships. Each concrete subreference node keeps a count property with the number of instances of this class in the graph.

Since:
13.09.2010
Author:
Michael Hunger

Field Summary
static org.neo4j.graphdb.RelationshipType INSTANCE_OF_RELATIONSHIP_TYPE
           
static org.neo4j.graphdb.RelationshipType SUBCLASS_OF_RELATIONSHIP_TYPE
           
static String SUBREF_CLASS_KEY
           
static String SUBREF_PREFIX
           
static String SUBREFERENCE_NODE_COUNTER_KEY
           
 
Constructor Summary
SubReferenceNodeTypeRepresentationStrategy(org.neo4j.graphdb.GraphDatabaseService graphDatabaseService, org.springframework.data.persistence.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> entityInstantiator)
           
 
Method Summary
static void acquireWriteLock(org.neo4j.graphdb.PropertyContainer entity)
           
 long count(Class<? extends NodeBacked> entityClass)
           
<U extends NodeBacked>
U
createEntity(org.neo4j.graphdb.Node state)
          Instantiate the entity given its state.
<U extends NodeBacked>
U
createEntity(org.neo4j.graphdb.Node state, Class<U> type)
          Instantiate the entity given its state.
static Integer decrementAndGetCounter(org.neo4j.graphdb.Node node, String propertyKey, int notLowerThan)
           
<T extends NodeBacked>
org.neo4j.helpers.collection.ClosableIterable<T>
findAll(Class<T> clazz)
           
 org.neo4j.graphdb.Node findSubreferenceNode(Class<? extends NodeBacked> entityClass)
           
<T extends NodeBacked>
Class<T>
getJavaType(org.neo4j.graphdb.Node node)
           
 org.neo4j.graphdb.Node getOrCreateSubReferenceNode(org.neo4j.graphdb.RelationshipType relType)
           
static org.neo4j.graphdb.Node getSingleOtherNode(org.neo4j.graphdb.Node node, org.neo4j.graphdb.RelationshipType type, org.neo4j.graphdb.Direction direction)
           
static Integer incrementAndGetCounter(org.neo4j.graphdb.Node node, String propertyKey)
           
 org.neo4j.graphdb.Node obtainSubreferenceNode(Class<?> entityClass)
           
 void postEntityCreation(org.neo4j.graphdb.Node state, Class<? extends NodeBacked> type)
          Callback for setting up and/or storing type information after creation.
 void preEntityRemoval(org.neo4j.graphdb.Node state)
          Callback for cleaning up type information before removal.
<U extends NodeBacked>
U
projectEntity(org.neo4j.graphdb.Node state, Class<U> type)
          Instantiate the entity of the given type, with the given state as backing state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE_OF_RELATIONSHIP_TYPE

public static final org.neo4j.graphdb.RelationshipType INSTANCE_OF_RELATIONSHIP_TYPE

SUBCLASS_OF_RELATIONSHIP_TYPE

public static final org.neo4j.graphdb.RelationshipType SUBCLASS_OF_RELATIONSHIP_TYPE

SUBREFERENCE_NODE_COUNTER_KEY

public static final String SUBREFERENCE_NODE_COUNTER_KEY
See Also:
Constant Field Values

SUBREF_PREFIX

public static final String SUBREF_PREFIX
See Also:
Constant Field Values

SUBREF_CLASS_KEY

public static final String SUBREF_CLASS_KEY
See Also:
Constant Field Values
Constructor Detail

SubReferenceNodeTypeRepresentationStrategy

public SubReferenceNodeTypeRepresentationStrategy(org.neo4j.graphdb.GraphDatabaseService graphDatabaseService,
                                                  org.springframework.data.persistence.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> entityInstantiator)
Method Detail

getSingleOtherNode

public static org.neo4j.graphdb.Node getSingleOtherNode(org.neo4j.graphdb.Node node,
                                                        org.neo4j.graphdb.RelationshipType type,
                                                        org.neo4j.graphdb.Direction direction)

incrementAndGetCounter

public static Integer incrementAndGetCounter(org.neo4j.graphdb.Node node,
                                             String propertyKey)

decrementAndGetCounter

public static Integer decrementAndGetCounter(org.neo4j.graphdb.Node node,
                                             String propertyKey,
                                             int notLowerThan)

acquireWriteLock

public static void acquireWriteLock(org.neo4j.graphdb.PropertyContainer entity)

postEntityCreation

public void postEntityCreation(org.neo4j.graphdb.Node state,
                               Class<? extends NodeBacked> type)
Description copied from interface: TypeRepresentationStrategy
Callback for setting up and/or storing type information after creation.

Specified by:
postEntityCreation in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Parameters:
state - Backing state of entity being created
type - Type of entity being created

count

public long count(Class<? extends NodeBacked> entityClass)
Specified by:
count in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Returns:
number of instances of this class contained in the graph

getJavaType

public <T extends NodeBacked> Class<T> getJavaType(org.neo4j.graphdb.Node node)
Specified by:
getJavaType in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Returns:
java type that of the node entity of this node

preEntityRemoval

public void preEntityRemoval(org.neo4j.graphdb.Node state)
Description copied from interface: TypeRepresentationStrategy
Callback for cleaning up type information before removal. If state does not have any state associated, doesn't do anything.

Specified by:
preEntityRemoval in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Parameters:
state - Backing state of entity being removed

findAll

public <T extends NodeBacked> org.neo4j.helpers.collection.ClosableIterable<T> findAll(Class<T> clazz)
Specified by:
findAll in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Parameters:
clazz - Type whose instances should be iterated over
Returns:
lazy Iterable over all instances of the given type

obtainSubreferenceNode

public org.neo4j.graphdb.Node obtainSubreferenceNode(Class<?> entityClass)

findSubreferenceNode

public org.neo4j.graphdb.Node findSubreferenceNode(Class<? extends NodeBacked> entityClass)

getOrCreateSubReferenceNode

public org.neo4j.graphdb.Node getOrCreateSubReferenceNode(org.neo4j.graphdb.RelationshipType relType)

createEntity

public <U extends NodeBacked> U createEntity(org.neo4j.graphdb.Node state)
Description copied from interface: TypeRepresentationStrategy
Instantiate the entity given its state. The type of the entity is inferred by the strategy from the state.

Specified by:
createEntity in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Type Parameters:
U - Helper parameter for castless use
Parameters:
state - Backing state of entity to be instantiated
Returns:
Entity instance

createEntity

public <U extends NodeBacked> U createEntity(org.neo4j.graphdb.Node state,
                                             Class<U> type)
Description copied from interface: TypeRepresentationStrategy
Instantiate the entity given its state. The type of the desired entity is also specified. If the type is not compatible with what the strategy can infer from the state, IllegalArgumentException is thrown.

Specified by:
createEntity in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Parameters:
state - Backing state of entity to be instantiated
type - Type of entity to be instantiated
Returns:
Entity instance

projectEntity

public <U extends NodeBacked> U projectEntity(org.neo4j.graphdb.Node state,
                                              Class<U> type)
Description copied from interface: TypeRepresentationStrategy
Instantiate the entity of the given type, with the given state as backing state. No checking is done by the strategy.

Specified by:
projectEntity in interface TypeRepresentationStrategy<org.neo4j.graphdb.Node,NodeBacked>
Parameters:
state - Backing state of entity to be instantiated
type - Type of entity to be instantiated
Returns:
Entity instance.

Spring Data Graph

Copyright © 2011 SpringSource. All Rights Reserved.