Package io.higson.runtime.model.value
Class Property
java.lang.Object
io.higson.runtime.model.value.Property
- Direct Known Subclasses:
CollectionProperty,EntityProperty,RefProperty,ValueProperty
This is main class representing property managed by Higson Persistence Engine. It exposes all necessary API for interaction.
Most basic interactions are setting property - set(String, Object) and retrieving - get(String) it based on certain path.
For more, examine API here and all subclasses.
ValueProperty- represents property for simple(Java) types, like String, int, etc.EntityProperty- represents complex property with fieldsCollectionProperty- represents collection property, that can store many properties as a containerRefProperty- represents reference property, that points to other property
Some methods are only available for certain property types. For example, it is not possible to call at(int) on RefProperty,
but only on CollectionProperty.
So be aware of property type and it's supported functionality.
- Author:
- przemek hertel
- Implementation Requirements:
- Some methods define default behaviour with either default values or throw exception. Make sure to provide proper implementation for each subclass.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAdds one or multiple properties to collection property.Adds one or multiple properties to collection property, that exists under givenpath.asEntity()asRef()asValue()at(int index) Gets property at givenindexwithingthisproperty.booleanbooleanbooleanValue(String path) Gets value as boolean from givenpath.bundle()Same asgetBundle()clear()Clear all children ofthisproperty.create()deepcopy()- creates deepcopy of this property - resets all IDs and ownerIDsabstract Propertydeepcopy(boolean resetIds) Returns deep copy of this property's subtree.booleanGets property under givenpath.getBoolean(String path) Gets value as Boolean from givenpath.Gets bundle root.Returns canonical path for this element.getCollection(String path) Find collection property based on givenpathwithin this property subtree.getDate()Gets value as Date from givenpath.getDatetime(String path) Gets value as Date with time from givenpath.getDecimal(String path) Gets value as BigDecimal from givenpath.Find entity property based on givenpathwithin this property subtree.Gets value of property wrapped intoValueHolderfrom givenpath.abstract longgetId()getInteger(String path) Gets value as Integer from givenpath.getLong()Gets value as Long from givenpath.getName()Gets name or parent name, if name is not setup.doubledoubleGets value as double from givenpath.longGets owner (parent) id.Gets name or parent name, if name is not setup.Gets owning(parent) entity.Gets parent name or null if not setup.getPath()Returns full path to thispropertywith . separator between elements names.
Example:intNumber of nodes referencing target's property.Gets property of reference's target.getState()Gets state of property.Gets value as String from givenpath.getType()Gets type of this bundle property/element.Gets type's code from associated definition.inthashCode()intintValue()intGets value as int from givenpath.booleanIs property a collection type.booleanisEntity()Is property an entity.booleanIs property in persistent state.booleanisRoot()Is property a root element.booleanIs property in transient state.booleanisValue()Is property a value type.iterator().print()Creates whole sub tree of this property as formatted String.abstract voidprint(StringBuilder sb, int level, String prefix, String suffix) Prints subtree to string builder.remove()Removes itself.Removes property from givenpath.voidresetIds()Reset ids.voidSets newvalueof this property.Sets newvalueunder givenpath, which must exists.voidsetContainer(Property container) Sets container for property.voidSets property name.voidsetOwnerId(long ownerId) Sets owner (parent) id.voidsetParent(EntityProperty parent) Sets parent(owner).voidThis method is similar tosetOwnerId(long), but id is fetched from parent.intsize()voidtraverse(PropertyVisitor visitor) This method walks on property subtree and invoke some action withPropertyVisitor.Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.higson.runtime.model.value.Handle
find, getElementType, has, isRefMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
getName
Gets name or parent name, if name is not setup.- Returns:
- null if name or parent name is not setup
- See Also:
-
getParentName
Gets parent name or null if not setup.- Returns:
- null if parent name is not setup
-
getOwnerPropertyName
Gets name or parent name, if name is not setup.- Returns:
- null if name or parent name is not setup
- See Also:
-
setName
Sets property name.- Parameters:
name- of property
-
getParent
Gets owning(parent) entity.- Returns:
- parent (might be null)
-
setParent
Sets parent(owner).- Parameters:
parent- of property
-
getPath
Returns full path to thispropertywith . separator between elements names.
Example:- cart.policies - cart.policies.variants.covers.premium- Returns:
- path or empty string "" if path does not exist
- See Also:
-
getCanonicalPath
Returns canonical path for this element. It will return exact position of this property within parent-child relation. For collections properties, name of property is also constructed with "array[index] like notation" - [0], [1], etc.
Examples:- cart.policies[1] - cart.policies[0].variants[2].covers[3].premium- Returns:
- canonical path or null, if path is empty
- See Also:
-
getOwnerId
public long getOwnerId()Gets owner (parent) id.- Returns:
- owner's id or 0 if there is no owner
-
setOwnerId
public void setOwnerId(long ownerId) Sets owner (parent) id.- Parameters:
ownerId- owner id
-
getContainer
- Returns:
- container for property
-
setContainer
Sets container for property.- Parameters:
container- for property
-
setupOwnerId
public void setupOwnerId()This method is similar tosetOwnerId(long), but id is fetched from parent. If parent is not setup, thenownerIdwill not be changed. -
getType
Gets type of this bundle property/element.- Returns:
- type associated to this property. Can't be null
-
getTypeCode
Gets type's code from associated definition.- Returns:
- type code, shouldn't be null
-
getBundle
Gets bundle root.- Returns:
- bundle root, shouldn't be null
- See Also:
-
bundle
Same asgetBundle()- Returns:
- bundle root, shouldn't be null
- See Also:
-
deepcopy
- creates deepcopy of this property - resets all IDs and ownerIDs- Returns:
- property created from deepcopy
-
resetIds
public void resetIds()Reset ids.- Implementation Requirements:
- Each subclass should define, what should be reseted
-
equals
-
hashCode
public int hashCode() -
getId
public abstract long getId()- Returns:
- id of property
-
deepcopy
Returns deep copy of this property's subtree.- Parameters:
resetIds- whether to reset ids on copy- Returns:
- property created from
deepcopy - See Also:
-
print
Prints subtree to string builder.- Parameters:
sb- StringBuilder containing data to printlevel- level used to indentationprefix- value to used as prefixsuffix- value to used as suffix
-
get
Gets property under givenpath. There are few path resolving possibilities:
If path is empty or null, property should return itself.1. Direct access to child property (element, reference, value or collection) property.get("child") - direct child property property.get("children") - direct children collection property property.get("child.name") - indirect child's name property as value 2. Access to collection element at available index property.get("children.id") - is not possible, if "children" is collection property property.get("children[0].id") - proper access to child, that exists within children collection 3. Chain of properties property.get("supplier.car.model.productionYear") -
getHolder
Gets value of property wrapped intoValueHolderfrom givenpath. All rules of path design, are the same as described inHandle.get(String).- Specified by:
getHolderin interfaceHandle- Parameters:
path- to value- Returns:
- value of property wrapped into
ValueHolder - See Also:
-
getString
Gets value as String from givenpath. All rules of path design, are the same as described inHandle.get(String). -
getInteger
Gets value as Integer from givenpath. All rules of path design, are the same as described inHandle.get(String).- Specified by:
getIntegerin interfaceHandle- Parameters:
path- to value- Returns:
- value of property as Integer
- See Also:
-
getDecimal
Gets value as BigDecimal from givenpath. All rules of path design, are the same as described inHandle.get(String).- Specified by:
getDecimalin interfaceHandle- Parameters:
path- to value- Returns:
- value of property as BigDecimal
- See Also:
-
getLong
Gets value as Long from givenpath. All rules of path design, are the same as described inHandle.get(String). -
getBoolean
Gets value as Boolean from givenpath. All rules of path design, are the same as described inHandle.get(String).- Specified by:
getBooleanin interfaceHandle- Parameters:
path- to value- Returns:
- value of property as Boolean
- See Also:
-
getDate
Gets value as Date from givenpath. All rules of path design, are the same as described inHandle.get(String). -
getDatetime
Gets value as Date with time from givenpath. All rules of path design, are the same as described inHandle.get(String).- Specified by:
getDatetimein interfaceHandle- Parameters:
path- to value- Returns:
- value of property as Date
- See Also:
-
getNumber
Gets value as double from givenpath. All rules of path design, are the same as described inHandle.get(String). -
intValue
Gets value as int from givenpath. All rules of path design, are the same as described inHandle.get(String). -
booleanValue
Gets value as boolean from givenpath. All rules of path design, are the same as described inHandle.get(String).- Specified by:
booleanValuein interfaceHandle- Parameters:
path- to value- Returns:
- value of property as boolean
- See Also:
-
set
Sets newvalueunder givenpath, which must exists. All rules of path design, are the same as described inHandle.get(String).
Example:
This method is useful for setting up multiple properties of one parent property, in the sense of Builder Pattern.Property agent = property.get("agent").set("age", 31).set("name", "steph"); -
add
Adds one or multiple properties to collection property, that exists under givenpath. The order of properties should be kept as they are provided. If there are properties added to collection property, which resides under this path, they should be added at the end. All rules of path design, are the same as described inHandle.get(String). -
remove
Removes property from givenpath. Property will first be detached from whole subtree, like collections and references. If that is possible, then property will be removed. All rules of path design, are the same as described inHandle.get(String). -
print
Creates whole sub tree of this property as formatted String. -
getRefCount
public int getRefCount()Number of nodes referencing target's property.- Specified by:
getRefCountin interfaceHandle- Returns:
- number of references
-
isValue
public boolean isValue()Is property a value type. -
isEntity
public boolean isEntity()Is property an entity. -
isCollection
public boolean isCollection()Is property a collection type.- Specified by:
isCollectionin interfaceHandle- Returns:
- true if property is collection type, false otherwise
- See Also:
-
isRoot
public boolean isRoot()Is property a root element. -
asCollection
- Specified by:
asCollectionin interfaceHandle- Returns:
- property as
CollectionProperty
-
asRef
- Specified by:
asRefin interfaceHandle- Returns:
- property as
RefProperty
-
asEntity
- Specified by:
asEntityin interfaceHandle- Returns:
- property as
EntityProperty
-
asValue
- Specified by:
asValuein interfaceHandle- Returns:
- property as
ValueProperty
-
create
- Specified by:
createin interfaceHandle- Implementation Requirements:
- by default it will throw
HigsonBundleUsageException. Subclasses might provide different behaviour. - Returns:
- new property
-
remove
Removes itself. Property will first be detached from whole subtree, like collections and references. If that is possible, then property will be removed. -
traverse
This method walks on property subtree and invoke some action withPropertyVisitor. Think of it as Visitor Pattern. -
getString
- Specified by:
getStringin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as String
-
getInteger
- Specified by:
getIntegerin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as Integer
-
getDecimal
- Specified by:
getDecimalin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as BigDecimal
-
booleanValue
public boolean booleanValue()- Specified by:
booleanValuein interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as boolean
-
getBoolean
- Specified by:
getBooleanin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as Boolean
-
getDate
- Specified by:
getDatein interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as Date
-
getDatetime
- Specified by:
getDatetimein interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as Date with time
-
getHolder
- Specified by:
getHolderin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property wrapped into
ValueHolder
-
getLong
- Specified by:
getLongin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as Long
-
getNumber
public double getNumber()- Specified by:
getNumberin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as double
-
intValue
public int intValue()- Specified by:
intValuein interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Returns:
- value of property as int
-
set
Sets newvalueof this property.- Specified by:
setin interfaceHandle- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. - Parameters:
value- new value
-
iterator
.- Specified by:
iteratorin interfaceIterable<Property>- Implementation Requirements:
- The default implementation will throw
HigsonBundleUsageException. This is only supported by collection property type.
-
add
Adds one or multiple properties to collection property. The order of properties should be kept as they are provided. If there are properties added to collection property, which resides under this path, they should be added at the end. -
size
public int size() -
at
Description copied from interface:HandleGets property at givenindexwithingthisproperty. Index starts with 0. -
clear
Description copied from interface:HandleClear all children ofthisproperty. -
getEntity
Find entity property based on givenpathwithin this property subtree. All rules of path design, are the same as described inHandle.get(String).- Specified by:
getEntityin interfaceHandle- Parameters:
path- of entity property- Returns:
- entity property if found or exception will be thrown
- Throws:
HigsonBundleUsageException- if element is not found or found but it is not instance ofEntityProperty- See Also:
-
getCollection
Find collection property based on givenpathwithin this property subtree. All rules of path design, are the same as described inHandle.get(String).- Specified by:
getCollectionin interfaceHandle- Parameters:
path- of collection property- Returns:
- collection property if found or exception will be thrown
- Throws:
HigsonBundleUsageException- if element is not found or found but it is not instance ofCollectionProperty- See Also:
-
getRefTarget
Gets property of reference's target.- Specified by:
getRefTargetin interfaceHandle- Returns:
- reference's target. If property is reference type, it shouldn't return
null
-
getState
Gets state of property. There are two possible states of entity:EntityState.TRANSIENT- if property was just created and not yet marked for persistenceEntityState.PERSISTENT- if property was marked for persistence
-
isPersistent
public boolean isPersistent()Is property in persistent state.- Specified by:
isPersistentin interfaceHandle- Returns:
- true if property is in persistent state, false otherwise
- See Also:
-
isTransient
public boolean isTransient()Is property in transient state.- Specified by:
isTransientin interfaceHandle- Returns:
- true if property is in transient state, false otherwise
- See Also:
-