Class Property

java.lang.Object
io.higson.runtime.model.value.Property
All Implemented Interfaces:
Handle, Iterable<Property>
Direct Known Subclasses:
CollectionProperty, EntityProperty, RefProperty, ValueProperty

public abstract class Property extends Object implements Handle
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.

Allowed subclasses are:
  • ValueProperty - represents property for simple(Java) types, like String, int, etc.
  • EntityProperty - represents complex property with fields
  • CollectionProperty - represents collection property, that can store many properties as a container
  • RefProperty - 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 Details

    • getName

      public String getName()
      Gets name or parent name, if name is not setup.
      Returns:
      null if name or parent name is not setup
      See Also:
    • getParentName

      public String getParentName()
      Gets parent name or null if not setup.
      Returns:
      null if parent name is not setup
    • getOwnerPropertyName

      public String getOwnerPropertyName()
      Gets name or parent name, if name is not setup.
      Returns:
      null if name or parent name is not setup
      See Also:
    • setName

      public void setName(String name)
      Sets property name.
      Parameters:
      name - of property
    • getParent

      public EntityProperty getParent()
      Gets owning(parent) entity.
      Returns:
      parent (might be null)
    • setParent

      public void setParent(EntityProperty parent)
      Sets parent(owner).
      Parameters:
      parent - of property
    • getPath

      public String getPath()
      Returns full path to this property with . 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

      public String 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

      public Property getContainer()
      Returns:
      container for property
    • setContainer

      public void setContainer(Property container)
      Sets container for property.
      Parameters:
      container - for property
    • setupOwnerId

      public void setupOwnerId()
      This method is similar to setOwnerId(long), but id is fetched from parent. If parent is not setup, then ownerId will not be changed.
    • getType

      public TypeDef getType()
      Gets type of this bundle property/element.
      Returns:
      type associated to this property. Can't be null
    • getTypeCode

      public String getTypeCode()
      Gets type's code from associated definition.
      Returns:
      type code, shouldn't be null
    • getBundle

      public Bundle getBundle()
      Gets bundle root.
      Returns:
      bundle root, shouldn't be null
      See Also:
    • bundle

      public Bundle bundle()
      Same as getBundle()
      Returns:
      bundle root, shouldn't be null
      See Also:
    • deepcopy

      public Property 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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getId

      public abstract long getId()
      Returns:
      id of property
    • deepcopy

      public abstract Property deepcopy(boolean resetIds)
      Returns deep copy of this property's subtree.
      Parameters:
      resetIds - whether to reset ids on copy
      Returns:
      property created from deepcopy
      See Also:
    • print

      public abstract void print(StringBuilder sb, int level, String prefix, String suffix)
      Prints subtree to string builder.
      Parameters:
      sb - StringBuilder containing data to print
      level - level used to indentation
      prefix - value to used as prefix
      suffix - value to used as suffix
    • get

      public Property get(String path)
      Gets property under given path. There are few path resolving possibilities:
      
      	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")
       
      If path is empty or null, property should return itself.
      Specified by:
      get in interface Handle
      Parameters:
      path - should exists within this property
      Returns:
      property if path was properly resolved and property exists, null otherwise
      See Also:
    • getHolder

      public ValueHolder getHolder(String path)
      Gets value of property wrapped into ValueHolder from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getHolder in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property wrapped into ValueHolder
      See Also:
    • getString

      public String getString(String path)
      Gets value as String from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getString in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as String
      See Also:
    • getInteger

      public Integer getInteger(String path)
      Gets value as Integer from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getInteger in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as Integer
      See Also:
    • getDecimal

      public BigDecimal getDecimal(String path)
      Gets value as BigDecimal from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getDecimal in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as BigDecimal
      See Also:
    • getLong

      public Long getLong(String path)
      Gets value as Long from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getLong in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as Long
      See Also:
    • getBoolean

      public Boolean getBoolean(String path)
      Gets value as Boolean from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getBoolean in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as Boolean
      See Also:
    • getDate

      public Date getDate(String path)
      Gets value as Date from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getDate in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as Date
      See Also:
    • getDatetime

      public Date getDatetime(String path)
      Gets value as Date with time from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getDatetime in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as Date
      See Also:
    • getNumber

      public double getNumber(String path)
      Gets value as double from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getNumber in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as double
      See Also:
    • intValue

      public int intValue(String path)
      Gets value as int from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      intValue in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as int
      See Also:
    • booleanValue

      public boolean booleanValue(String path)
      Gets value as boolean from given path. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      booleanValue in interface Handle
      Parameters:
      path - to value
      Returns:
      value of property as boolean
      See Also:
    • set

      public Property set(String path, Object value)
      Sets new value under given path, which must exists. All rules of path design, are the same as described in Handle.get(String).
      Example:
      
        Property agent = property.get("agent").set("age", 31).set("name", "steph");
       
      This method is useful for setting up multiple properties of one parent property, in the sense of Builder Pattern.
      Specified by:
      set in interface Handle
      Parameters:
      path - should exists within this property
      value - new value for path.
      Returns:
      same property instance.
      See Also:
    • add

      public Property add(String path, Property... properties)
      Adds one or multiple properties to collection property, that exists under given path. 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 in Handle.get(String).
      Specified by:
      add in interface Handle
      Parameters:
      path - to collection property
      properties - one or multiple properties that will be added
      Returns:
      property under path
      See Also:
    • remove

      public Property remove(String path)
      Removes property from given path. 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 in Handle.get(String).
      Specified by:
      remove in interface Handle
      Parameters:
      path - points to property, that will be removed
      Returns:
      removed property
      See Also:
    • print

      public String print()
      Creates whole sub tree of this property as formatted String.
      Specified by:
      print in interface Handle
      Returns:
      formatted String of subtree
    • getRefCount

      public int getRefCount()
      Number of nodes referencing target's property.
      Specified by:
      getRefCount in interface Handle
      Returns:
      number of references
    • isValue

      public boolean isValue()
      Is property a value type.
      Specified by:
      isValue in interface Handle
      Returns:
      true if property is value type, false otherwise
      See Also:
    • isEntity

      public boolean isEntity()
      Is property an entity.
      Specified by:
      isEntity in interface Handle
      Returns:
      true if property is entity type, false otherwise
      See Also:
    • isCollection

      public boolean isCollection()
      Is property a collection type.
      Specified by:
      isCollection in interface Handle
      Returns:
      true if property is collection type, false otherwise
      See Also:
    • isRoot

      public boolean isRoot()
      Is property a root element.
      Specified by:
      isRoot in interface Handle
      Returns:
      true if property is root element, false otherwise
      See Also:
    • asCollection

      public CollectionProperty asCollection()
      Specified by:
      asCollection in interface Handle
      Returns:
      property as CollectionProperty
    • asRef

      public RefProperty asRef()
      Specified by:
      asRef in interface Handle
      Returns:
      property as RefProperty
    • asEntity

      public EntityProperty asEntity()
      Specified by:
      asEntity in interface Handle
      Returns:
      property as EntityProperty
    • asValue

      public ValueProperty asValue()
      Specified by:
      asValue in interface Handle
      Returns:
      property as ValueProperty
    • create

      public Property create()
      Specified by:
      create in interface Handle
      Implementation Requirements:
      by default it will throw HigsonBundleUsageException. Subclasses might provide different behaviour.
      Returns:
      new property
    • remove

      public 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.
      Specified by:
      remove in interface Handle
      Returns:
      removed property
    • traverse

      public void traverse(PropertyVisitor visitor)
      This method walks on property subtree and invoke some action with PropertyVisitor. Think of it as Visitor Pattern.
      Specified by:
      traverse in interface Handle
      Parameters:
      visitor - property
      See Also:
    • getString

      public String getString()
      Specified by:
      getString in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as String
    • getInteger

      public Integer getInteger()
      Specified by:
      getInteger in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as Integer
    • getDecimal

      public BigDecimal getDecimal()
      Specified by:
      getDecimal in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as BigDecimal
    • booleanValue

      public boolean booleanValue()
      Specified by:
      booleanValue in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as boolean
    • getBoolean

      public Boolean getBoolean()
      Specified by:
      getBoolean in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as Boolean
    • getDate

      public Date getDate()
      Specified by:
      getDate in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as Date
    • getDatetime

      public Date getDatetime()
      Specified by:
      getDatetime in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as Date with time
    • getHolder

      public ValueHolder getHolder()
      Specified by:
      getHolder in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property wrapped into ValueHolder
    • getLong

      public Long getLong()
      Specified by:
      getLong in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as Long
    • getNumber

      public double getNumber()
      Specified by:
      getNumber in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as double
    • intValue

      public int intValue()
      Specified by:
      intValue in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Returns:
      value of property as int
    • set

      public void set(Object value)
      Sets new value of this property.
      Specified by:
      set in interface Handle
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException.
      Parameters:
      value - new value
    • iterator

      public Iterator<Property> iterator()
      .
      Specified by:
      iterator in interface Iterable<Property>
      Implementation Requirements:
      The default implementation will throw HigsonBundleUsageException. This is only supported by collection property type.
    • add

      public Property add(Property... properties)
      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.
      Specified by:
      add in interface Handle
      Implementation Requirements:
      By default, this method will throw exception. Subclass should implement proper behaviour.
      Parameters:
      properties - one or multiple properties that will be added
      Returns:
      this property
    • size

      public int size()
      Specified by:
      size in interface Handle
      Returns:
      number of properties
    • at

      public Property at(int index)
      Description copied from interface: Handle
      Gets property at given index withing this property. Index starts with 0.
      Specified by:
      at in interface Handle
      Parameters:
      index - of element within property
      Returns:
      found property of index
    • clear

      public Property clear()
      Description copied from interface: Handle
      Clear all children of this property.
      Specified by:
      clear in interface Handle
      Returns:
      itself
    • getEntity

      public EntityProperty getEntity(String path)
      Find entity property based on given path within this property subtree. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getEntity in interface Handle
      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 of EntityProperty
      See Also:
    • getCollection

      public CollectionProperty getCollection(String path)
      Find collection property based on given path within this property subtree. All rules of path design, are the same as described in Handle.get(String).
      Specified by:
      getCollection in interface Handle
      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 of CollectionProperty
      See Also:
    • getRefTarget

      public Property getRefTarget()
      Gets property of reference's target.
      Specified by:
      getRefTarget in interface Handle
      Returns:
      reference's target. If property is reference type, it shouldn't return null
    • getState

      public EntityState getState()
      Gets state of property. There are two possible states of entity:
      Specified by:
      getState in interface Handle
      Returns:
      state of property
    • isPersistent

      public boolean isPersistent()
      Is property in persistent state.
      Specified by:
      isPersistent in interface Handle
      Returns:
      true if property is in persistent state, false otherwise
      See Also:
    • isTransient

      public boolean isTransient()
      Is property in transient state.
      Specified by:
      isTransient in interface Handle
      Returns:
      true if property is in transient state, false otherwise
      See Also: