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

feat(sql): Support sql based configuration provider.

This commit is contained in:
2023-12-24 04:52:28 +08:00
parent aa50345329
commit 374f646f9e
14 changed files with 547 additions and 103 deletions
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.LinkedHashMap;
/**
@@ -37,6 +38,16 @@ public class JSONConfigProvider extends FileConfigProvider<JSONConfigWrapper> {
}
public void initializeConfig() {
onReload();
}
@Override
public @NotNull JSONConfigWrapper getConfiguration() {
return this.configuration;
}
@Override
protected void onReload() {
LinkedHashMap<?, ?> map = null;
try (FileInputStream is = new FileInputStream(file)) {
@@ -50,17 +61,6 @@ public class JSONConfigProvider extends FileConfigProvider<JSONConfigWrapper> {
this.configuration = new JSONConfigWrapper(map);
}
@Override
public @NotNull JSONConfigWrapper getConfiguration() {
return this.configuration;
}
@Override
protected void onReload() throws Exception {
super.reload();
initializeConfig();
}
@Override
public @Nullable ConfigurationComments getComments() {
return null;
@@ -68,7 +68,7 @@ public class JSONConfigProvider extends FileConfigProvider<JSONConfigWrapper> {
@Override
public void save() throws Exception {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8)) {
gson.toJson(configuration.data, writer);
}
}