Package science.aist.neo4j.reflective
Class ClassInformation
- java.lang.Object
-
- science.aist.neo4j.reflective.ClassInformation
-
public class ClassInformation extends Object
ClassInformation handles the metadata for theReflectiveNeo4JNodeRepositoryImplIt contains info on the id, fields and relationships that should be modelled in the database- Since:
- 1.0
- Author:
- Oliver Krauss
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClassInformation.Neo4JTypeType of neo4J instance, Can be either a Node, or a Relationship.
-
Field Summary
Fields Modifier and Type Field Description protected Class<?>clazzClass that this info is forstatic StringEXTENSION_IDENTIFIERprotected Map<String,FieldInformation>fieldsFields in the db for this class (@Transient -> not in db)protected FieldInformationidId of the the classprotected LinkedList<String>labelsAll labels of the class, incl.protected StringnamespaceNamespace of the classprotected booleannamespaceawareif the class information will behave with or without namespaces.static StringNEO4J_EXTENSIONS_FIELDstatic StringNEO4J_LABELS_FIELDstatic StringNEO4J_MAP_RELATIONSHIPS_FIELDstatic StringNeo4J_RELATION_FIELDstatic StringNEO4J_SYNC_FIELDprotected LinkedList<String>nsLabelsAll labels of the class with namespace added.protected Map<String,RelationshipInformation>relationshipsRelationships in dbstatic ReflectiveNeo4JNodeRepositoryImplrequestingRepositoryRepository currently asking for Class Information.protected StringsignatureSignature of class including the generic type namesstatic StringSOURCEstatic StringTARGETprotected ClassInformation.Neo4JTypetypeNeo4J Instance Type for this Class Information
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Objectcast(Long id, Map<String,Object> value, List<org.neo4j.driver.types.Relationship> relationships, List<org.neo4j.driver.types.Node> children, Map<Long,Object> nodes)Casts a database node or relationship into a java objectprotected Objectcast(org.neo4j.driver.types.Node value, List<org.neo4j.driver.types.Relationship> relationships, List<org.neo4j.driver.types.Node> children, Map<Long,Object> nodes)protected Objectcast(org.neo4j.driver.types.Relationship value, org.neo4j.driver.types.Node source, org.neo4j.driver.types.Node target, Map<Long,Object> castNodes)static <T> TcastToClass(Object o, Class<T> c)Casts a Neo4J database object to the required classstatic ClassInformationconstructClassInformation(Class clazz)Constructs the Class Information from a given class.static ClassInformationconstructClassInformation(Class clazz, boolean namespaceaware)Constructs the Class Information from a given class.protected static ClassInformationconstructClassInformation(ParameterizedType targetClass, String relationshipName)Constructs the Class information from a given class including the GENERIC TYPES.Map<String,Object>getAlternativeNamespaceFields(Object node)Provides a map of fields that alternative namespaces used in the given node.Map<String,Pair<org.neo4j.driver.types.Node,org.neo4j.driver.types.Relationship>>getAlternativeRelationshipsInNamespaces(Object node)Provides a map of relationships that alternative namespaces used in the given node.ClassgetClazz()ObjectgetExtension(Object node, String name)Returns the extension of name or null if it doesnt existMap<String,Object>getExtensions(Object node)Returns all extensions provided in the objectMap<String,FieldInformation>getFields()FieldInformationgetId()StringgetLabels()List<String>getLabels(Object node)Returns the database labels from the given nodeStringgetName()StringgetNamespace()StringgetNsLabels()StringgetNsName()Map<String,RelationshipInformation>getRelationships()ClassInformation.Neo4JTypegetType()booleanisNamespaceaware()gets value of fieldnamespaceawareMap<String,Object>objectifyProperties(Object node)turns the object into a map of fields->valuesvoidsetExtension(Object node, String name, Object extension)Adds the extension of name to the object o.booleansetExtensionSafe(Object node, String name, Object extension)Adds the extension of name to the object o.
-
-
-
Field Detail
-
NEO4J_SYNC_FIELD
public static final String NEO4J_SYNC_FIELD
- See Also:
- Constant Field Values
-
Neo4J_RELATION_FIELD
public static final String Neo4J_RELATION_FIELD
- See Also:
- Constant Field Values
-
NEO4J_LABELS_FIELD
public static final String NEO4J_LABELS_FIELD
- See Also:
- Constant Field Values
-
NEO4J_EXTENSIONS_FIELD
public static final String NEO4J_EXTENSIONS_FIELD
- See Also:
- Constant Field Values
-
EXTENSION_IDENTIFIER
public static final String EXTENSION_IDENTIFIER
- See Also:
- Constant Field Values
-
NEO4J_MAP_RELATIONSHIPS_FIELD
public static final String NEO4J_MAP_RELATIONSHIPS_FIELD
- See Also:
- Constant Field Values
-
SOURCE
public static final String SOURCE
- See Also:
- Constant Field Values
-
TARGET
public static final String TARGET
- See Also:
- Constant Field Values
-
requestingRepository
public static ReflectiveNeo4JNodeRepositoryImpl requestingRepository
Repository currently asking for Class Information. Used to auto-inject auto generated repositories.
-
clazz
protected Class<?> clazz
Class that this info is for
-
signature
protected String signature
Signature of class including the generic type names
-
labels
protected LinkedList<String> labels
All labels of the class, incl. its own name on the first position
-
nsLabels
protected LinkedList<String> nsLabels
All labels of the class with namespace added. Own name on first position
-
namespace
protected String namespace
Namespace of the class
-
id
protected FieldInformation id
Id of the the class
-
fields
protected Map<String,FieldInformation> fields
Fields in the db for this class (@Transient -> not in db)
-
relationships
protected Map<String,RelationshipInformation> relationships
Relationships in db
-
type
protected ClassInformation.Neo4JType type
Neo4J Instance Type for this Class Information
-
namespaceaware
protected boolean namespaceaware
if the class information will behave with or without namespaces. It WILL load the information regardless, but manages casting differently.
-
-
Method Detail
-
constructClassInformation
protected static ClassInformation constructClassInformation(ParameterizedType targetClass, String relationshipName)
Constructs the Class information from a given class including the GENERIC TYPES. TODO #22: Currently this is only used for MapRelationship, we may be able to support generics in general.- Parameters:
targetClass- Parameterized fieldClass of class.relationshipName- name of relationship, as this becomes part of the class identity.- Returns:
- Class information of targetClass
-
constructClassInformation
public static ClassInformation constructClassInformation(Class clazz)
Constructs the Class Information from a given class. It will fail if the class does not contain a valid ID field A Valid ID Field is either named "id" or contains theIdAnnotation- Parameters:
clazz- Class to be analized- Returns:
- ClassInformation for Neo4J DB transformation
-
constructClassInformation
public static ClassInformation constructClassInformation(Class clazz, boolean namespaceaware)
Constructs the Class Information from a given class. It will fail if the class does not contain a valid ID field A Valid ID Field is either named "id" or contains theIdAnnotation- Parameters:
clazz- Class to be analizednamespaceaware- -> if it is constructed with or without namespacing, per default it is not- Returns:
- ClassInformation for Neo4J DB transformation
-
cast
protected Object cast(org.neo4j.driver.types.Relationship value, org.neo4j.driver.types.Node source, org.neo4j.driver.types.Node target, Map<Long,Object> castNodes)
-
cast
protected Object cast(org.neo4j.driver.types.Node value, List<org.neo4j.driver.types.Relationship> relationships, List<org.neo4j.driver.types.Node> children, Map<Long,Object> nodes)
-
cast
protected Object cast(Long id, Map<String,Object> value, List<org.neo4j.driver.types.Relationship> relationships, List<org.neo4j.driver.types.Node> children, Map<Long,Object> nodes)
Casts a database node or relationship into a java object- Parameters:
id- java object will be asigned tovalue- map of values contained in the noderelationships- relationships in the subtreechildren- nodes not yet cast in the subtreenodes- nodes already cast in the subtree- Returns:
- cast result
-
objectifyProperties
public Map<String,Object> objectifyProperties(Object node)
turns the object into a map of fields->values- Parameters:
node- to be turned into a map- Returns:
- map of all fields
-
getAlternativeNamespaceFields
public Map<String,Object> getAlternativeNamespaceFields(Object node)
Provides a map of fields that alternative namespaces used in the given node. If the system doesn't consider namespaces, or no alternative namespaces exist yet NULL is returned- Parameters:
node- for which namepsace fields should be retrieved- Returns:
- Map with all alternative fields or null
Please note that the return map can also contain maps!
Warning: This is NOT READ ONLY. Changes WILL be stored in the DB.
-
getLabels
public List<String> getLabels(Object node)
Returns the database labels from the given node- Parameters:
node- to be checked- Returns:
- database labels or the labels the node will receive when stored into the db.
Warning: this is READ ONLY. No changes will be stored in the DB.
-
getAlternativeRelationshipsInNamespaces
public Map<String,Pair<org.neo4j.driver.types.Node,org.neo4j.driver.types.Relationship>> getAlternativeRelationshipsInNamespaces(Object node)
Provides a map of relationships that alternative namespaces used in the given node. If the system doesn't consider namespaces, or no alternative namespaces exist yet NULL is returned- Parameters:
node- for which relationships should be retrieved- Returns:
- Map with all alternative relationships or null (The pair contains
<TARGETNODE, RELATIONSHIP>) Please note that the return map can also contain maps!Warning: this is READ ONLY. No changes will be stored in the DB.
-
getClazz
public Class getClazz()
-
getName
public String getName()
-
getLabels
public String getLabels()
-
getId
public FieldInformation getId()
-
getFields
public Map<String,FieldInformation> getFields()
-
getRelationships
public Map<String,RelationshipInformation> getRelationships()
-
getType
public ClassInformation.Neo4JType getType()
-
getNamespace
public String getNamespace()
-
getNsName
public String getNsName()
-
getNsLabels
public String getNsLabels()
-
isNamespaceaware
public boolean isNamespaceaware()
gets value of fieldnamespaceaware- Returns:
- value of field namespaceaware
- See Also:
namespaceaware
-
castToClass
public static <T> T castToClass(Object o, Class<T> c)
Casts a Neo4J database object to the required class- Type Parameters:
T- Type = class given as c- Parameters:
o- object to be castc- class to cast to- Returns:
- object now of class c
-
getExtensions
public Map<String,Object> getExtensions(Object node)
Returns all extensions provided in the object- Parameters:
node- object where extensions should be accessed- Returns:
- all extensions (map can be modified!)
-
getExtension
public Object getExtension(Object node, String name)
Returns the extension of name or null if it doesnt exist- Parameters:
node- object that the extension should be loaded out ofname- of extension that should be returned- Returns:
- extension or null (object CAN NOT be modified)
-
setExtension
public void setExtension(Object node, String name, Object extension)
Adds the extension of name to the object o. Warning: If the extension already exists it will be overwritten!- Parameters:
node- object that the extension should be added toname- name of extension to be setextension- to be added (can only be primitive!)
-
setExtensionSafe
public boolean setExtensionSafe(Object node, String name, Object extension)
Adds the extension of name to the object o. Will only write extension if it does NOT exist- Parameters:
node- object that the extension should be added toname- name of extension to be setextension- to be added (can only be primitive!)- Returns:
- true if write was successful, false if the extension already existed
-
-