mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-05 02:58:20 +08:00
feat(sql): Try to implement sql source
This commit is contained in:
+1
-2
@@ -1,6 +1,5 @@
|
||||
package cc.carm.lib.configuration.annotation;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -22,7 +21,7 @@ public @interface ConfigVersion {
|
||||
*
|
||||
* @return the version of the configuration field
|
||||
*/
|
||||
@Range(from = 0, to = Integer.MAX_VALUE)
|
||||
@Range(from = 0, to = 65535)
|
||||
int value() default 0;
|
||||
|
||||
}
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package cc.carm.lib.configuration.option;
|
||||
|
||||
import cc.carm.lib.configuration.source.option.ConfigurationOption;
|
||||
|
||||
public interface VersionedOptions {
|
||||
|
||||
/**
|
||||
* Whether to set newer defaults when a {@link cc.carm.lib.configuration.value.ConfigValue}'s marked version
|
||||
* is newer than the current in storage.
|
||||
*/
|
||||
ConfigurationOption<Boolean> RESET_NEWER_DEFAULTS = ConfigurationOption.of(true);
|
||||
|
||||
}
|
||||
+13
-2
@@ -1,4 +1,4 @@
|
||||
package cc.carm.lib.configuration.commentable;
|
||||
package cc.carm.lib.configuration.versioned;
|
||||
|
||||
import cc.carm.lib.configuration.annotation.ConfigVersion;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
@@ -19,7 +19,18 @@ public interface VersionedMetaTypes {
|
||||
}
|
||||
|
||||
static void register(@NotNull ConfigurationInitializer initializer) {
|
||||
initializer.registerFieldAnnotation(ConfigVersion.class, VERSION, ConfigVersion::value);
|
||||
initializer.appendFieldInitializer((holder, path, field, value) -> {
|
||||
ConfigVersion annotation = field.getAnnotation(ConfigVersion.class);
|
||||
if (annotation == null || value == null) return;
|
||||
int currentVersion = annotation.value();
|
||||
int savedVersion = holder.metadata(path).get(VERSION, 0);
|
||||
if (currentVersion == savedVersion) return;
|
||||
|
||||
if (currentVersion > savedVersion) { // This values updated.
|
||||
value.setDefault(true); // Mark as default value, force write.
|
||||
}
|
||||
holder.metadata(path).set(VERSION, currentVersion);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user