Spring Data Graph

org.springframework.data.graph.neo4j.support
Class GraphDatabaseContext

java.lang.Object
  extended by org.springframework.data.graph.neo4j.support.GraphDatabaseContext

public class GraphDatabaseContext
extends Object

Mediator class for the graph related services like the GraphDatabaseService, the used NodeTypeStrategy, entity instantiators for nodes and relationships as well as a spring conversion service. It delegates the appropriate methods to those services. The services are not intended to be accessible from outside.

Since:
13.09.2010
Author:
Michael Hunger

Field Summary
static String DEFAULT_NODE_INDEX_NAME
           
static String DEFAULT_RELATIONSHIP_INDEX_NAME
           
 org.springframework.persistence.support.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> graphEntityInstantiator
           
 org.springframework.persistence.support.EntityInstantiator<RelationshipBacked,org.neo4j.graphdb.Relationship> relationshipEntityInstantiator
           
 
Constructor Summary
GraphDatabaseContext()
           
 
Method Summary
 org.neo4j.graphdb.Transaction beginTx()
          delegates to @{link GraphDatabaseService}
 long count(Class<? extends GraphBacked> entityClass)
          delegates to the configured @{link NodeTypeStrategy} for a count of all instances of this type
<S,T extends GraphBacked>
T
createEntityFromState(S state, Class<T> type)
          Creates either a node or relationship entity by delegating the creation to the appropriate @{link EntityInstantiator}
<T extends NodeBacked>
T
createEntityFromStoredType(org.neo4j.graphdb.Node node)
           
 org.neo4j.graphdb.Node createNode()
           
<T extends GraphBacked>
Iterable<T>
findAll(Class<T> clazz)
          delegates to the configured @{link NodeTypeStrategy} to iterate over all instances of this type
 Iterable<? extends org.neo4j.graphdb.Node> getAllNodes()
          delegates to @{link GraphDatabaseService}
 ConversionService getConversionService()
           
 org.neo4j.graphdb.GraphDatabaseService getGraphDatabaseService()
           
 org.springframework.persistence.support.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> getGraphEntityInstantiator()
           
<T extends org.neo4j.graphdb.PropertyContainer,N extends GraphBacked<T>>
org.neo4j.graphdb.index.Index<T>
getIndex(Class<N> type, String indexName)
           
<T extends org.neo4j.graphdb.PropertyContainer,N extends GraphBacked<T>>
org.neo4j.graphdb.index.Index<T>
getIndex(Class<N> type, String indexName, boolean fullText)
           
<T extends NodeBacked>
Class<T>
getJavaType(org.neo4j.graphdb.Node node)
          delegates to the configured @{link NodeTypeStrategy} to lookup the type information for the given node
 org.neo4j.graphdb.Node getNodeById(long nodeId)
           
 NodeTypeStrategy getNodeTypeStrategy()
           
 org.neo4j.graphdb.Node getOrCreateSubReferenceNode(org.neo4j.graphdb.RelationshipType relType)
           
 org.neo4j.graphdb.Node getReferenceNode()
           
 org.neo4j.graphdb.Relationship getRelationshipById(long id)
          delegates to @{link GraphDatabaseService}
 org.springframework.persistence.support.EntityInstantiator<RelationshipBacked,org.neo4j.graphdb.Relationship> getRelationshipEntityInstantiator()
           
 TransactionManager getTxManager()
           
 javax.validation.Validator getValidator()
           
 void postEntityCreation(NodeBacked entity)
          delegates to the configured @{link NodeTypeStrategy} for after entity creation operations
<T extends GraphBacked>
T
projectTo(GraphBacked entity, Class<T> targetType)
           
 void removeNodeEntity(NodeBacked entity)
          removes the entity by cleaning the relationships first and then removing the node it removes all of them from all indexes in advance the entity and relationship are still accessible after removal but before transaction commit but all modifications will throw an exception
 void removeRelationshipEntity(RelationshipBacked entity)
           
 void setConversionService(ConversionService conversionService)
           
 void setGraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService graphDatabaseService)
           
 void setGraphEntityInstantiator(org.springframework.persistence.support.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> graphEntityInstantiator)
           
 void setNodeTypeStrategy(NodeTypeStrategy nodeTypeStrategy)
           
 void setRelationshipEntityInstantiator(org.springframework.persistence.support.EntityInstantiator<RelationshipBacked,org.neo4j.graphdb.Relationship> relationshipEntityInstantiator)
           
 void setValidator(javax.validation.Validator validatorFactory)
           
 boolean transactionIsRunning()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NODE_INDEX_NAME

public static final String DEFAULT_NODE_INDEX_NAME
See Also:
Constant Field Values

DEFAULT_RELATIONSHIP_INDEX_NAME

public static final String DEFAULT_RELATIONSHIP_INDEX_NAME
See Also:
Constant Field Values

graphEntityInstantiator

public org.springframework.persistence.support.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> graphEntityInstantiator

relationshipEntityInstantiator

public org.springframework.persistence.support.EntityInstantiator<RelationshipBacked,org.neo4j.graphdb.Relationship> relationshipEntityInstantiator
Constructor Detail

GraphDatabaseContext

public GraphDatabaseContext()
Method Detail

getGraphDatabaseService

