mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 10:38:19 +08:00
style: Reformatted code with .editorconfig
This commit is contained in:
+48
-15
@@ -1,8 +1,16 @@
|
||||
# configured-SQL
|
||||
|
||||
SQL database implementation, support for MySQL or MariaDB.
|
||||
SQL
|
||||
database
|
||||
implementation,
|
||||
support
|
||||
for
|
||||
MySQL
|
||||
or
|
||||
MariaDB.
|
||||
|
||||
## Table schema
|
||||
|
||||
```mysql
|
||||
CREATE TABLE IF NOT EXISTS conf
|
||||
(
|
||||
@@ -16,9 +24,11 @@ CREATE TABLE IF NOT EXISTS conf
|
||||
`version` MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, # 配置项的版本
|
||||
`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;
|
||||
PRIMARY KEY (`namespace`,
|
||||
`path`)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4;
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
@@ -32,16 +42,30 @@ CREATE TABLE IF NOT EXISTS conf
|
||||
|
||||
<repository>
|
||||
<!-- Using Maven Central Repository for secure and stable updates, though synchronization might be needed. -->
|
||||
<id>maven</id>
|
||||
<name>Maven Central</name>
|
||||
<url>https://repo1.maven.org/maven2</url>
|
||||
<id>
|
||||
maven
|
||||
</id>
|
||||
<name>
|
||||
Maven
|
||||
Central
|
||||
</name>
|
||||
<url>
|
||||
https://repo1.maven.org/maven2
|
||||
</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<!-- Using GitHub dependencies for real-time updates, configuration required (recommended). -->
|
||||
<id>configured</id>
|
||||
<name>GitHub Packages</name>
|
||||
<url>https://maven.pkg.github.com/CarmJos/configured</url>
|
||||
<id>
|
||||
configured
|
||||
</id>
|
||||
<name>
|
||||
GitHub
|
||||
Packages
|
||||
</name>
|
||||
<url>
|
||||
https://maven.pkg.github.com/CarmJos/configured
|
||||
</url>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
@@ -53,10 +77,19 @@ CREATE TABLE IF NOT EXISTS conf
|
||||
<project>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>configured-sql</artifactId>
|
||||
<version>[LATEST RELEASE]</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>
|
||||
cc.carm.lib
|
||||
</groupId>
|
||||
<artifactId>
|
||||
configured-sql
|
||||
</artifactId>
|
||||
<version>
|
||||
[LATEST
|
||||
RELEASE]
|
||||
</version>
|
||||
<scope>
|
||||
compile
|
||||
</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -80,4 +113,4 @@ repositories {
|
||||
dependencies {
|
||||
api "cc.carm.lib:configured-sql:[LATEST RELEASE]"
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
@@ -81,4 +81,4 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
+9
-9
@@ -32,7 +32,7 @@ public class SQLConfigFactory extends ConfigurationFactory<SQLSource, Configurat
|
||||
}
|
||||
|
||||
protected static final @NotNull Gson DEFAULT_GSON = new GsonBuilder()
|
||||
.serializeNulls().disableHtmlEscaping().create();
|
||||
.serializeNulls().disableHtmlEscaping().create();
|
||||
|
||||
protected static final @NotNull BiConsumer<String, TableCreateBuilder> DEFAULT_TABLE_SCHEMA = (tableName, builder) -> {
|
||||
builder.addColumn("namespace", "VARCHAR(32) NOT NULL");
|
||||
@@ -48,17 +48,17 @@ public class SQLConfigFactory extends ConfigurationFactory<SQLSource, Configurat
|
||||
builder.addColumn("version", "MEDIUMINT UNSIGNED NOT NULL DEFAULT 0");
|
||||
|
||||
builder.addColumn(
|
||||
"create_time",
|
||||
"TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"
|
||||
"create_time",
|
||||
"TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"
|
||||
);
|
||||
builder.addColumn(
|
||||
"update_time",
|
||||
"TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
|
||||
"update_time",
|
||||
"TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
|
||||
);
|
||||
|
||||
builder.setIndex(
|
||||
IndexType.PRIMARY_KEY, "pk_" + tableName.toLowerCase(),
|
||||
"namespace", "path"
|
||||
IndexType.PRIMARY_KEY, "pk_" + tableName.toLowerCase(),
|
||||
"namespace", "path"
|
||||
);
|
||||
builder.setTableSettings("ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
|
||||
};
|
||||
@@ -163,8 +163,8 @@ public class SQLConfigFactory extends ConfigurationFactory<SQLSource, Configurat
|
||||
|
||||
return new ConfigurationHolder<SQLSource>(this.adapters, this.options, this.metadata, this.initializer) {
|
||||
final SQLSource source = new SQLSource(
|
||||
this, System.currentTimeMillis(),
|
||||
gson, manager, resolvers, tableName, namespace
|
||||
this, System.currentTimeMillis(),
|
||||
gson, manager, resolvers, tableName, namespace
|
||||
);
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,6 @@ public interface SQLOptions {
|
||||
/**
|
||||
* Whether to purge the configuration's in-database data when saving.
|
||||
*/
|
||||
ConfigurationOption<Boolean> PURGE = ConfigurationOption.of( true);
|
||||
ConfigurationOption<Boolean> PURGE = ConfigurationOption.of(true);
|
||||
|
||||
}
|
||||
|
||||
@@ -104,10 +104,10 @@ public class SQLSource extends ConfigureSource<SourcedSection, Map<String, Objec
|
||||
|
||||
int version = holder().metadata(path).get(VersionedMetaTypes.VERSION, 0);
|
||||
dataValues.add(new Object[]{
|
||||
namespace, path, time, version, typeID, data,
|
||||
Commentable.getInlineComment(holder(), path),
|
||||
gson.toJson(Commentable.getHeaderComments(holder(), path)),
|
||||
gson.toJson(Commentable.getFooterComments(holder(), path))
|
||||
namespace, path, time, version, typeID, data,
|
||||
Commentable.getInlineComment(holder(), path),
|
||||
gson.toJson(Commentable.getHeaderComments(holder(), path)),
|
||||
gson.toJson(Commentable.getFooterComments(holder(), path))
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -118,18 +118,18 @@ public class SQLSource extends ConfigureSource<SourcedSection, Map<String, Objec
|
||||
purge();
|
||||
}
|
||||
this.table.createReplaceBatch()
|
||||
.setColumnNames(
|
||||
"namespace", "path", "update_time", "version", "type", "value",
|
||||
"inline_comment", "header_comments", "footer_comments"
|
||||
).setAllParams(dataValues).execute();
|
||||
.setColumnNames(
|
||||
"namespace", "path", "update_time", "version", "type", "value",
|
||||
"inline_comment", "header_comments", "footer_comments"
|
||||
).setAllParams(dataValues).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onReload() throws Exception {
|
||||
Map<String, Object> loaded = new LinkedHashMap<>();
|
||||
try (SQLQuery query = this.table.createQuery()
|
||||
.addCondition("namespace", namespace)
|
||||
.build().execute()) {
|
||||
.addCondition("namespace", namespace)
|
||||
.build().execute()) {
|
||||
ResultSet rs = query.getResultSet();
|
||||
while (rs.next()) {
|
||||
String path = rs.getString("path");
|
||||
@@ -161,9 +161,9 @@ public class SQLSource extends ConfigureSource<SourcedSection, Map<String, Objec
|
||||
|
||||
protected int typeIdOf(@NotNull Object value) {
|
||||
return this.resolvers.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().isInstance(value))
|
||||
.findFirst().map(Map.Entry::getKey)
|
||||
.orElseThrow(() -> new IllegalStateException("No resolvers for value " + value.getClass().getName()));
|
||||
.filter(entry -> entry.getValue().isInstance(value))
|
||||
.findFirst().map(Map.Entry::getKey)
|
||||
.orElseThrow(() -> new IllegalStateException("No resolvers for value " + value.getClass().getName()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user