mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 10:38:19 +08:00
feat(sql): Support SQL sources
This commit is contained in:
@@ -33,6 +33,19 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easyconfiguration-feature-versioned</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyconfiguration-feature-versioned</artifactId>
|
||||
<version>4.0.8</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -25,6 +25,7 @@ public interface DatabaseConfiguration extends Configuration {
|
||||
ConfigValue<String> DATABASE = ConfiguredValue.of(String.class, "minecraft");
|
||||
ConfigValue<String> USERNAME = ConfiguredValue.of(String.class, "root");
|
||||
ConfigValue<String> PASSWORD = ConfiguredValue.of(String.class, "password");
|
||||
|
||||
ConfigValue<String> EXTRA = ConfiguredValue.of(String.class, "?useSSL=false");
|
||||
|
||||
static String buildJDBC() {
|
||||
|
||||
@@ -69,14 +69,14 @@ public class ConfigurationTest {
|
||||
provider.initialize(TEST);
|
||||
|
||||
System.out.println("> Test Inner value before:");
|
||||
System.out.println(TEST.INSTANCE.INNER_VALUE.resolve());
|
||||
System.out.println(TEST.INSTANCE.STATUS.resolve());
|
||||
|
||||
double after = Math.random() * 200D;
|
||||
System.out.println("> Test Inner value -> " + after);
|
||||
TEST.INSTANCE.INNER_VALUE.set(after);
|
||||
TEST.INSTANCE.STATUS.set(after);
|
||||
|
||||
System.out.println("> Test Inner value after:");
|
||||
System.out.println(TEST.INSTANCE.INNER_VALUE.resolve());
|
||||
System.out.println(TEST.INSTANCE.STATUS.resolve());
|
||||
|
||||
}
|
||||
|
||||
|
||||
+3
-10
@@ -1,11 +1,7 @@
|
||||
package cc.carm.lib.configuration.demo.tests.conf;
|
||||
|
||||
import cc.carm.lib.configuration.Configuration;
|
||||
import cc.carm.lib.configuration.annotation.ConfigPath;
|
||||
import cc.carm.lib.configuration.annotation.FooterComments;
|
||||
import cc.carm.lib.configuration.annotation.HeaderComments;
|
||||
import cc.carm.lib.configuration.annotation.InlineComment;
|
||||
import cc.carm.lib.configuration.demo.DatabaseConfiguration;
|
||||
import cc.carm.lib.configuration.annotation.*;
|
||||
import cc.carm.lib.configuration.demo.tests.model.ItemStack;
|
||||
import cc.carm.lib.configuration.demo.tests.model.UserRecord;
|
||||
import cc.carm.lib.configuration.value.ConfigValue;
|
||||
@@ -29,7 +25,8 @@ import java.util.UUID;
|
||||
public interface DemoConfiguration extends Configuration {
|
||||
|
||||
@ConfigPath(root = true)
|
||||
ConfigValue<Double> VERSION = ConfiguredValue.of(Double.class, 1.0D);
|
||||
@ConfigVersion(2)
|
||||
ConfigValue<Double> VERSION = ConfiguredValue.of(Double.class, 2.0D);
|
||||
|
||||
@ConfigPath(root = true)
|
||||
@FooterComments({"此处内容将显示在配置条目的下方", "可用于补充说明,但一般不建议使用"})
|
||||
@@ -39,10 +36,6 @@ public interface DemoConfiguration extends Configuration {
|
||||
@FooterComments({"上述的枚举内容本质上是通过STRING解析的"})
|
||||
ConfigValue<ChronoUnit> TEST_ENUM = ConfiguredValue.of(ChronoUnit.class, ChronoUnit.DAYS);
|
||||
|
||||
// 支持通过 Class<?> 变量标注子配置,一并注册。
|
||||
// 注意: 若对应类也有注解,则优先使用类的注解。
|
||||
Class<?> DATABASE = DatabaseConfiguration.class;
|
||||
|
||||
@ConfigPath("registered_users") // 通过注解规定配置文件中的路径,若不进行注解则以变量名自动生成。
|
||||
@HeaderComments({"Section类型数据测试"}) // 通过注解给配置添加注释。
|
||||
@InlineComment("默认地注释会加到Section的首行末尾") // 通过注解给配置添加注释。
|
||||
|
||||
@@ -8,6 +8,6 @@ import cc.carm.lib.configuration.value.standard.ConfiguredValue;
|
||||
@HeaderComments("Inner Test")
|
||||
public class InstanceConfig implements Configuration {
|
||||
|
||||
public final ConfigValue<Double> INNER_VALUE = ConfiguredValue.of(1.0D);
|
||||
public final ConfigValue<Double> STATUS = ConfiguredValue.of(1.0D);
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class RegistryConfig implements Configuration {
|
||||
@FooterComments({"12313213212"})
|
||||
@InlineComment(value = "用户名(匹配注释)", regex = "name") // 通过注解给配置添加注释。
|
||||
@InlineComment(value = "信息", regex = {"info.*", "info.game.*"}) // 通过注解给配置添加注释。
|
||||
public final ConfigValue<UserRecord> TEST_MODEL = ConfiguredValue.builderOf(UserRecord.class).fromSection()
|
||||
public final ConfigValue<UserRecord> OWNER = ConfiguredValue.builderOf(UserRecord.class).fromSection()
|
||||
.defaults(new UserRecord("Carm", UUID.randomUUID()))
|
||||
.parse((holder, section) -> UserRecord.deserialize(section))
|
||||
.serialize((holder, data) -> data.serialize()).build();
|
||||
|
||||
Reference in New Issue
Block a user