Class ObjRelationship
java.lang.Object
org.apache.cayenne.map.Relationship<ObjEntity, ObjAttribute, ObjRelationship>
org.apache.cayenne.map.ObjRelationship
- All Implemented Interfaces:
ProjectNode, XMLSerializable
public class ObjRelationship
extends Relationship<ObjEntity, ObjAttribute, ObjRelationship>
implements ProjectNode
Describes an association between two Java classes mapped as source and target
ObjEntity. Maps to a path of DbRelationships.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringStores the type of collection mapped by a to-many relationship.protected List<DbRelationship> static final StringDenotes a default type of to-many relationship collection which is a Java List.protected DeleteRuleprotected StringStores a property name of a target entity used to create a relationship map.protected booleanFields inherited from class Relationship
name, runtime, sourceEntity, targetEntityName, toMany -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TacceptVisitor(ProjectNodeVisitor<T> visitor) voidaddDbRelationship(DbRelationship dbRel) Appends a DbRelationship to the existing list of DbRelationships.voidvoidencodeAsXML(XMLEncoder encoder, ProjectNodeVisitor<?> delegate) Prints itself as XML to the provided XMLEncoder.Returns the interface of collection mapped by a to-many relationship.Returns a dot-separated path over mapped DbRelationships.Returns an immutable list of underlying DbRelationships.Returns the deleteRule.Returns a property name of a target entity used to create a relationship map.Returns a reversed dbRelationship path.Returns a "complementary" ObjRelationship going in the opposite direction.getReverseRelationship(ObjEntity entity) Returns a relationship of the given entity that is complementary to this one, or null if it's not found.Returns the name of a complementary relationship going in the opposite direction or null if it doesn't exist.Returns relationship source entity.Returns a target ObjEntity of this relationship.booleanReturns true if the relationship is a "flattened" relationship.booleanisFromFK()Returns true if this relationship's source owns the foreign key side of the relationship.booleanisToMany()Returns a boolean value that determines relationship multiplicity.booleanReturns whether this attribute should be used for locking.voidRecalculates whether a relationship is toMany or toOne, based on the underlying db relationships.voidRemoves the relationshipdbRelfrom the list of relationships.voidsetCollectionType(String collectionType) voidsetDbRelationshipPath(String relationshipPath) Sets mapped DbRelationships as a dot-separated path.voidsetDbRelationshipPath(CayennePath relationshipPath) Sets mapped DbRelationships as a dot-separated path.voidsetDeferredDbRelationshipPath(String relationshipPath) Sets relationship path, but does not trigger its conversion toList<DbRelationship>.voidsetDeleteRule(DeleteRule deleteRule) Sets the delete rule of the relationship.voidvoidsetUsedForLocking(boolean usedForLocking) Sets whether this attribute should be used for locking.toString()Overrides Object.toString() to return informative description.Methods inherited from class Relationship
getName, getTargetEntityName, isRuntime, setName, setRuntime, setSourceEntity, setTargetEntityName, setTargetEntityName
-
Field Details
-
DEFAULT_COLLECTION_TYPE
Denotes a default type of to-many relationship collection which is a Java List.- Since:
- 3.0
- See Also:
-
deleteRule
-
usedForLocking
protected boolean usedForLocking -
dbRelationships
-
collectionType
Stores the type of collection mapped by a to-many relationship. Null for to-one relationships.- Since:
- 3.0
-
mapKey
Stores a property name of a target entity used to create a relationship map. Only has effect if collectionType property is set to "java.util.Map".- Since:
- 3.0
-
-
Constructor Details
-
ObjRelationship
public ObjRelationship() -
ObjRelationship
-
-
Method Details
-
getSourceEntity
Description copied from class:RelationshipReturns relationship source entity.- Overrides:
getSourceEntityin classRelationship<ObjEntity, ObjAttribute, ObjRelationship>
-
acceptVisitor
- Specified by:
acceptVisitorin interfaceProjectNode- Since:
- 3.1
-
encodeAsXML
Prints itself as XML to the provided XMLEncoder.- Specified by:
encodeAsXMLin interfaceXMLSerializable- Since:
- 1.1
-
getTargetEntity
Returns a target ObjEntity of this relationship. Entity is looked up in the parent DataMap using "targetEntityName".- Specified by:
getTargetEntityin classRelationship<ObjEntity, ObjAttribute, ObjRelationship>
-
getReverseRelationshipName
Returns the name of a complementary relationship going in the opposite direction or null if it doesn't exist.- Since:
- 1.2
-
getReverseRelationship
Returns a "complementary" ObjRelationship going in the opposite direction. Returns null if no such relationship is found.- Specified by:
getReverseRelationshipin classRelationship<ObjEntity, ObjAttribute, ObjRelationship>
-
getReverseRelationship
Returns a relationship of the given entity that is complementary to this one, or null if it's not found.- Since:
- 5.0
- See Also:
-
getDbRelationships
Returns an immutable list of underlying DbRelationships. -
addDbRelationship
Appends a DbRelationship to the existing list of DbRelationships. -
removeDbRelationship
Removes the relationshipdbRelfrom the list of relationships. -
clearDbRelationships
public void clearDbRelationships() -
isFromFK
public boolean isFromFK()Returns true if this relationship's source owns the foreign key side of the relationship.- Since:
- 5.0
-
isFlattened
public boolean isFlattened()Returns true if the relationship is a "flattened" relationship. A relationship is considered "flattened" if it maps to more than one DbRelationship. Such chain of DbRelationships is also called "relationship path".- Returns:
- flag indicating if the relationship is flattened or not.
-
isToMany
public boolean isToMany()Description copied from class:RelationshipReturns a boolean value that determines relationship multiplicity. This defines semantics of the connection between two nodes described by the source and target entities. E.g. to-many relationship between two Persistent object classes means that a source object would have a collection of target objects. This is a read-only property.- Overrides:
isToManyin classRelationship<ObjEntity, ObjAttribute, ObjRelationship>
-
getDeleteRule
Returns the deleteRule. The delete rule is a constant from the DeleteRule class, and specifies what should happen to the destination object when the source object is deleted.- See Also:
-
setDeleteRule
Sets the delete rule of the relationship. A null rule means that no action is taken on the target objects. -
isUsedForLocking
public boolean isUsedForLocking()Returns whether this attribute should be used for locking.- Since:
- 1.1
-
setUsedForLocking
public void setUsedForLocking(boolean usedForLocking) Sets whether this attribute should be used for locking.- Since:
- 1.1
-
getDbRelationshipPath
Returns a dot-separated path over mapped DbRelationships.- Returns:
- path or
nullif no db relationships set - Since:
- 1.1, 5.0 returns
CayennePathinstead of a plainString
-
getReverseDbRelationshipPath
Returns a reversed dbRelationship path.- Throws:
ExpressionException- Since:
- 1.2, 5.0 returns
CayennePathinstead of a plainString
-
setDbRelationshipPath
Sets mapped DbRelationships as a dot-separated path. -
setDbRelationshipPath
Sets mapped DbRelationships as a dot-separated path.- Since:
- 5.0
-
setDeferredDbRelationshipPath
Sets relationship path, but does not trigger its conversion toList<DbRelationship>.
NOTE: this method is intended for internal usage, primarily datamap loading.- Since:
- 4.1 this method is public as it is used by new XML loaders
-
recalculateToManyValue
public void recalculateToManyValue()Recalculates whether a relationship is toMany or toOne, based on the underlying db relationships. -
toString
Description copied from class:RelationshipOverrides Object.toString() to return informative description.- Overrides:
toStringin classRelationship<ObjEntity, ObjAttribute, ObjRelationship>
-
getCollectionType
Returns the interface of collection mapped by a to-many relationship. Returns null for to-one relationships. Default for to-many is "java.util.List". Other possible values are "java.util.Set", "java.util.Collection", "java.util.Map".- Since:
- 3.0
-
setCollectionType
- Since:
- 3.0
-
getMapKey
Returns a property name of a target entity used to create a relationship map. Only has effect if collectionType property is set to "java.util.Map".- Returns:
- The attribute name used for the map key or
nullif the default (PK) is used as the map key. - Since:
- 3.0
-
setMapKey
- Since:
- 3.0
-