Package io.higson.runtime.model.value
Class Bundle
java.lang.Object
io.higson.runtime.model.value.Property
io.higson.runtime.model.value.EntityProperty
io.higson.runtime.model.value.Bundle
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
Example of bundle creation and setup some properties:
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 Summary
ConstructorsConstructorDescriptionBasic constructor to use with definition.Shouldn't be used outside of Higson persistence engine.Shouldn't be used outside of Higson persistence engine.Shouldn't be used outside of Higson persistence engine. -
Method Summary
Modifier and TypeMethodDescriptionAdds givenpropertyunder providedname.booleanChecks if givenpropproperty exists within bundle.Create instance of property, that matches giventypename from associated bundle definition.deepcopy()Same asdeepcopy(boolean), but with flag set totrue.deepcopy(boolean resetIds) Creates new bundle instance with copied: all bundle data internal fields references It applies to all nested properties within bundle root.booleangetAll()Get all properties within bundle.Get bundle's creation time.getDef()Get bundle's definition.intGet last lob hash.intGet bundle's revision.Get bundle's last update timeinthashCode()Returns identity set with nested properties.booleanChecks if bundle was not saved yet.booleanisRoot()Since bundle is always a root, it will returntrue.booleanisSaved()Checks if bundle was saved already.print()This will print bundle with specific format.
Example:remove()This method is not supported.voidsetCreated(Date created) Shouldn't be used outside of Higson persistence engine.voidsetLobHash(int lobHash) Shouldn't be used outside of Higson persistence engine.voidsetRevision(int revision) Shouldn't be used outside of Higson persistence engine.voidsetUpdated(Date updated) Shouldn't be used outside of Higson persistence engine.toString()Formatted String as follows:voidwalk(PropertyVisitor visitor) This method allows to walk on each property using providedvisitorand do some action.Methods inherited from class io.higson.runtime.model.value.EntityProperty
containsOnlyEntityFields, create, find, getElementType, getFields, getId, getProp, getState, getValue, has, isEntity, mark, print, printValues, resetIds, set, setBundle, setId, sizeMethods inherited from class io.higson.runtime.model.value.Property
add, add, asCollection, asEntity, asRef, asValue, at, booleanValue, booleanValue, bundle, clear, get, getBoolean, getBoolean, getBundle, getCanonicalPath, getCollection, getContainer, getDate, getDate, getDatetime, getDatetime, getDecimal, getDecimal, getEntity, getHolder, getHolder, getInteger, getInteger, getLong, getLong, getName, getNumber, getNumber, getOwnerId, getOwnerPropertyName, getParent, getParentName, getPath, getRefCount, getRefTarget, getString, getString, getType, getTypeCode, intValue, intValue, isCollection, isPersistent, isTransient, isValue, iterator, remove, set, setContainer, setName, setOwnerId, setParent, setupOwnerId, traverseMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Bundle
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
Shouldn't be used outside of Higson persistence engine. Basic constructor with definition and id.- Parameters:
def- bundle definitionid- bundle id
-
Bundle
Shouldn't be used outside of Higson persistence engine. Basic constructor with definition, id and revision.- Parameters:
def- bundle definitionid- bundle idrevision- bundle revision starting number
-
Bundle
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 definitionid- bundle idrevision- bundle revision starting numberexpectedSize- size of created identity set
-
-
Method Details
-
add
Adds givenpropertyunder providedname. It is another way of setting properties within bundle.- Overrides:
addin classEntityProperty- Parameters:
name- unique nameprop- property to store under name- Returns:
- same bundle instance
- See Also:
-
isRoot
public boolean isRoot()Since bundle is always a root, it will returntrue. -
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
Get bundle's creation time.- Returns:
- bundle's creation time
-
setCreated
Shouldn't be used outside of Higson persistence engine.- Parameters:
created- creation date
-
getUpdated
Get bundle's last update time- Returns:
- bundle's last update time
-
setUpdated
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
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
Create instance of property, that matches giventypename 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
Returns identity set with nested properties. It is exposed forIdentityScannerusage. 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
Checks if givenpropproperty exists within bundle.- Parameters:
prop- property to check- Returns:
- true if exists, false otherwise
-
getAll
Get all properties within bundle.- Returns:
- set of properties
-
deepcopy
Creates new bundle instance with copied:- all bundle data
- internal fields
- references
Extra flag is responsible for resetting ids, if set totrue.- Overrides:
deepcopyin classEntityProperty- 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
Same asdeepcopy(boolean), but with flag set totrue. -
equals
- Overrides:
equalsin classEntityProperty
-
hashCode
public int hashCode()- Overrides:
hashCodein classEntityProperty
-
walk
This method allows to walk on each property using providedvisitorand do some action.- Parameters:
visitor- property visitor implementation- See Also:
-
remove
This method is not supported.- Specified by:
removein interfaceHandle- Overrides:
removein classProperty- Returns:
- nothing
- Throws:
UnsupportedOperationException- this is not supported on root bundle level
-
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) -
toString
Description copied from class:EntityPropertyFormatted String as follows:EntityProperty[name#23, @432423432, owner=101, fields=field1, refc=2]- Overrides:
toStringin classEntityProperty- Returns:
- formatted String
-