From 262e1dbc8101e93453ab0bb5b9c457f2b3520b82 Mon Sep 17 00:00:00 2001 From: MarcGuiot Date: Thu, 26 Sep 2024 21:23:59 +0200 Subject: [PATCH] cleaning --- .../impl/DefaultUniqueFunctionalKeyRepository.java | 2 +- .../core/metamodel/annotations/AllAnnotations.java | 2 +- .../metamodel/annotations/FieldNameAnnotationType.java | 7 +++---- .../core/metamodel/impl/DefaultGlobModel.java | 7 +++---- .../core/metamodel/impl/DefaultGlobType.java | 2 +- .../core/utils/exceptions/DuplicateGlobType.java | 7 +++++++ 6 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/globsframework/core/utils/exceptions/DuplicateGlobType.java diff --git a/src/main/java/org/globsframework/core/functional/impl/DefaultUniqueFunctionalKeyRepository.java b/src/main/java/org/globsframework/core/functional/impl/DefaultUniqueFunctionalKeyRepository.java index f6ba580..762f9ec 100644 --- a/src/main/java/org/globsframework/core/functional/impl/DefaultUniqueFunctionalKeyRepository.java +++ b/src/main/java/org/globsframework/core/functional/impl/DefaultUniqueFunctionalKeyRepository.java @@ -23,7 +23,7 @@ public class DefaultUniqueFunctionalKeyRepository implements MutableFunctionalKeyRepository { static private final Logger LOGGER = LoggerFactory.getLogger(DefaultUniqueFunctionalKeyRepository.class); - private static final Glob NULL = new DefaultGlob(DefaultGlobTypeBuilder.init("NULL GLOB").get()); + private static final Glob NULL = DefaultGlobTypeBuilder.init("NULL GLOB").get().instantiate(); private final DataAccess dataAccess; private final Map index = new ConcurrentHashMap<>(); private final MapOfMaps indexed = new ConcurrentMapOfMaps<>(); diff --git a/src/main/java/org/globsframework/core/metamodel/annotations/AllAnnotations.java b/src/main/java/org/globsframework/core/metamodel/annotations/AllAnnotations.java index 54547f7..8ad6049 100644 --- a/src/main/java/org/globsframework/core/metamodel/annotations/AllAnnotations.java +++ b/src/main/java/org/globsframework/core/metamodel/annotations/AllAnnotations.java @@ -5,7 +5,7 @@ public class AllAnnotations { static final public GlobModel MODEL = - new DefaultGlobModel(DefaultStringAnnotationType.DESC, AutoIncrementAnnotationType.TYPE, + new DefaultGlobModel(AutoIncrementAnnotationType.TYPE, ContainmentLinkAnnotationType.DESC, DefaultBooleanAnnotationType.TYPE, DefaultDoubleAnnotationType.DESC, DefaultFieldValueType.TYPE, DefaultIntegerAnnotationType.DESC, DefaultLongAnnotationType.DESC, diff --git a/src/main/java/org/globsframework/core/metamodel/annotations/FieldNameAnnotationType.java b/src/main/java/org/globsframework/core/metamodel/annotations/FieldNameAnnotationType.java index 27011f8..2b56cc6 100644 --- a/src/main/java/org/globsframework/core/metamodel/annotations/FieldNameAnnotationType.java +++ b/src/main/java/org/globsframework/core/metamodel/annotations/FieldNameAnnotationType.java @@ -13,12 +13,11 @@ import java.util.LinkedHashMap; public class FieldNameAnnotationType { - public static GlobType TYPE; + public static final GlobType TYPE; - public static StringField NAME; + public static final StringField NAME; - @InitUniqueKey - public static Key UNIQUE_KEY; + public static final Key UNIQUE_KEY; public static Glob create(FieldNameAnnotation nameAnnotation) { return create(nameAnnotation.value()); diff --git a/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobModel.java b/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobModel.java index f37ac1f..41bb913 100644 --- a/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobModel.java +++ b/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobModel.java @@ -6,14 +6,12 @@ import org.globsframework.core.metamodel.MutableGlobModel; import org.globsframework.core.metamodel.links.impl.DefaultMutableGlobLinkModel; import org.globsframework.core.metamodel.utils.GlobTypeDependencies; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.globsframework.core.utils.exceptions.DuplicateGlobType; import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class DefaultGlobModel implements MutableGlobModel { - private static Logger LOGGER = LoggerFactory.getLogger(DefaultGlobModel.class); private Map typesByName = new ConcurrentHashMap<>(); private GlobModel innerModel; private GlobTypeDependencies dependencies; @@ -71,7 +69,8 @@ private void add(GlobType... types) { public void add(GlobType type) { GlobType put = typesByName.put(type.getName(), type); if (put != null && put != type) { - LOGGER.error(type.getName() + " already registered : " + type.describe() + " AND " + put.describe(), new RuntimeException()); + String message = type.getName() + " already registered : " + type.describe() + " AND " + put.describe(); + throw new DuplicateGlobType(message); } } diff --git a/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobType.java b/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobType.java index 2c465dd..665a0b4 100644 --- a/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobType.java +++ b/src/main/java/org/globsframework/core/metamodel/impl/DefaultGlobType.java @@ -155,7 +155,7 @@ public void completeInit() { if (annotation != null) { int index = annotation.get(KeyAnnotationType.INDEX, -1); if (index == -1) { - ((MutableAnnotations) field).addAnnotation(KeyAnnotationType.create(field.getKeyIndex())); + field.addAnnotation(KeyAnnotationType.create(field.getKeyIndex())); keySet.add(field.getKeyIndex()); } else { keySet.add(index); diff --git a/src/main/java/org/globsframework/core/utils/exceptions/DuplicateGlobType.java b/src/main/java/org/globsframework/core/utils/exceptions/DuplicateGlobType.java new file mode 100644 index 0000000..5373aa8 --- /dev/null +++ b/src/main/java/org/globsframework/core/utils/exceptions/DuplicateGlobType.java @@ -0,0 +1,7 @@ +package org.globsframework.core.utils.exceptions; + +public class DuplicateGlobType extends RuntimeException { + public DuplicateGlobType(String message) { + super(message); + } +}