Skip to content

Commit 7c367c5

Browse files
dmealingclaude
andcommitted
refactor(java): post-review simplifications in Stage 2 Unit 1
- ValidationPhase: replace manual MetaSource child iteration in validateObjectPrimarySource with obj.getSources() (own-only) - ValidationPhase: replace 5-way &&-chain @kind check with MetaSource.VALID_KINDS.contains(), matching REFERENTIAL_ACTIONS pattern - ValidationPhase: replace 6-way &&-chain @ROLE check with MetaSource.VALID_ROLES.contains() - MetaSource: add VALID_KINDS and VALID_ROLES Set constants, symmetric to the existing READ_ONLY_KINDS and the relationship REFERENTIAL_ACTIONS Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d266fcc commit 7c367c5

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

server/java/metadata/src/main/java/com/metaobjects/loader/ValidationPhase.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,7 @@ private static void validateSourceNode(MetaData node) {
204204
// Validate @kind (own attribute only — defaults are fine)
205205
if (node.hasMetaAttr(MetaSource.ATTR_KIND, false)) {
206206
String kind = src.getEffectiveKind();
207-
if (!MetaSource.KIND_TABLE.equals(kind)
208-
&& !MetaSource.KIND_VIEW.equals(kind)
209-
&& !MetaSource.KIND_MATERIALIZED_VIEW.equals(kind)
210-
&& !MetaSource.KIND_STORED_PROC.equals(kind)
211-
&& !MetaSource.KIND_TABLE_FUNCTION.equals(kind)) {
207+
if (!MetaSource.VALID_KINDS.contains(kind)) {
212208
throw new MetaDataException(
213209
ErrorMessageConstants.ERR_BAD_ATTR_VALUE
214210
+ ": source '" + node.getName()
@@ -222,12 +218,7 @@ private static void validateSourceNode(MetaData node) {
222218
// Validate @role (own attribute only — defaults are fine)
223219
if (node.hasMetaAttr(MetaSource.ATTR_ROLE, false)) {
224220
String role = src.getRole();
225-
if (!MetaSource.ROLE_PRIMARY.equals(role)
226-
&& !MetaSource.ROLE_REPLICA.equals(role)
227-
&& !MetaSource.ROLE_INDEX.equals(role)
228-
&& !MetaSource.ROLE_CACHE.equals(role)
229-
&& !MetaSource.ROLE_PUBLISH.equals(role)
230-
&& !MetaSource.ROLE_MIRROR.equals(role)) {
221+
if (!MetaSource.VALID_ROLES.contains(role)) {
231222
throw new MetaDataException(
232223
ErrorMessageConstants.ERR_BAD_ATTR_VALUE
233224
+ ": source '" + node.getName()
@@ -287,13 +278,9 @@ private static void walkOnePrimarySource(MetaData node) {
287278
* @throws MetaDataException if the one-primary rule is violated
288279
*/
289280
private static void validateObjectPrimarySource(MetaObject obj) {
290-
// Collect own MetaSource children (own-only, includeParentData=false).
291-
java.util.List<MetaSource> sources = new java.util.ArrayList<>();
292-
for (MetaData child : obj.getChildren(MetaData.class, false)) {
293-
if (child instanceof MetaSource) {
294-
sources.add((MetaSource) child);
295-
}
296-
}
281+
// Own-only MetaSource children — delegates to MetaObject.getSources() to avoid
282+
// duplicating the child-collection logic here.
283+
java.util.Collection<MetaSource> sources = obj.getSources();
297284

298285
if (sources.isEmpty()) {
299286
// No sources declared — object is not persisted; no rule to enforce.

server/java/metadata/src/main/java/com/metaobjects/source/MetaSource.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ public abstract class MetaSource extends MetaData {
6464
KIND_TABLE_FUNCTION
6565
);
6666

67+
/** All valid {@code @kind} values. Used by {@code ValidationPhase} for enum-membership checks. */
68+
public static final Set<String> VALID_KINDS = Set.of(
69+
KIND_TABLE,
70+
KIND_VIEW,
71+
KIND_MATERIALIZED_VIEW,
72+
KIND_STORED_PROC,
73+
KIND_TABLE_FUNCTION
74+
);
75+
6776
// === ROLE VALUE CONSTANTS ===
6877

6978
public static final String ROLE_PRIMARY = "primary";
@@ -76,6 +85,11 @@ public abstract class MetaSource extends MetaData {
7685
/** Default role when {@code @role} is absent. */
7786
public static final String DEFAULT_ROLE = ROLE_PRIMARY;
7887

88+
/** All valid {@code @role} values. Used by {@code ValidationPhase} for enum-membership checks. */
89+
public static final Set<String> VALID_ROLES = Set.of(
90+
ROLE_PRIMARY, ROLE_REPLICA, ROLE_INDEX, ROLE_CACHE, ROLE_PUBLISH, ROLE_MIRROR
91+
);
92+
7993
// -----------------------------------------------------------------------
8094
// Constructor
8195
// -----------------------------------------------------------------------

0 commit comments

Comments
 (0)