This is an automated email from the ASF dual-hosted git repository.

mpochatkin pushed a commit to branch IGNITE-22277
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit e80d7ac55ddafbd6a70799263c6883ef5d275bc8
Author: Mikhail Pochatkin <[email protected]>
AuthorDate: Fri May 31 12:56:04 2024 +0300

    IGNITE-22277 Rework Zone annotation
---
 .../org/apache/ignite/catalog/DefaultZone.java     | 27 --------------
 .../apache/ignite/catalog/annotations/Table.java   | 10 ++++--
 .../apache/ignite/catalog/annotations/Zone.java    | 19 +++++-----
 .../ignite/internal/catalog/ItCatalogDslTest.java  | 10 +++---
 .../catalog/sql/CreateFromAnnotationsImpl.java     | 14 ++++----
 .../catalog/sql/CreateFromAnnotationsTest.java     | 42 ++++++++++++----------
 6 files changed, 49 insertions(+), 73 deletions(-)

diff --git 
a/modules/api/src/main/java/org/apache/ignite/catalog/DefaultZone.java 
b/modules/api/src/main/java/org/apache/ignite/catalog/DefaultZone.java
deleted file mode 100644
index b3591123b7..0000000000
--- a/modules/api/src/main/java/org/apache/ignite/catalog/DefaultZone.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.catalog;
-
-
-import org.apache.ignite.catalog.annotations.Table;
-
-/**
- * Marker interface for {@link Table} annotation.
- */
-public interface DefaultZone {
-}
diff --git 
a/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Table.java 
b/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Table.java
index 18f8a72a01..0650ef0c40 100644
--- a/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Table.java
+++ b/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Table.java
@@ -22,7 +22,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
-import org.apache.ignite.catalog.DefaultZone;
 import org.apache.ignite.catalog.IndexType;
 
 /**
@@ -31,6 +30,11 @@ import org.apache.ignite.catalog.IndexType;
 @Target(TYPE)
 @Retention(RUNTIME)
 public @interface Table {
+    /**
+     * Default zone name.
+     */
+    String DEFAULT_ZONE = "Default";
+
     /**
      * The name of the table. If it's empty, the name of the class annotated 
with this annotation will be used.
      *
@@ -43,7 +47,7 @@ public @interface Table {
      *
      * @return The schema name.
      */
-    String schemaName() default "";
+    String schemaName() default "PUBLIC";
 
     /**
      * Indexes to create on this table.
@@ -71,5 +75,5 @@ public @interface Table {
      *
      * @return Zone description class.
      */
-    Class<?> zone() default DefaultZone.class;
+    Zone zone() default @Zone(value = DEFAULT_ZONE, storageProfiles = "");
 }
diff --git 
a/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Zone.java 
b/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Zone.java
index 939936f0ea..58e6b1e146 100644
--- a/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Zone.java
+++ b/modules/api/src/main/java/org/apache/ignite/catalog/annotations/Zone.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.catalog.annotations;
 
-import static java.lang.annotation.ElementType.TYPE;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
 import java.lang.annotation.Retention;
@@ -26,7 +25,7 @@ import java.lang.annotation.Target;
 /**
  * Describes a distribution zone.
  */
-@Target(TYPE)
+@Target({})
 @Retention(RUNTIME)
 public @interface Zone {
     /**
@@ -34,7 +33,14 @@ public @interface Zone {
      *
      * @return The name of the zone.
      */
-    String value() default "";
+    String value();
+
+    /**
+     * Storage profiles.
+     *
+     * @return Storage profiles.
+     */
+    String storageProfiles();
 
     /**
      * Number of partitions.
@@ -84,11 +90,4 @@ public @interface Zone {
      * @return Nodes filter.
      */
     String filter() default "";
-
-    /**
-     * Storage profiles.
-     *
-     * @return Storage profiles.
-     */
-    String storageProfiles();
 }
diff --git 
a/modules/catalog-dsl/src/integrationTest/java/org/apache/ignite/internal/catalog/ItCatalogDslTest.java
 
b/modules/catalog-dsl/src/integrationTest/java/org/apache/ignite/internal/catalog/ItCatalogDslTest.java
index 58e86ac96a..88dbc19de2 100644
--- 
a/modules/catalog-dsl/src/integrationTest/java/org/apache/ignite/internal/catalog/ItCatalogDslTest.java
+++ 
b/modules/catalog-dsl/src/integrationTest/java/org/apache/ignite/internal/catalog/ItCatalogDslTest.java
@@ -286,10 +286,6 @@ class ItCatalogDslTest extends 
ClusterPerClassIntegrationTest {
         return CLUSTER.node(0).tables();
     }
 
