Class Tree
- All Implemented Interfaces:
Closeable,AutoCloseable
Depends on a compatible tree model (entity types), which is matched by type and property names. E.g. names like "DataLeaf.valueString" are fixed and may not be changed. Adding properties to tree types is allowed.
Note there are TWO ways to work with tree data (both ways can be mixed): - Standard ObjectBox entity types with e.g. Box<DataLeaf> - Higher level tree API via this Tree class
To navigate in the tree, you typically start with getRoot(), which returns a Branch.
From one branch you can navigate to other branches and also Leafs, which carry data attributes.
You can easily navigate the tree by using a path, which is either a string or a string array. A path refers to the names of the meta tree nodes, e.g. "Book.Author.Name".
If you already know the IDs, you can efficiently access branches, data leaves, and data values directly.
To access any data in the tree, you must use explicit transactions offer by methods such as
runInTx(Runnable), runInReadTx(Runnable), callInTx(Callable), or
callInReadTx(Callable).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TcallInReadTx(Callable<T> callable) Similar toBoxStore.callInReadTx(Callable), but allows Tree functions.<T> TSimilar toBoxStore.callInReadTx(Callable), but allows Tree functions.<T> TcallInTxNoThrow(Callable<T> callable) Wraps any Exception thrown by the callable into a RuntimeException.voidclose()Cleans up any (native) resources associated with this tree.private <T> Callable<T> createTxCallable(Callable<T> callable) private RunnablecreateTxRunnable(Runnable runnable) getDouble(long id) Get data value for the given ID or null if no data leaf exists with that ID.(package private) longgetInteger(long id) Get data value for the given ID or null if no data leaf exists with that ID.getLeaf(long id) Get the leaf for the given ID or null if no leaf exists with that ID.The path separator regex is used to split a string path into individual path names.getRoot()Gets the root of the data tree.longThe root ID, which the tree was constructed with.getStore()getString(long id) Get data value for the given ID or null if no data leaf exists with that ID.(package private) voidnativeClearTransaction(long handle) (package private) static longnativeCreate(long store, long rootId) Create a (Data)Tree instance for the given meta-branch root, or find a singular root if 0 is given.(package private) static longnativeCreateWithUid(long store, String uid) Not usable yet; TX is not aligned(package private) static voidnativeDelete(long handle) (package private) LeafNodenativeGetLeafById(long treeHandle, long leafId) (package private) longnativeGetRootId(long handle) Get the root data branch ID.(package private) longnativePutBranch(long treeHandle, long id, long parentBranchId, long metaId, String uid) (package private) longnativePutMetaBranch(long treeHandle, long id, long parentBranchId, String name, String description) (package private) long[]nativePutMetaBranches(long treeHandle, long parentBranchId, String[] path) (package private) longnativePutMetaLeaf(long treeHandle, long id, long parentBranchId, String name, short valueType, boolean isUnsigned, String description) (package private) longnativePutValueFP(long treeHandle, long id, long parentBranchId, long metaId, double value) (package private) longnativePutValueInteger(long treeHandle, long id, long parentBranchId, long metaId, long value) (package private) longnativePutValueString(long treeHandle, long id, long parentBranchId, long metaId, String value) (package private) booleannativeSetTransaction(long handle, long txHandle) longPuts (persists) a data leaf (containing a data value).longputBranch(long parentBranchId, long metaId) Put a new (inserts) data branchlongPut a new or existing data branchlongPut a new (inserts) data branchlongputMetaBranch(long id, long parentBranchId, String name) Puts (persists) a branch in the metamodel.longputMetaBranch(long id, long parentBranchId, String name, String description) Puts (persists) a branch in the metamodel with an optional description.long[]putMetaBranches(long parentBranchId, String[] path) Puts (persists) several branches in the metamodel from the given parent ID (must be a meta branch).long[]putMetaBranches(String[] path) Puts (persists) several branches in the metamodel to create the given path from the root.longputMetaLeaf(long id, long parentBranchId, String name, short valueType) Puts (persists) a data leaf in the metamodel (describes values).longputMetaLeaf(long id, long parentBranchId, String name, short valueType, boolean isUnsigned) Puts (persists) a data leaf in the metamodel (describes values).longputMetaLeaf(long id, long parentBranchId, String name, short valueType, boolean isUnsigned, String description) Puts (persists) a data leaf in the metamodel (describes values).longputValue(long parentBranchId, long metaId, double value) Puts (inserts) a new data value (using a data leaf).longputValue(long parentBranchId, long metaId, long value) Puts (inserts) a new data value (using a data leaf).longputValue(long id, long parentBranchId, long metaId, double value) Puts (persists) a data value (using a data leaf).longputValue(long id, long parentBranchId, long metaId, long value) Puts (persists) a data value (using a data leaf).longPuts (persists) a data value (using a data leaf).longPuts (inserts) a new data value (using a data leaf).voidrunInReadTx(Runnable runnable) Similar toBoxStore.runInReadTx(Runnable), but allows Tree functions.voidSimilar toBoxStore.runInTx(Runnable), but allows Tree functions.voidsetPathSeparatorRegex(String pathSeparatorRegex) E.g.
-
Field Details
-
handle
private long handle -
store
-
rootId
private long rootId -
pathSeparatorRegex
-
-
Constructor Details
-
Tree
Create a tree instance for the given meta-branch rootuid, or find a singular root if 0 is given. -
Tree
Create a tree instance for the given data-branch root ID.
-
-
Method Details
-
getHandle
long getHandle() -
getPathSeparatorRegex
The path separator regex is used to split a string path into individual path names. Example: with the default separator, e.g. "Book.Author" becomes ["Book", "Author"]. -
setPathSeparatorRegex
E.g. use "\\/" to change path strings to "Book/Author"; seegetPathSeparatorRegex()for details. -
getRootId
public long getRootId()The root ID, which the tree was constructed with. -
getStore
-
getRoot
Gets the root of the data tree. -
close
public void close()Cleans up any (native) resources associated with this tree.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
runInTx
Similar toBoxStore.runInTx(Runnable), but allows Tree functions. -
runInReadTx
Similar toBoxStore.runInReadTx(Runnable), but allows Tree functions. -
callInTx
Similar toBoxStore.callInReadTx(Callable), but allows Tree functions.- Throws:
Exception
-
callInTxNoThrow
Wraps any Exception thrown by the callable into a RuntimeException. -
callInReadTx
Similar toBoxStore.callInReadTx(Callable), but allows Tree functions. -
createTxRunnable
-
createTxCallable
-
getLeaf
Get the leaf for the given ID or null if no leaf exists with that ID. -
getString
Get data value for the given ID or null if no data leaf exists with that ID. -
getInteger
Get data value for the given ID or null if no data leaf exists with that ID. -
getDouble
Get data value for the given ID or null if no data leaf exists with that ID. -
putMetaBranch
Puts (persists) a branch in the metamodel. -
putMetaBranch
Puts (persists) a branch in the metamodel with an optional description. -
putMetaBranches
Puts (persists) several branches in the metamodel to create the given path from the root. -
putMetaBranches
Puts (persists) several branches in the metamodel from the given parent ID (must be a meta branch). -
putMetaLeaf
Puts (persists) a data leaf in the metamodel (describes values). -
putMetaLeaf
public long putMetaLeaf(long id, long parentBranchId, String name, short valueType, boolean isUnsigned) Puts (persists) a data leaf in the metamodel (describes values). -
putMetaLeaf
public long putMetaLeaf(long id, long parentBranchId, String name, short valueType, boolean isUnsigned, @Nullable String description) Puts (persists) a data leaf in the metamodel (describes values). -
putBranch
Put a new or existing data branch -
putBranch
Put a new (inserts) data branch -
putBranch
public long putBranch(long parentBranchId, long metaId) Put a new (inserts) data branch -
putValue
public long putValue(long id, long parentBranchId, long metaId, long value) Puts (persists) a data value (using a data leaf). If a data leaf exists at the given ID, it's overwritten.- Parameters:
id- Existing ID or zero to insert a new data leaf.parentBranchId- ID of the data branch, this data value belongs to.metaId- ID of the metadata leaf "describing" this data value.value- the actual data value.- Returns:
- the ID of the put data leaf.
-
putValue
public long putValue(long parentBranchId, long metaId, long value) Puts (inserts) a new data value (using a data leaf).- Parameters:
parentBranchId- ID of the data branch, this data value belongs to.metaId- ID of the metadata leaf "describing" this data value.value- the actual data value.- Returns:
- the ID of the new data leaf.
-
putValue
public long putValue(long parentBranchId, long metaId, double value) Puts (inserts) a new data value (using a data leaf).- Parameters:
parentBranchId- ID of the data branch, this data value belongs to.metaId- ID of the metadata leaf "describing" this data value.value- the actual data value.- Returns:
- the ID of the new data leaf.
-
putValue
public long putValue(long id, long parentBranchId, long metaId, double value) Puts (persists) a data value (using a data leaf). If a data leaf exists at the given ID, it's overwritten.- Parameters:
id- Existing ID or zero to insert a new data leaf.parentBranchId- ID of the data branch, this data value belongs to.metaId- ID of the metadata leaf "describing" this data value.value- the actual data value.- Returns:
- the ID of the put data leaf.
-
putValue
Puts (persists) a data value (using a data leaf). If a data leaf exists at the given ID, it's overwritten.- Parameters:
id- Existing ID or zero to insert a new data leaf.parentBranchId- ID of the data branch, this data value belongs to.metaId- ID of the metadata leaf "describing" this data value.value- the actual data value.- Returns:
- the ID of the put data leaf.
-
putValue
Puts (inserts) a new data value (using a data leaf).- Parameters:
parentBranchId- ID of the data branch, this data value belongs to.metaId- ID of the metadata leaf "describing" this data value.value- the actual data value.- Returns:
- the ID of the new data leaf.
-
put
Puts (persists) a data leaf (containing a data value). If a data leaf exists with the same ID, it's overwritten.- Returns:
- the ID of the put data leaf.
-
nativeCreate
static long nativeCreate(long store, long rootId) Create a (Data)Tree instance for the given meta-branch root, or find a singular root if 0 is given. -
nativeCreateWithUid
Not usable yet; TX is not aligned -
nativeDelete
static void nativeDelete(long handle) -
nativeSetTransaction
boolean nativeSetTransaction(long handle, long txHandle) -
nativeClearTransaction
void nativeClearTransaction(long handle) -
nativeGetRootId
long nativeGetRootId(long handle) Get the root data branch ID. -
nativeGetLeafById
-
nativePutMetaBranch
-
nativePutMetaBranches
-
nativePutMetaLeaf
-
nativePutBranch
long nativePutBranch(long treeHandle, long id, long parentBranchId, long metaId, @Nullable String uid) -
nativePutValueInteger
long nativePutValueInteger(long treeHandle, long id, long parentBranchId, long metaId, long value) -
nativePutValueFP
long nativePutValueFP(long treeHandle, long id, long parentBranchId, long metaId, double value) -
nativePutValueString
long nativePutValueString(long treeHandle, long id, long parentBranchId, long metaId, @Nullable String value)
-