-
-
Notifications
You must be signed in to change notification settings - Fork 250
JSON API draft
In order to store JSON-nodes within Sirix we need a node-transaction API (cursor-like) similar to the XdmNodeReadTrx/XdmNodeWriteTrx-API for XML.
The JSON-resource is also bootstrapped with a DocumentRootNode (the only node in an empty JSON-resource).
JSONNodeWriteTrx:
-
insertString(String)
creates a String node and moves the cursor to the created node -
insertBoolean(boolean)
creates a boolean node and moves the cursor to the created node -
insertNull()
creates a null node and moves the cursor to the created node -
insertNumber(double)
creates a number node and moves the cursor to the created node
All of these nodes can have a right sibling in case they are used in arrays, when used as object values they don't have a right sibling.
-
insertObject()
creates an empty object node and moves the node cursor to the created object node. Inserts the new nodeKey from the inserted object into the parent or the "left-sibling" node, even if there's no order among children in JSON. Otherwise a potential parent would grow and grow (which is always going to be copied).
Key (when the cursor is located on an object-node the only valid method is):
-
insertObjectKey(String)
creates an object-key node and moves the node cursor to the created object-key node
Value (when the cursor is on an object-key the valid methods are and the node keys are inserted into the object key node):
-
insertString(String)
creates a String node -
insertBoolean(boolean)
creates a boolean node -
insertNumber(double)
creates a number node -
insertNull()
creates a null node insertObject()
-
insertArray()
creates an empty array and moves the node cursor to the created array node
On an array the above methods are valid.
Once on another node within an array or on a object-key node, the following methods are valid:
insertStringAsRightSibling(String)
insertBooleanAsRightSibling(boolean)
insertNullAsRightSibling(null)
insertNumberAsRightSibling(double)
insertObjectAsRightSibling()
insertArrayAsRightSibling()
Object-key nodes are stored with a pointer to the next object-key node within an object, otherwise the object-node would grow with the number of object-keys (and we need to copy-on-write the parent). Similar behavior for array-nodes. Object-key nodes store a pointer to their first (and maybe only child), the node which has the value. All nodes in general also store the nodeKey/ID of their parent node.
JSONNodeReadTrx simply implements our NodeCursor-API, then we get for instance the diffing, the ChildAxis, DescendantAxis... for free: https://github.com/sirixdb/sirix/blob/master/bundles/sirix-core/src/main/java/org/sirix/api/NodeCursor.java