-    @Zone(value = ZONE_NAME, storageProfiles = DEFAULT_AIPERSIST_PROFILE_NAME)
-    private static class ZoneTest {
-    }
-
     private static class PojoKey {
         @Id
         Integer id;
@@ -309,7 +305,10 @@ class ItCatalogDslTest extends 
ClusterPerClassIntegrationTest {
 
     @Table(
             value = POJO_KV_TABLE_NAME,
-            zone = ZoneTest.class,
+            zone = @Zone(
+                    value = ZONE_NAME,
+                    storageProfiles = DEFAULT_AIPERSIST_PROFILE_NAME
+            ),
             colocateBy = @ColumnRef("id"),
             indexes = @Index(value = "ix_pojo", columns = {
                     @ColumnRef("f_name"),
@@ -354,7 +353,6 @@ class ItCatalogDslTest extends 
ClusterPerClassIntegrationTest {
 
     @Table(
             value = POJO_RECORD_TABLE_NAME,
-            zone = ZoneTest.class,
             colocateBy = @ColumnRef("id"),
             indexes = @Index(value = "ix_pojo", columns = {
                     @ColumnRef("f_name"),
diff --git 
a/modules/catalog-dsl/src/main/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsImpl.java
 
b/modules/catalog-dsl/src/main/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsImpl.java
index cda0865ef0..65050b1333 100644
--- 
a/modules/catalog-dsl/src/main/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsImpl.java
+++ 
b/modules/catalog-dsl/src/main/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsImpl.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.catalog.sql;
 
 import static org.apache.ignite.catalog.ColumnSorted.column;
+import static org.apache.ignite.catalog.annotations.Table.DEFAULT_ZONE;
 import static org.apache.ignite.internal.catalog.sql.QueryUtils.mapArrayToList;
 import static org.apache.ignite.table.mapper.Mapper.nativelySupported;
 
@@ -25,9 +26,9 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import org.apache.ignite.catalog.ColumnSorted;
 import org.apache.ignite.catalog.ColumnType;
-import org.apache.ignite.catalog.DefaultZone;
 import org.apache.ignite.catalog.IndexType;
 import org.apache.ignite.catalog.Options;
 import org.apache.ignite.catalog.annotations.Column;
@@ -100,15 +101,12 @@ class CreateFromAnnotationsImpl extends 
AbstractCatalogQuery {
     }
 
     private void processZone(Table table) {
-        Class<?> zoneRef = table.zone();
-        if (zoneRef == DefaultZone.class) {
-            return;
-        }
-        Zone zone = zoneRef.getAnnotation(Zone.class);
-        if (zone != null) {
+        Zone zone = table.zone();
+
+        if (zone != null && !Objects.equals(zone.value(), DEFAULT_ZONE)) {
             createZone = new CreateZoneImpl(sql, options).ifNotExists();
 
-            String zoneName = zone.value().isEmpty() ? zoneRef.getSimpleName() 
: zone.value();
+            String zoneName = zone.value();
             createTable.zone(zoneName);
             createZone.name(zoneName);
             createZone.storageProfiles(zone.storageProfiles());
diff --git 
a/modules/catalog-dsl/src/test/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsTest.java
 
b/modules/catalog-dsl/src/test/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsTest.java
index 1e732b85b8..5b8d593a27 100644
--- 
a/modules/catalog-dsl/src/test/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsTest.java
+++ 
b/modules/catalog-dsl/src/test/java/org/apache/ignite/internal/catalog/sql/CreateFromAnnotationsTest.java
@@ -223,19 +223,6 @@ class CreateFromAnnotationsTest {
         assertThrows(IllegalArgumentException.class, () -> 
createTable().processRecordClass(NoAnnotations.class));
     }
 
-    @Zone(
-            value = "zone_test",
-            partitions = 1,
-            replicas = 3,
-            affinityFunction = "affinity",
-            dataNodesAutoAdjust = 1,
-            dataNodesAutoAdjustScaleDown = 2,
-            dataNodesAutoAdjustScaleUp = 3,
-            filter = "filter",
-            storageProfiles = "default"
-    )
-    private static class ZoneTest {}
-
     @SuppressWarnings("unused")
     private static class PojoKey {
         @Id
@@ -249,7 +236,17 @@ class CreateFromAnnotationsTest {
     @SuppressWarnings("unused")
     @Table(
             value = "pojo_value_test",
-            zone = ZoneTest.class,
+            zone = @Zone(
+                    value = "zone_test",
+                    partitions = 1,
+                    replicas = 3,
+                    affinityFunction = "affinity",
+                    dataNodesAutoAdjust = 1,
+                    dataNodesAutoAdjustScaleDown = 2,
+                    dataNodesAutoAdjustScaleUp = 3,
+                    filter = "filter",
+                    storageProfiles = "default"
+            ),
             colocateBy = {@ColumnRef("id"), @ColumnRef("id_str")},
             indexes = @Index(value = "ix_pojo", columns = {
                     @ColumnRef("f_name"),
@@ -269,7 +266,17 @@ class CreateFromAnnotationsTest {
     @SuppressWarnings("unused")
     @Table(
             value = "pojo_test",
-            zone = ZoneTest.class,
+            zone = @Zone(
+                    value = "zone_test",
+                    partitions = 1,
+                    replicas = 3,
+                    affinityFunction = "affinity",
+                    dataNodesAutoAdjust = 1,
+                    dataNodesAutoAdjustScaleDown = 2,
+                    dataNodesAutoAdjustScaleUp = 3,
+                    filter = "filter",
+                    storageProfiles = "default"
+            ),
             colocateBy = {@ColumnRef("id"), @ColumnRef("id_str")},
             indexes = @Index(value = "ix_pojo", columns = {
                     @ColumnRef("f_name"),
@@ -293,10 +300,7 @@ class CreateFromAnnotationsTest {
         String str;
     }
 
-    @Table(
-            schemaName = "public",
-            indexes = @Index(columns = {@ColumnRef("col1"), 
@ColumnRef("col2")})
-    )
+    @Table(indexes = @Index(columns = {@ColumnRef("col1"), 
@ColumnRef("col2")}))
     private static class NameGeneration {
         Integer col1;
         String col2;

Reply via email to