public org.neo4j.graphdb.GraphDatabaseService getGraphDatabaseService()

setGraphDatabaseService

public void setGraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService graphDatabaseService)

getGraphEntityInstantiator

public org.springframework.persistence.support.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> getGraphEntityInstantiator()

setGraphEntityInstantiator

public void setGraphEntityInstantiator(org.springframework.persistence.support.EntityInstantiator<NodeBacked,org.neo4j.graphdb.Node> graphEntityInstantiator)

getRelationshipEntityInstantiator

public org.springframework.persistence.support.EntityInstantiator<RelationshipBacked,org.neo4j.graphdb.Relationship> getRelationshipEntityInstantiator()

setRelationshipEntityInstantiator

public void setRelationshipEntityInstantiator(org.springframework.persistence.support.EntityInstantiator<RelationshipBacked,org.neo4j.graphdb.Relationship> relationshipEntityInstantiator)

getConversionService

public ConversionService getConversionService()

setConversionService

public void setConversionService(ConversionService conversionService)

getNodeTypeStrategy

public NodeTypeStrategy getNodeTypeStrategy()

setNodeTypeStrategy

public void setNodeTypeStrategy(NodeTypeStrategy nodeTypeStrategy)

createNode

public org.neo4j.graphdb.Node createNode()

removeNodeEntity

public void removeNodeEntity(NodeBacked entity)
removes the entity by cleaning the relationships first and then removing the node it removes all of them from all indexes in advance the entity and relationship are still accessible after removal but before transaction commit but all modifications will throw an exception

Parameters:
entity - to remove

removeRelationshipEntity

public void removeRelationshipEntity(RelationshipBacked entity)

createEntityFromState

public <S,T extends GraphBacked> T createEntityFromState(S state,
                                                         Class<T> type)
Creates either a node or relationship entity by delegating the creation to the appropriate @{link EntityInstantiator}

Parameters:
state - Node or Relationship
type - target entity type
Returns:
an instance of the entity type

getIndex

public <T extends org.neo4j.graphdb.PropertyContainer,N extends GraphBacked<T>> org.neo4j.graphdb.index.Index<T> getIndex(Class<N> type,
                                                                                                                          String indexName)
Parameters:
indexName - or null, "node" is assumed if null
Returns:
node index Index

getIndex

public <T extends org.neo4j.graphdb.PropertyContainer,N extends GraphBacked<T>> org.neo4j.graphdb.index.Index<T> getIndex(Class<N> type,
                                                                                                                          String indexName,
                                                                                                                          boolean fullText)
Parameters:
type - type of index requested - either Node.class or Relationship.class
indexName - or null, "node" is assumed if null
fullText - true if a fulltext queryable index is needed, false for exact match
Returns:
node index Index

getNodeById

public org.neo4j.graphdb.Node getNodeById(long nodeId)
Parameters:
nodeId -
Returns:
Node
Throws:
org.neo4j.graphdb.NotFoundException

postEntityCreation

public void postEntityCreation(NodeBacked entity)
delegates to the configured @{link NodeTypeStrategy} for after entity creation operations

Parameters:
entity -

findAll

public <T extends GraphBacked> Iterable<T> findAll(Class<T> clazz)
delegates to the configured @{link NodeTypeStrategy} to iterate over all instances of this type

Type Parameters:
T -
Parameters:
clazz - type of entity
Returns:
TODO inheritance handling

count

public long count(Class<? extends GraphBacked> entityClass)
delegates to the configured @{link NodeTypeStrategy} for a count of all instances of this type

Parameters:
entityClass -
Returns:
count of all instances

getJavaType

public <T extends NodeBacked> Class<T> getJavaType(org.neo4j.graphdb.Node node)
delegates to the configured @{link NodeTypeStrategy} to lookup the type information for the given node

Type Parameters:
T -
Parameters:
node -
Returns:
entity type of the node
Throws:
IllegalStateException - for nodes that are not instance backing nodes of a known type

getReferenceNode

public org.neo4j.graphdb.Node getReferenceNode()
Returns:
reference node of the graph database

getOrCreateSubReferenceNode

public org.neo4j.graphdb.Node getOrCreateSubReferenceNode(org.neo4j.graphdb.RelationshipType relType)
Parameters:
relType -
Returns:

getTxManager

public TransactionManager getTxManager()
Returns:
Neo4j Transaction manager

transactionIsRunning

public boolean transactionIsRunning()
Returns:
true if a transaction manager is available and a transaction is currently running

getAllNodes

public Iterable<? extends org.neo4j.graphdb.Node> getAllNodes()
delegates to @{link GraphDatabaseService}


beginTx

public org.neo4j.graphdb.Transaction beginTx()
delegates to @{link GraphDatabaseService}


getRelationshipById

public org.neo4j.graphdb.Relationship getRelationshipById(long id)
delegates to @{link GraphDatabaseService}


projectTo

public <T extends GraphBacked> T projectTo(GraphBacked entity,
                                           Class<T> targetType)

getValidator

public javax.validation.Validator getValidator()

setValidator

public void setValidator(javax.validation.Validator validatorFactory)

createEntityFromStoredType

public <T extends NodeBacked> T createEntityFromStoredType(org.neo4j.graphdb.Node node)

Spring Data Graph

Copyright © 2011. All Rights Reserved.