Package org.infinispan.server.resp.json
Class EmbeddedJsonCache
java.lang.Object
org.infinispan.server.resp.json.EmbeddedJsonCache
A cache implementation for JSON data, providing various methods for interacting with and
manipulating JSON objects, arrays, and values. This class includes methods for setting,
retrieving, and querying JSON data in an embedded cache.
Note: The implementation provides a set of functionalities for handling JSON objects, including operations like recursively extracting values, checking types, and working with specific paths.
- Since:
- 15.2
- Author:
- Vittorio Rigamonti, Katia Aresti
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AdvancedCache
<byte[], JsonBucket> protected final InternalEntryFactory
static final String
static final String
protected final FunctionalMap.ReadWriteMap
<byte[], JsonBucket> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the given values to the array at the specified paths in the JSON document associated with the specified key.del
(byte[] key, byte[] path) Deletes the value at the given path in the JSON document.CompletionStage
<byte[]> Retrieves the JSON value at the specified paths within the given key.Retrieves the length of a JSON value at the specified path based on the givenLenType
.CompletionStage
<List<List<byte[]>>> objkeys
(byte[] key, byte[] path) Retrieves the keys of the JSON object at the specified path within the given JSON document.set
(byte[] key, byte[] value, byte[] path, boolean nx, boolean xx) Sets a JSON value at the specified path in the given key.strAppend
(byte[] key, byte[] path, byte[] value) Appends the given value to the string at the specified paths in the JSON document associated with the specified key.toggle
(byte[] key, byte[] path) Toggles the boolean value at the specified JSON path in the stored JSON document.type
(byte[] key, byte[] path) Reports the type of the JSON value at the specified path within the given JSON.
-
Field Details
-
ERR_KEY_CAN_T_BE_NULL
- See Also:
-
ERR_VALUE_CAN_T_BE_NULL
- See Also:
-
readWriteMap
-
cache
-
entryFactory
-
-
Constructor Details
-
EmbeddedJsonCache
-
-
Method Details
-
get
public CompletionStage<byte[]> get(byte[] key, List<byte[]> paths, byte[] space, byte[] newline, byte[] indent) Retrieves the JSON value at the specified paths within the given key. The resulting JSON content can be formatted with the provided spacing, newline, and indentation settings.- Parameters:
key
- The key from which the JSON value will be retrieved, represented as a byte array.paths
- A list of JSON paths used to access specific values within the JSON, each represented as a byte array.space
- The byte array used to represent spaces for formatting the JSON output.newline
- The byte array used to represent newline characters for formatting the JSON output.indent
- The byte array used to represent indentation characters for formatting the JSON output.- Returns:
- A
CompletionStage
containing the formatted JSON content as a byte array.
-
set
Sets a JSON value at the specified path in the given key.- Parameters:
key
- The key in which the JSON value should be stored, represented as a byte array.value
- The JSON value to set, represented as a byte array.path
- The JSON path where the value should be inserted, represented as a byte array.nx
- Iftrue
, the operation will only succeed if the key does not already exist (NX - "Not Exists").xx
- Iftrue
, the operation will only succeed if the key already exists (XX - "Exists").- Returns:
- A
CompletionStage
containing the result of the operation as aString
.
-
len
Retrieves the length of a JSON value at the specified path based on the givenLenType
.Returns:
- Object → Number of key-value pairs
- Array → Number of elements
- String → Character count
null
if the value does not match the specifiedlenType
.- Parameters:
key
- The JSON document key.path
- The JSON path to evaluate.lenType
- The type (OBJECT, ARRAY, STRING) whose length to compute.- Returns:
- A
CompletionStage
with aList
of lengths ornull
if mismatched.
-
type
Reports the type of the JSON value at the specified path within the given JSON. The result will indicate the type of the value at each path in the list.- Parameters:
key
- The key representing the JSON document, provided as a byte array.path
- The JSON path at which the type of the value should be determined, provided as a byte array.- Returns:
- A
CompletionStage
containing aList
of type strings, representing the type of the JSON value at each path (e.g., "object", "array", "string", etc.).
-
del
Deletes the value at the given path in the JSON document.- Parameters:
key
- the key of the JSON documentpath
- the path to the value to be deleted- Returns:
- a
CompletionStage
of the number of bytes deleted
-
arrAppend
Appends the given values to the array at the specified paths in the JSON document associated with the specified key. If the paths does not refer to an array, no changes are made to the document.- Parameters:
key
- The key of the JSON document to update.path
- The JSON path of the array to append to.values
- The values to append to the array.- Returns:
- A
CompletionStage
that will complete with the returning a list of the new lengths of the changed arrays. Null is returned for the matching paths that are not arrays.
-
strAppend
Appends the given value to the string at the specified paths in the JSON document associated with the specified key. If the path exists but is not a string, no changes are made.IllegalArgumentException
is thrown.- Parameters:
key
- the key identifying the JSON documentpath
- the path to the array in the JSON documentvalue
- the value to append to the array- Returns:
- A
CompletionStage
that will complete with the returning a list of the new lengths of the changed string. Null is returned for the matching paths that are not string.
-
toggle
Toggles the boolean value at the specified JSON path in the stored JSON document. If the value is `true`, it becomes `false`, and vice versa. Non-boolean values result in `null`.- Parameters:
key
- The key identifying the JSON document in the Infinispan cache.path
- The JSON path where the boolean value should be toggled.- Returns:
- A
CompletionStage
with aList<Integer>
of results:1
if toggled totrue
0
if toggled tofalse
null
if the value is not a boolean
-
objkeys
Retrieves the keys of the JSON object at the specified path within the given JSON document.- Parameters:
key
- The key representing the JSON document, provided as a byte array.path
- The JSON path at which the keys should be retrieved, provided as a byte array.- Returns:
- A
CompletionStage
containing aList
of list of byte arrays, each representing a key in the JSON object or null if object is not a json object.
-