Class Bundle

All Implemented Interfaces:
Handle, Iterable<Property>

public class Bundle extends EntityProperty
This is main class, that developer can interact with using higson persistence engine. In general, this class should store all data, that should be managed by persistence engine. Bundle is a root for Higson context. What's really important is that data, should match BundleDef definition. Bundle stores basic information like:
  • def - bundle definition, which holds type structure of created bundle
  • revision - incremental number of updated bundle. By default, it starts with 0 on init, but on first persist it will store 1
  • created - creation time, only setup on first persistence call
  • updated - update time, on first persistence call it is null, but for next revisions this field will be updated
  • lobHash - last hash code of serialized JSON

Example of bundle creation and setup some properties:

 	Bundle bundle = new Bundle(def); // def must match properties that are setup later

 	Property steph = bundle.create("Client").set("age", 31).set("name", "steph");
 	Property dean = bundle.create("Client").set("age", 32).set("name", "dean");
 	Property alex = bundle.create("Client").set("age", 33).set("name", "alex");

 	bundle.get("agent").set(steph);
 	bundle.get("policy.insurer").set(dean);
 	bundle.get("policy.insured").set(alex);
 
Author:
przemek hertel
See Also:
  • Constructor Details

    • Bundle

      public Bundle(BundleDef def)
      Basic constructor to use with definition. Id of created bundle will be 0. This one should be used for bundle creation.
      Parameters:
      def - bundle definition
    • Bundle

      public Bundle(BundleDef def, long id)
      Shouldn't be used outside of Higson persistence engine. Basic constructor with definition and id.
      Parameters:
      def - bundle definition
      id - bundle id
    • Bundle

      public Bundle(BundleDef def, long id, int revision)
      Shouldn't be used outside of Higson persistence engine. Basic constructor with definition, id and revision.
      Parameters:
      def - bundle definition
      id - bundle id
      revision - bundle revision starting number
    • Bundle

      public Bundle(BundleDef def, long id, int revision, int expectedSize)
      Shouldn't be used outside of Higson persistence engine. Advanced constructor with definition, id, revision and expected size of identity set(storage for nested properties).
      Parameters:
      def - bundle definition
      id - bundle id
      revision - bundle revision starting number
      expectedSize - size of created identity set
  • Method Details

    • add

      public Bundle add(String name, Property prop)
      Adds given property under provided name. It is another way of setting properties within bundle.
      Overrides:
      add in class EntityProperty
      Parameters:
      name - unique name
      prop - property to store under name
      Returns:
      same bundle instance
      See Also:
    • isRoot

      public boolean isRoot()
      Since bundle is always a root, it will return true.
      Specified by:
      isRoot in interface Handle
      Overrides:
      isRoot in class Property
      Returns:
      true
      See Also:
    • getRevision

      public int getRevision()
      Get bundle's revision.
      Returns:
      bundle's revision
    • setRevision

      public void setRevision(int revision)
      Shouldn't be used outside of Higson persistence engine.
      Parameters:
      revision - revision number
    • getCreated

      public Date getCreated()
      Get bundle's creation time.
      Returns:
      bundle's creation time
    • setCreated

      public void setCreated(Date created)
      Shouldn't be used outside of Higson persistence engine.
      Parameters:
      created - creation date
    • getUpdated

      public Date getUpdated()
      Get bundle's last update time
      Returns:
      bundle's last update time
    • setUpdated

      public void setUpdated(Date updated)
      Shouldn't be used outside of Higson persistence engine.
      Parameters:
      updated - update date
    • setLobHash

      public void setLobHash(int lobHash)
      Shouldn't be used outside of Higson persistence engine.
      Parameters:
      lobHash - lob hash
    • getLobHash

      public int getLobHash()
      Get last lob hash.
      Returns:
      last lob hash
    • getDef

      public BundleDef getDef()
      Get bundle's definition.
      Returns:
      bundle's definition
    • isNotSaved

      public boolean isNotSaved()
      Checks if bundle was not saved yet.
      Returns:
      true if id == 0, false otherwise
    • isSaved

      public boolean isSaved()
      Checks if bundle was saved already.
      Returns:
      true if id != 0, false otherwise
    • create

      public Property create(String type)
      Create instance of property, that matches given type name from associated bundle definition.
      Parameters:
      type - from bundle definition
      Returns:
      created new EntityProperty instance
      Throws:
      HigsonBundleException - if type is not defined within bundle definition
    • identitySet

      public IdentitySet identitySet()
      Returns identity set with nested properties. It is exposed for IdentityScanner usage. This method shouldn't be used to access elements of bundle and especially modify it's content.
      Returns:
      identity set of properties
      See Also:
    • contains

      public boolean contains(Property prop)
      Checks if given prop property exists within bundle.
      Parameters:
      prop - property to check
      Returns:
      true if exists, false otherwise
    • getAll

      public Set<Property> getAll()
      Get all properties within bundle.
      Returns:
      set of properties
    • deepcopy

      public Bundle deepcopy(boolean resetIds)
      Creates new bundle instance with copied:
      • all bundle data
      • internal fields
      • references
      It applies to all nested properties within bundle root.
      Extra flag is responsible for resetting ids, if set to true.
      Overrides:
      deepcopy in class EntityProperty
      Parameters:
      resetIds - control flag, if true then bundle and all elements will have id's set to 0, if false, id will be copied
      Returns:
      new instance of bundle with copied properties
      See Also:
    • deepcopy

      public Bundle deepcopy()
      Same as deepcopy(boolean), but with flag set to true.
      Overrides:
      deepcopy in class Property
      Returns:
      new instance of bundle with copied properties and reset ids
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class EntityProperty
    • walk

      public void walk(PropertyVisitor visitor)
      This method allows to walk on each property using provided visitor and do some action.
      Parameters:
      visitor - property visitor implementation
      See Also:
    • remove

      public Property remove()
      This method is not supported.
      Specified by:
      remove in interface Handle
      Overrides:
      remove in class Property
      Returns:
      nothing
      Throws:
      UnsupportedOperationException - this is not supported on root bundle level
    • print

      public String print()
      This will print bundle with specific format.
      Example:
      
         bundle D: Bundle[id=0, revision=0]
         * agent  (Client#0  @60861)
           - pesel = null  (string)
           * age = 11  (integer)
         * policy  (Policy#0  @12577)
           * building  (Building#0  @23246)
             * area = 99  (integer)
           * clients  collection(Client)  size=1
             * clients[0]  (Client#0  @31764)
               - addr  (Address#0  @49659)
       
      Specified by:
      print in interface Handle
      Overrides:
      print in class Property
      Returns:
      formatted string
      See Also:
    • toString

      public String toString()
      Description copied from class: EntityProperty
      Formatted String as follows:
      
        EntityProperty[name#23, @432423432, owner=101, fields=field1, refc=2]
       
      Overrides:
      toString in class EntityProperty
      Returns:
      formatted String