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 DatabaseRuleNodeGenerator Generate

From Leeroopedia


Knowledge Sources
Domains Mode_Management, Reflection
Last Updated 2026-02-10 00:00 GMT

Overview

DatabaseRuleNodeGenerator generates DatabaseRuleNode metadata by reflecting on YAML rule configuration class annotations to discover named and unique rule items.

Description

DatabaseRuleNodeGenerator is a utility class with a private constructor that provides static methods to generate DatabaseRuleNode instances. The generate(Class) method inspects a YamlRuleConfiguration class for the @RuleNodeTupleEntity annotation to determine the rule type, then iterates over fields annotated with @RuleNodeTupleField using YamlRuleConfigurationReflectionEngine. Fields of type Map or Collection with @RuleNodeTupleKeyListNameGenerator are classified as named items, while others become unique items. The generate(String) overload locates the YAML class by scanning SPI-loaded YamlRuleConfigurationSwapper instances.

Usage

Use this generator when building the registry node structure for a rule type. It is invoked during rule configuration persistence and during the tuple swapping process to determine which registry paths correspond to which configuration fields.

Code Reference

Source Location

Signature

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DatabaseRuleNodeGenerator {

    public static DatabaseRuleNode generate(final Class<? extends YamlRuleConfiguration> yamlRuleConfigClass)

    public static DatabaseRuleNode generate(final String ruleType)
}

Import

import org.apache.shardingsphere.mode.node.rule.node.DatabaseRuleNodeGenerator;

I/O Contract

Inputs

Name Type Required Description
yamlRuleConfigClass Class<? extends YamlRuleConfiguration> Yes YAML rule config class to reflect upon
ruleType String Yes Rule type string to find the corresponding YAML class via SPI

Outputs

Name Type Description
databaseRuleNode DatabaseRuleNode Generated node containing rule type, named items, and unique items

Usage Examples

// Generate from YAML class directly
DatabaseRuleNode node = DatabaseRuleNodeGenerator.generate(YamlShardingRuleConfiguration.class);
// node.getRuleType() returns "sharding"
// node.getNamedItems() returns ["tables", "algorithms", ...]
// node.getUniqueItems() returns ["default_strategy", ...]

// Generate from rule type string
DatabaseRuleNode node = DatabaseRuleNodeGenerator.generate("sharding");

Related Pages

Page Connections

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