1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2026-06-04 18:48:20 +08:00

feat(map): 支持通过ConfigurationSection创建MapValue。

This commit is contained in:
2023-08-28 17:00:56 +08:00
parent c6cce5208f
commit 27a68ead7c
17 changed files with 404 additions and 208 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>cc.carm.lib</groupId>
<artifactId>easyconfiguration-parent</artifactId>
<version>3.7.2</version>
<version>3.8.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<properties>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>3.7.2</version>
<version>3.8.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>3.7.2</version>
<version>3.8.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
+9 -9
View File
@@ -1,14 +1,14 @@
CREATE TABLE IF NOT EXISTS conf
(
`namespace` VARCHAR(255) NOT NULL, #
`section` VARCHAR(255) NOT NULL, # (ConfigPath)
`type` VARCHAR(255) NOT NULL, # (Integer/Byte/List/Map/...)
`value` MEDIUMTEXT, # (JSON格式)
`inline_comments` TINYTEXT, #
`header_comments` TEXT, #
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`namespace`, `section`)
`namespace` VARCHAR(255) NOT NULL, #
`path` VARCHAR(255) NOT NULL, # (ConfigPath)
`type` TINYINT UNSIGNED NOT NULL DEFAULT 0, # (Integer/Byte/List/Map/...)
`value` MEDIUMTEXT, # (JSON格式)
`inline_comments` TEXT, #
`header_comments` MEDIUMTEXT, #
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, #
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`namespace`, `path`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4;
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<artifactId>easyconfiguration-parent</artifactId>
<groupId>cc.carm.lib</groupId>
<version>3.7.2</version>
<version>3.8.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -42,6 +42,8 @@ public class DemoConfigTest {
if (anyModel != null) System.out.println(anyModel.getName());
ModelConfiguration.MODELS.forEach(System.out::println);
ModelConfiguration.MODEL_MAP.forEach((v, anyModel1) -> System.out.println(v + " -> " + anyModel1.toString()));
System.out.println("----------------------------------------------------");
}
@@ -5,13 +5,13 @@ import cc.carm.lib.configuration.core.annotation.ConfigPath;
import cc.carm.lib.configuration.core.annotation.HeaderComment;
import cc.carm.lib.configuration.core.value.ConfigValue;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.configuration.core.value.type.ConfiguredMap;
import cc.carm.lib.configuration.core.value.type.ConfiguredSectionMap;
import cc.carm.lib.configuration.demo.tests.model.AbstractModel;
import cc.carm.lib.configuration.yaml.value.ConfiguredSerializable;
import config.model.AnyModel;
import config.model.SomeModel;
import java.util.Map;
@HeaderComment("以下内容用于测试序列化")
@ConfigPath("model-test")
public class ModelConfiguration extends ConfigurationRoot {
@@ -25,10 +25,19 @@ public class ModelConfiguration extends ConfigurationRoot {
);
public static final ConfiguredList<AnyModel> MODELS = ConfiguredList.builderOf(AnyModel.class)
.fromObject()
.parseValue((section) -> AnyModel.deserialize((Map<String, ?>) section))
.serializeValue(AnyModel::serialize)
.fromMap()
.parseValue(AnyModel::deserialize).serializeValue(AnyModel::serialize)
.defaults(AnyModel.random(), AnyModel.random(), AnyModel.random())
.build();
public static final ConfiguredSectionMap<String, AnyModel> MODEL_MAP = ConfiguredMap.builderOf(String.class, AnyModel.class)
.asLinkedMap().fromSection()
.parseValue(v -> new AnyModel(v.getString("name", "EMPTY"), v.getBoolean("state", false)))
.serializeValue(AnyModel::serialize)
.defaults(m -> {
m.put("a", AnyModel.random());
m.put("b", AnyModel.random());
})
.build();
}