Package io.permazen.schema
Class ReferenceSchemaField
java.lang.Object
io.permazen.util.AbstractXMLStreaming
io.permazen.schema.SchemaItem
io.permazen.schema.SchemaField
io.permazen.schema.SimpleSchemaField
io.permazen.schema.ReferenceSchemaField
- All Implemented Interfaces:
DiffGenerating<SimpleSchemaField>,Cloneable
A reference field in a
SchemaObjectType.-
Field Summary
FieldsFields inherited from class io.permazen.schema.SchemaItem
NAME_PATTERNFields inherited from class io.permazen.util.AbstractXMLStreaming
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()Deep-clone this instance.differencesFrom(SimpleSchemaField other) Detect the differences of this instance when compared to the given instance.booleanGet the desired behavior when an object referred to by this field is deleted.final ItemTypeGet theItemTypecorresponding to this instance.Get theSchemaObjectTypeof which this field is a member.Get the object types this field is allowed to reference, if so restricted.final SchemaIdGenerate a uniqueSchemaIdcorresponding to the type and encoding structure of this schema item.booleanDetermine if this field has a fixed encoding.inthashCode()booleanDetermine whether this field accepts references to deleted objects in normal (non-detached) transactions.booleanDetermine if this field is always indexed.booleanDetermine whether the referred-to object should be deleted when an object containing this field is deleted.final booleanisLockedDown(boolean includingStorageIds) Determine whether this instance is locked down.voidsetAllowDeleted(boolean allowDeleted) Set the whether this field may reference non-existent objects in normal (non-detached) transactions.voidsetForwardDelete(boolean forwardDelete) Set the whether to forward cascade delete operations.voidsetInverseDelete(DeleteAction inverseDelete) Set the desired behavior when an object referred to by this field is deleted.final voidsetObjectType(SchemaObjectType objectType) Set theSchemaObjectTypeof which this field is a member.voidsetObjectTypes(NavigableSet<String> objectTypes) Set the object types this field is allowed to reference.<R> Rvisit(SchemaFieldSwitch<R> target) Apply visitor pattern.final <T extends SchemaItem>
voidvisitSchemaItems(Class<T> nodeType, Consumer<? super T> visitor) Visit this schema item and all of its descendents matching the given type with the given visitor.voidvisitSchemaItems(Consumer<? super SchemaItem> visitor) Visit allSchemaItemdescendents of this instance with the given visitor.Methods inherited from class io.permazen.schema.SimpleSchemaField
getEncodingId, getFullName, getParent, isIndexed, setEncodingId, setIndexed, setParent, toStringMethods inherited from class io.permazen.schema.SchemaItem
differencesFrom, getName, getStorageId, setName, setStorageIdMethods inherited from class io.permazen.util.AbstractXMLStreaming
expect, expectClose, getAttr, getAttr, getBooleanAttr, getBooleanAttr, getIntAttr, getIntAttr, getLongAttr, newInvalidAttributeException, newInvalidInputException, newInvalidInputException, next, skip, writeAttr, writeCData, writeCharacters, writeElement, writeEmptyElement, writeStartElement
-
Field Details
-
ITEM_TYPE
TheItemTypethat this class represents.
-
-
Constructor Details
-
ReferenceSchemaField
public ReferenceSchemaField()
-
-
Method Details
-
getInverseDelete
Get the desired behavior when an object referred to by this field is deleted.- Returns:
- desired behavior when a referenced object is deleted
-
setInverseDelete
Set the desired behavior when an object referred to by this field is deleted.- Parameters:
inverseDelete- action on deletion of target object- Throws:
UnsupportedOperationException- if this instance is locked down
-
isForwardDelete
public boolean isForwardDelete()Determine whether the referred-to object should be deleted when an object containing this field is deleted.- Returns:
- whether deletion should cascade to the referred-to object
-
setForwardDelete
public void setForwardDelete(boolean forwardDelete) Set the whether to forward cascade delete operations.- Parameters:
forwardDelete- true to forward cascade delete operations, false to do nothing- Throws:
UnsupportedOperationException- if this instance is locked down
-
isAllowDeleted
public boolean isAllowDeleted()Determine whether this field accepts references to deleted objects in normal (non-detached) transactions.- Returns:
- whether deleted objects are allowed in normal transactions
-
setAllowDeleted
public void setAllowDeleted(boolean allowDeleted) Set the whether this field may reference non-existent objects in normal (non-detached) transactions.- Parameters:
allowDeleted- true to allow dangling references, otherwise false- Throws:
UnsupportedOperationException- if this instance is locked down
-
getObjectTypes
Get the object types this field is allowed to reference, if so restricted.If not null, the returned set will be unmodifiable if this instance is locked down.
- Returns:
- names allowed object types, or null if there is no restriction
-
hasFixedEncoding
public boolean hasFixedEncoding()Description copied from class:SimpleSchemaFieldDetermine if this field has a fixed encoding.- Overrides:
hasFixedEncodingin classSimpleSchemaField- Returns:
- true if this is a
ReferenceSchemaFieldorAbstractEnumSchemaField, otherwise false
-
isAlwaysIndexed
public boolean isAlwaysIndexed()Description copied from class:SimpleSchemaFieldDetermine if this field is always indexed.- Overrides:
isAlwaysIndexedin classSimpleSchemaField- Returns:
- true if this is a
ReferenceSchemaField, otherwise false
-
visit
Description copied from class:SchemaFieldApply visitor pattern.- Overrides:
visitin classSimpleSchemaField- Type Parameters:
R- visitor return type- Parameters:
target- target to invoke- Returns:
- value from the method of
targetcorresponding to this instance's type
-
getItemType
Get theItemTypecorresponding to this instance.- Overrides:
getItemTypein classSimpleSchemaField- Returns:
- schema item type
-
differencesFrom
Description copied from interface:DiffGeneratingDetect the differences of this instance when compared to the given instance.- Specified by:
differencesFromin interfaceDiffGenerating<SimpleSchemaField>- Overrides:
differencesFromin classSimpleSchemaField- Parameters:
other- other instance- Returns:
- differences; will be empty if there are none detected
-
equals
- Overrides:
equalsin classSimpleSchemaField
-
hashCode
public int hashCode()- Overrides:
hashCodein classSimpleSchemaField
-
clone
Deep-clone this instance.The returned instance will not be locked down even if this one is.
- Overrides:
clonein classSimpleSchemaField
-
getObjectType
Get theSchemaObjectTypeof which this field is a member.- Returns:
- containing object type
-
setObjectType
Set theSchemaObjectTypeof which this field is a member.Note: this field is considered derived information, and will be set automatically when a referrring
SchemaObjectTypeis locked down.- Parameters:
objectType- containing object type- Throws:
UnsupportedOperationException- if this instance is locked down
-
visitSchemaItems
Visit allSchemaItemdescendents of this instance with the given visitor.If this instance is also a
SchemaItem, then also visit this instance.The traversal is depth first, pre-order.
- Parameters:
visitor- visitor for schema items- Throws:
IllegalArgumentException- ifvisitoris null
-
visitSchemaItems
public final <T extends SchemaItem> void visitSchemaItems(Class<T> nodeType, Consumer<? super T> visitor) Visit this schema item and all of its descendents matching the given type with the given visitor.The traversal is depth first, post-order.
- Parameters:
nodeType- node type to includevisitor- visitor for schema items- Throws:
IllegalArgumentException- if either parameter is null
-
isLockedDown
public final boolean isLockedDown(boolean includingStorageIds) Determine whether this instance is locked down.- Parameters:
includingStorageIds- false to test all but storage ID's, true to require storage ID's to be locked down as well- Returns:
- true if instance is locked down, otherwise false
-
getSchemaId
Generate a uniqueSchemaIdcorresponding to the type and encoding structure of this schema item.The
SchemaIddoes not depend on the storage ID.This instance must be locked down except for storage ID's. Repeated invocations of this method will be very fast, just returning the cached previous result.
- Returns:
- schema ID
- Throws:
IllegalStateException- if this instance is not locked down- See Also:
-