Class EmbeddedJsonCache

java.lang.Object
org.infinispan.server.resp.json.EmbeddedJsonCache

public class EmbeddedJsonCache extends Object
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 Details

  • Constructor Details

    • EmbeddedJsonCache

      public EmbeddedJsonCache(Cache<byte[],JsonBucket> cache)
  • 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

      public CompletionStage<String> set(byte[] key, byte[] value, byte[] path, boolean nx, boolean xx)
      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 - If true, the operation will only succeed if the key does not already exist (NX - "Not Exists").
      xx - If true, the operation will only succeed if the key already exists (XX - "Exists").
      Returns:
      A CompletionStage containing the result of the operation as a String.
    • len

      public CompletionStage<List<Long>> len(byte[] key, byte[] path, LenType lenType)
      Retrieves the length of a JSON value at the specified path based on the given LenType.

      Returns:

      • Object → Number of key-value pairs
      • Array → Number of elements
      • String → Character count
      Returns null if the value does not match the specified lenType.
      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 a List of lengths or null if mismatched.
    • type

      public CompletionStage<List<String>> type(byte[] key, byte[] path)
      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 a List of type strings, representing the type of the JSON value at each path (e.g., "object", "array", "string", etc.).
    • del

      public CompletionStage<Long> del(byte[] key, byte[] path)
      Deletes the value at the given path in the JSON document.
      Parameters:
      key - the key of the JSON document
      path - the path to the value to be deleted
      Returns:
      a CompletionStage of the number of bytes deleted
    • arrAppend

      public CompletionStage<List<Long>> arrAppend(byte[] key, byte[] path, List<byte[]> values)
      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

      public CompletionStage<List<Long>> 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. If the path exists but is not a string, no changes are made. IllegalArgumentException is thrown.
      Parameters:
      key - the key identifying the JSON document
      path - the path to the array in the JSON document
      value - 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

      public CompletionStage<List<Integer>> toggle(byte[] key, byte[] path)
      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 a List<Integer> of results:
      • 1 if toggled to true
      • 0 if toggled to false
      • null if the value is not a boolean
    • objkeys

      public 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.
      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 a List of list of byte arrays, each representing a key in the JSON object or null if object is not a json object.