From e4ece2e2f9a757d4310b722f3c2ad5698a4f8821 Mon Sep 17 00:00:00 2001 From: weiping-code Date: Sun, 25 Aug 2024 12:11:29 +0800 Subject: [PATCH] refactor: modify annotation name (#100) Signed-off-by: weiping-code <54316849+weiping-code@users.noreply.github.com> --- .../OpenGeminiReactiveAutoConfiguration.java | 2 +- ...enGeminiReactiveAutoConfigurationTest.java | 11 +------ .../{ => sample}/TestReactiveApplication.java | 2 +- .../OpenGeminiAutoConfigurationTest.java | 2 +- .../data/{ => sample}/TestApplication.java | 2 +- .../measurement/WeatherFixNameNoCreate.java | 30 +++++++++++++++++++ .../{annotations => annotation}/Database.java | 5 +++- .../Column.java => annotation/Field.java} | 8 ++--- .../Measurement.java | 7 +++-- .../data/annotation/MeasurementScan.java | 30 +++++++++++++++++++ .../RetentionPolicy.java | 9 ++++-- .../client/spring/data/annotation/Tag.java | 17 +++++++++++ .../TimeColumn.java => annotation/Time.java} | 4 +-- .../spring/data/annotation/package-info.java | 1 + .../spring/data/annotations/package-info.java | 1 - 15 files changed, 103 insertions(+), 28 deletions(-) rename spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/{ => sample}/TestReactiveApplication.java (86%) rename spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/{ => sample}/TestApplication.java (85%) create mode 100644 spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/sample/measurement/WeatherFixNameNoCreate.java rename spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/{annotations => annotation}/Database.java (66%) rename spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/{annotations/Column.java => annotation/Field.java} (71%) rename spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/{annotations => annotation}/Measurement.java (56%) create mode 100644 spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/MeasurementScan.java rename spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/{annotations => annotation}/RetentionPolicy.java (66%) create mode 100644 spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Tag.java rename spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/{annotations/TimeColumn.java => annotation/Time.java} (80%) create mode 100644 spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/package-info.java delete mode 100644 spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/package-info.java diff --git a/spring/opengemini-spring-boot-starter-reactive/src/main/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfiguration.java b/spring/opengemini-spring-boot-starter-reactive/src/main/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfiguration.java index 45946740..a40e54cb 100644 --- a/spring/opengemini-spring-boot-starter-reactive/src/main/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfiguration.java +++ b/spring/opengemini-spring-boot-starter-reactive/src/main/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfiguration.java @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Bean; import reactor.core.publisher.Flux; -@AutoConfiguration(after = OpenGeminiAutoConfiguration.class) +@AutoConfiguration @ConditionalOnClass({ReactiveOpenGeminiTemplate.class, Flux.class}) public class OpenGeminiReactiveAutoConfiguration { diff --git a/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfigurationTest.java b/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfigurationTest.java index e1ea3730..2fd68bf4 100644 --- a/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfigurationTest.java +++ b/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiReactiveAutoConfigurationTest.java @@ -1,9 +1,8 @@ package io.opengemini.client.spring.data.config; -import io.opengemini.client.spring.data.TestReactiveApplication; import io.opengemini.client.spring.data.core.OpenGeminiProperties; -import io.opengemini.client.spring.data.core.OpenGeminiTemplate; import io.opengemini.client.spring.data.core.ReactiveOpenGeminiTemplate; +import io.opengemini.client.spring.data.sample.TestReactiveApplication; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -17,9 +16,6 @@ public class OpenGeminiReactiveAutoConfigurationTest { @Autowired private OpenGeminiProperties openGeminiProperties; - @Autowired - private OpenGeminiTemplate openGeminiTemplate; - @Autowired private ReactiveOpenGeminiTemplate reactiveOpenGeminiTemplate; @@ -29,11 +25,6 @@ public void properties_bean_should_be_declared() { Assertions.assertEquals("localhost:8086", openGeminiProperties.getAddresses().get(0)); } - @Test - public void template_bean_should_be_declared() { - Assertions.assertNotNull(openGeminiTemplate); - } - @Test public void reactive_template_bean_should_be_declared() { Assertions.assertNotNull(reactiveOpenGeminiTemplate); diff --git a/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/TestReactiveApplication.java b/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/sample/TestReactiveApplication.java similarity index 86% rename from spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/TestReactiveApplication.java rename to spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/sample/TestReactiveApplication.java index b2869df1..b53a313c 100644 --- a/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/TestReactiveApplication.java +++ b/spring/opengemini-spring-boot-starter-reactive/src/test/java/io/opengemini/client/spring/data/sample/TestReactiveApplication.java @@ -1,4 +1,4 @@ -package io.opengemini.client.spring.data; +package io.opengemini.client.spring.data.sample; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiAutoConfigurationTest.java b/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiAutoConfigurationTest.java index 390b76f5..79e64de8 100644 --- a/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiAutoConfigurationTest.java +++ b/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/config/OpenGeminiAutoConfigurationTest.java @@ -1,8 +1,8 @@ package io.opengemini.client.spring.data.config; -import io.opengemini.client.spring.data.TestApplication; import io.opengemini.client.spring.data.core.OpenGeminiProperties; import io.opengemini.client.spring.data.core.OpenGeminiTemplate; +import io.opengemini.client.spring.data.sample.TestApplication; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/TestApplication.java b/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/sample/TestApplication.java similarity index 85% rename from spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/TestApplication.java rename to spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/sample/TestApplication.java index 2db54571..825f026e 100644 --- a/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/TestApplication.java +++ b/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/sample/TestApplication.java @@ -1,4 +1,4 @@ -package io.opengemini.client.spring.data; +package io.opengemini.client.spring.data.sample; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/sample/measurement/WeatherFixNameNoCreate.java b/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/sample/measurement/WeatherFixNameNoCreate.java new file mode 100644 index 00000000..deb43607 --- /dev/null +++ b/spring/opengemini-spring-boot-starter/src/test/java/io/opengemini/client/spring/data/sample/measurement/WeatherFixNameNoCreate.java @@ -0,0 +1,30 @@ +package io.opengemini.client.spring.data.sample.measurement; + + +import io.opengemini.client.api.Precision; +import io.opengemini.client.spring.data.annotation.Database; +import io.opengemini.client.spring.data.annotation.Field; +import io.opengemini.client.spring.data.annotation.Measurement; +import io.opengemini.client.spring.data.annotation.RetentionPolicy; +import io.opengemini.client.spring.data.annotation.Tag; +import io.opengemini.client.spring.data.annotation.Time; +import lombok.Getter; +import lombok.Setter; + +@Database(name = "testdb", create = false) +@RetentionPolicy(name = "testrp", create = false) +@Measurement(name = "testms") +@Getter +@Setter +public class WeatherFixNameNoCreate { + + @Tag(name = "Location") + private String location; + + @Field(name = "Temperature") + private Double temperature; + + @Time(precision = Precision.PRECISIONMILLISECOND) + private Long time; + +} diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Database.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Database.java similarity index 66% rename from spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Database.java rename to spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Database.java index 419fdf9b..054b96fd 100644 --- a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Database.java +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Database.java @@ -1,10 +1,13 @@ -package io.opengemini.client.spring.data.annotations; +package io.opengemini.client.spring.data.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * If unannotated, the method in OpenGeminiTemplate that requires a database name should be used. + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface Database { diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Column.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Field.java similarity index 71% rename from spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Column.java rename to spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Field.java index d310e62f..4553f263 100644 --- a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Column.java +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Field.java @@ -1,4 +1,4 @@ -package io.opengemini.client.spring.data.annotations; +package io.opengemini.client.spring.data.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -7,13 +7,11 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) -public @interface Column { +public @interface Field { /** - * If unset, the annotated field's name will be used as the column name. + * If unset, the annotated field's name will be used as the field name. */ String name(); - boolean tag() default false; - } diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Measurement.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Measurement.java similarity index 56% rename from spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Measurement.java rename to spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Measurement.java index c3c49fd5..68cd7d76 100644 --- a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/Measurement.java +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Measurement.java @@ -1,4 +1,4 @@ -package io.opengemini.client.spring.data.annotations; +package io.opengemini.client.spring.data.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -9,6 +9,9 @@ @Target(ElementType.TYPE) public @interface Measurement { - String name(); + /** + * If unset, the method in OpenGeminiTemplate that requires a measurement name should be used. + */ + String name() default ""; } diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/MeasurementScan.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/MeasurementScan.java new file mode 100644 index 00000000..d0f059dc --- /dev/null +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/MeasurementScan.java @@ -0,0 +1,30 @@ +package io.opengemini.client.spring.data.annotation; + +import org.springframework.core.annotation.AliasFor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface MeasurementScan { + + /** + * Alias for {@link #basePackages}. + *

Allows for more concise annotation declarations if no other attributes + * are needed — for example, {@code @MeasurementScan("org.my.pkg")} + * instead of {@code @MeasurementScan(basePackages = "org.my.pkg")}. + */ + @AliasFor("basePackages") + String[] value() default {}; + + /** + * Base packages to scan for annotated measurements. + *

{@link #value} is an alias for this attribute. + */ + @AliasFor("value") + String[] basePackages() default {}; + +} diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/RetentionPolicy.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/RetentionPolicy.java similarity index 66% rename from spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/RetentionPolicy.java rename to spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/RetentionPolicy.java index 372ab473..3e14a8c0 100644 --- a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/RetentionPolicy.java +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/RetentionPolicy.java @@ -1,9 +1,12 @@ -package io.opengemini.client.spring.data.annotations; +package io.opengemini.client.spring.data.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.Target; +/** + * If unannotated, the method in OpenGeminiTemplate that requires a retention policy name should be used. + */ @Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface RetentionPolicy { @@ -12,9 +15,9 @@ boolean create() default true; - String duration(); + String duration() default ""; - String shardGroupDuration(); + String shardGroupDuration() default ""; String hotDuration() default ""; diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Tag.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Tag.java new file mode 100644 index 00000000..ecfae699 --- /dev/null +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Tag.java @@ -0,0 +1,17 @@ +package io.opengemini.client.spring.data.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Tag { + + /** + * If unset, the annotated field's name will be used as the tag name. + */ + String name(); + +} diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/TimeColumn.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Time.java similarity index 80% rename from spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/TimeColumn.java rename to spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Time.java index c96fdd59..d0021008 100644 --- a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/TimeColumn.java +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/Time.java @@ -1,4 +1,4 @@ -package io.opengemini.client.spring.data.annotations; +package io.opengemini.client.spring.data.annotation; import io.opengemini.client.api.Precision; @@ -9,7 +9,7 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) -public @interface TimeColumn { +public @interface Time { Precision precision() default Precision.PRECISIONMILLISECOND; diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/package-info.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/package-info.java new file mode 100644 index 00000000..e9fe8403 --- /dev/null +++ b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotation/package-info.java @@ -0,0 +1 @@ +package io.opengemini.client.spring.data.annotation; diff --git a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/package-info.java b/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/package-info.java deleted file mode 100644 index 648527b1..00000000 --- a/spring/opengemini-spring/src/main/java/io/opengemini/client/spring/data/annotations/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package io.opengemini.client.spring.data.annotations;