mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2025-07-05 06:56:40 +00:00
Implement User Data SQL Handling
This commit is contained in:
@ -27,6 +27,7 @@ import fns.patchwork.data.ConfigRegistry;
|
||||
import fns.patchwork.data.EventRegistry;
|
||||
import fns.patchwork.data.GroupRegistry;
|
||||
import fns.patchwork.data.ModuleRegistry;
|
||||
import fns.patchwork.data.SQLRegistry;
|
||||
import fns.patchwork.data.ServiceTaskRegistry;
|
||||
import fns.patchwork.data.UserRegistry;
|
||||
|
||||
@ -62,6 +63,10 @@ public class Registration
|
||||
* The {@link ConfigRegistry}
|
||||
*/
|
||||
private static final ConfigRegistry configRegistry = new ConfigRegistry();
|
||||
/**
|
||||
* The {@link SQLRegistry}
|
||||
*/
|
||||
private static final SQLRegistry sqlRegistry = new SQLRegistry();
|
||||
|
||||
private Registration()
|
||||
{
|
||||
@ -115,4 +120,12 @@ public class Registration
|
||||
{
|
||||
return configRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link SQLRegistry}
|
||||
*/
|
||||
public static SQLRegistry getSQLRegistry()
|
||||
{
|
||||
return sqlRegistry;
|
||||
}
|
||||
}
|
49
Patchwork/src/main/java/fns/patchwork/data/SQLRegistry.java
Normal file
49
Patchwork/src/main/java/fns/patchwork/data/SQLRegistry.java
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite
|
||||
* Copyright (C) 2023 Total Freedom Server Network and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package fns.patchwork.data;
|
||||
|
||||
import fns.patchwork.sql.SQL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SQLRegistry
|
||||
{
|
||||
private final Map<String, SQL> sqlMapByModule = new HashMap<>();
|
||||
|
||||
public void registerSQL(@NotNull final String serverName, @NotNull final SQL sql)
|
||||
{
|
||||
sqlMapByModule.put(serverName, sql);
|
||||
}
|
||||
|
||||
public void unregisterSQL(@NotNull final String serverName)
|
||||
{
|
||||
sqlMapByModule.remove(serverName);
|
||||
}
|
||||
|
||||
public SQL getSQL(@NotNull final String serverName)
|
||||
{
|
||||
return sqlMapByModule.get(serverName);
|
||||
}
|
||||
}
|
@ -29,6 +29,8 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface SQL
|
||||
{
|
||||
SQLProperties getProperties();
|
||||
|
||||
CompletableFuture<PreparedStatement> prepareStatement(final String query, final Object... args);
|
||||
|
||||
CompletableFuture<ResultSet> executeQuery(final String query, final Object... args);
|
||||
|
@ -28,7 +28,9 @@ import java.util.Properties;
|
||||
|
||||
public interface SQLProperties
|
||||
{
|
||||
Properties getProperties(File propertiesFile);
|
||||
Properties getProperties();
|
||||
|
||||
Properties load(final File propertiesFile);
|
||||
|
||||
default Properties getDefaultProperties()
|
||||
{
|
||||
@ -39,6 +41,7 @@ public interface SQLProperties
|
||||
properties.setProperty("database", "database.db");
|
||||
properties.setProperty("username", "root");
|
||||
properties.setProperty("password", "password");
|
||||
properties.setProperty("serverName", "server");
|
||||
return properties;
|
||||
}
|
||||
|
||||
@ -73,4 +76,6 @@ public interface SQLProperties
|
||||
String getUsername();
|
||||
|
||||
String getPassword();
|
||||
|
||||
String getServerName();
|
||||
}
|
||||
|
Reference in New Issue
Block a user