Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Shardingsphere MemoryRepository Persist

From Leeroopedia


Knowledge Sources
Domains Persistence, Standalone
Last Updated 2026-02-10 00:00 GMT

Overview

MemoryRepository is an in-memory standalone persist repository using a TreeMap for hierarchical key-value storage without durability.

Description

MemoryRepository implements StandalonePersistRepository with a simple TreeMap<String, String> backing store. The query method returns the value directly from the map. getChildrenKeys uses TreeMap.subMap with a search prefix to efficiently find all entries under a parent path, extracts the immediate child segment by finding the next slash after the prefix, deduplicates, and filters empty results. isExisted checks containsKey. persist puts the key-value pair unconditionally. update puts only if the key already exists. delete removes the exact key. The close method is a no-op. It is registered as the default standalone repository type (isDefault returns true) with type "Memory".

Usage

Use this repository for testing, development, or lightweight standalone scenarios where metadata persistence across restarts is not required. It is the default repository when no explicit repository type is configured in standalone mode.

Code Reference

Source Location

Signature

public final class MemoryRepository implements StandalonePersistRepository {

    public String query(final String key)

    public List<String> getChildrenKeys(final String key)

    public boolean isExisted(final String key)

    public void persist(final String key, final String value)

    public void update(final String key, final String value)

    public void delete(final String key)

    public void close()

    public Object getType()

    public boolean isDefault()
}

Import

import org.apache.shardingsphere.mode.repository.standalone.memory.MemoryRepository;

I/O Contract

Inputs

Name Type Required Description
key String Yes Hierarchical path key for all operations
value String Yes Data value for persist and update operations

Outputs

Name Type Description
queryResult String Value at the key, or null if not found
childrenKeys List<String> Immediate child key names under the parent path
isExisted boolean Whether the key exists in the TreeMap

Usage Examples

MemoryRepository repository = new MemoryRepository();

// Persist data
repository.persist("/metadata/my_db/rules/sharding", "sharding_config_yaml");

// Query data
String config = repository.query("/metadata/my_db/rules/sharding");

// List children
List<String> children = repository.getChildrenKeys("/metadata/my_db/rules");
// Returns: ["sharding"]

// Update existing data
repository.update("/metadata/my_db/rules/sharding", "updated_config_yaml");

// Delete
repository.delete("/metadata/my_db/rules/sharding");

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment