mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Renamed FLATFILE databasetype to YAML
This commit is contained in:
parent
db5ac2d0e5
commit
e8ba1805a5
@ -9,7 +9,7 @@ import java.util.logging.Logger;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||
import world.bentobox.bentobox.database.flatfile.FlatFileDatabase;
|
||||
import world.bentobox.bentobox.database.yaml.YamlDatabase;
|
||||
|
||||
/**
|
||||
* Handy config class to store and load Java POJOs as YAML configs
|
||||
@ -24,12 +24,12 @@ public class Config<T> {
|
||||
|
||||
public Config(BentoBox plugin, Class<T> type) {
|
||||
this.logger = plugin.getLogger();
|
||||
handler = new FlatFileDatabase().getConfig(type);
|
||||
handler = new YamlDatabase().getConfig(type);
|
||||
}
|
||||
|
||||
public Config(Addon addon, Class<T> type) {
|
||||
this.logger = addon.getLogger();
|
||||
handler = new FlatFileDatabase().getConfig(type);
|
||||
handler = new YamlDatabase().getConfig(type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
package world.bentobox.bentobox.database;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.database.flatfile.FlatFileDatabase;
|
||||
import world.bentobox.bentobox.database.yaml.YamlDatabase;
|
||||
import world.bentobox.bentobox.database.json.JSONDatabase;
|
||||
import world.bentobox.bentobox.database.mongodb.MongoDBDatabase;
|
||||
import world.bentobox.bentobox.database.mysql.MySQLDatabase;
|
||||
@ -10,8 +10,8 @@ public interface DatabaseSetup {
|
||||
|
||||
/**
|
||||
* Gets the type of database being used.
|
||||
* Currently supported options are FLATFILE, JSON, MYSQL and MONGODB.
|
||||
* Default is FLATFILE.
|
||||
* Currently supported options are YAML, JSON, MYSQL and MONGODB.
|
||||
* Default is YAML.
|
||||
* @return Database type
|
||||
*/
|
||||
static DatabaseSetup getDatabase() {
|
||||
@ -20,11 +20,11 @@ public interface DatabaseSetup {
|
||||
return type.database;
|
||||
}
|
||||
}
|
||||
return DatabaseType.FLATFILE.database;
|
||||
return DatabaseType.YAML.database;
|
||||
}
|
||||
|
||||
enum DatabaseType {
|
||||
FLATFILE(new FlatFileDatabase()),
|
||||
YAML(new YamlDatabase()),
|
||||
JSON(new JSONDatabase()),
|
||||
MYSQL(new MySQLDatabase()),
|
||||
MONGODB(new MongoDBDatabase());
|
||||
|
@ -1,4 +1,4 @@
|
||||
package world.bentobox.bentobox.database.flatfile;
|
||||
package world.bentobox.bentobox.database.yaml;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -14,7 +14,7 @@ import world.bentobox.bentobox.database.DatabaseConnector;
|
||||
* @param <T> Handles config files for Class <T>
|
||||
*/
|
||||
|
||||
public class ConfigHandler<T> extends FlatFileDatabaseHandler<T> {
|
||||
public class ConfigHandler<T> extends YamlDatabaseHandler<T> {
|
||||
|
||||
public ConfigHandler(BentoBox plugin, Class<T> type, DatabaseConnector databaseConnector) {
|
||||
super(plugin, type, databaseConnector);
|
@ -1,10 +1,10 @@
|
||||
package world.bentobox.bentobox.database.flatfile;
|
||||
package world.bentobox.bentobox.database.yaml;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||
import world.bentobox.bentobox.database.DatabaseSetup;
|
||||
|
||||
public class FlatFileDatabase implements DatabaseSetup {
|
||||
public class YamlDatabase implements DatabaseSetup {
|
||||
|
||||
/**
|
||||
* Get the config
|
||||
@ -13,12 +13,12 @@ public class FlatFileDatabase implements DatabaseSetup {
|
||||
* @return - the config handler
|
||||
*/
|
||||
public <T> AbstractDatabaseHandler<T> getConfig(Class<T> type) {
|
||||
return new ConfigHandler<>(BentoBox.getInstance(), type, new FlatFileDatabaseConnector(BentoBox.getInstance()));
|
||||
return new ConfigHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
||||
return new FlatFileDatabaseHandler<>(BentoBox.getInstance(), type, new FlatFileDatabaseConnector(BentoBox.getInstance()));
|
||||
return new YamlDatabaseHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package world.bentobox.bentobox.database.flatfile;
|
||||
package world.bentobox.bentobox.database.yaml;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -21,7 +21,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.database.DatabaseConnector;
|
||||
|
||||
public class FlatFileDatabaseConnector implements DatabaseConnector {
|
||||
public class YamlDatabaseConnector implements DatabaseConnector {
|
||||
|
||||
private static final int MAX_LOOPS = 100;
|
||||
private static final String DATABASE_FOLDER_NAME = "database";
|
||||
@ -29,7 +29,7 @@ public class FlatFileDatabaseConnector implements DatabaseConnector {
|
||||
private final File dataFolder;
|
||||
|
||||
|
||||
public FlatFileDatabaseConnector(BentoBox plugin) {
|
||||
public YamlDatabaseConnector(BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME);
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class FlatFileDatabaseConnector implements DatabaseConnector {
|
||||
config = new YamlConfiguration();
|
||||
config.load(yamlFile);
|
||||
} catch (Exception e) {
|
||||
plugin.logError("Could not load yaml file from database " + tableName + " " + fileName + " " + e.getMessage());
|
||||
plugin.logError("Could not load yml file from database " + tableName + " " + fileName + " " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
// Create the missing file
|
||||
@ -96,7 +96,7 @@ public class FlatFileDatabaseConnector implements DatabaseConnector {
|
||||
yamlConfig.save(file.toPath().toString());
|
||||
Files.deleteIfExists(tmpFile.toPath());
|
||||
} catch (Exception e) {
|
||||
plugin.logError("Could not save yaml file: " + tableName + " " + fileName + " " + e.getMessage());
|
||||
plugin.logError("Could not save yml file: " + tableName + " " + fileName + " " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
if (commentMap != null && !commentMap.isEmpty()) {
|
@ -1,4 +1,4 @@
|
||||
package world.bentobox.bentobox.database.flatfile;
|
||||
package world.bentobox.bentobox.database.yaml;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.PropertyDescriptor;
|
||||
@ -47,7 +47,7 @@ import world.bentobox.bentobox.util.Util;
|
||||
* @param <T> Handles flat files for Class <T>
|
||||
*/
|
||||
|
||||
public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
|
||||
/**
|
||||
* Flag to indicate if this is a config or a pure object database (difference is in comments and annotations)
|
||||
@ -60,7 +60,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
* @param type - class to store in the database
|
||||
* @param databaseConnector - the database credentials, in this case, just the YAML functions
|
||||
*/
|
||||
FlatFileDatabaseHandler(BentoBox plugin, Class<T> type, DatabaseConnector databaseConnector) {
|
||||
YamlDatabaseHandler(BentoBox plugin, Class<T> type, DatabaseConnector databaseConnector) {
|
||||
super(plugin, type, databaseConnector);
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
key = storeAt.filename();
|
||||
}
|
||||
// Load the YAML file at the location.
|
||||
YamlConfiguration config = ((FlatFileDatabaseConnector)databaseConnector).loadYamlFile(path, key);
|
||||
YamlConfiguration config = ((YamlDatabaseConnector)databaseConnector).loadYamlFile(path, key);
|
||||
// Use the createObject method to turn a YAML config into an Java object
|
||||
return createObject(config);
|
||||
}
|
||||
@ -119,7 +119,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
if (storeAt != null) {
|
||||
fileName = storeAt.filename();
|
||||
}
|
||||
YamlConfiguration config = ((FlatFileDatabaseConnector)databaseConnector).loadYamlFile(DATABASE_FOLDER_NAME + File.separator + dataObject.getSimpleName(), fileName);
|
||||
YamlConfiguration config = ((YamlDatabaseConnector)databaseConnector).loadYamlFile(DATABASE_FOLDER_NAME + File.separator + dataObject.getSimpleName(), fileName);
|
||||
list.add(createObject(config));
|
||||
}
|
||||
return list;
|
||||
@ -243,7 +243,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
} else {
|
||||
// Not a collection. Get the value and rely on YAML to supply it
|
||||
Object value = config.get(storageLocation);
|
||||
// If the value is a yaml MemorySection then something is wrong, so ignore it. Maybe an admin did some bad editing
|
||||
// If the value is a yml MemorySection then something is wrong, so ignore it. Maybe an admin did some bad editing
|
||||
if (value != null && !value.getClass().equals(MemorySection.class)) {
|
||||
method.invoke(instance, deserialize(value,propertyDescriptor.getPropertyType()));
|
||||
}
|
||||
@ -355,7 +355,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
try {
|
||||
config.set(storageLocation, ((AdapterInterface<?,?>)adapterNotation.value().getDeclaredConstructor().newInstance()).serialize(value));
|
||||
} catch (InstantiationException | IllegalArgumentException | NoSuchMethodException | SecurityException e) {
|
||||
plugin.logError("Could not instatiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
|
||||
plugin.logError("Could not instantiate adapter " + adapterNotation.value().getName() + " " + e.getMessage());
|
||||
}
|
||||
// We are done here
|
||||
continue;
|
||||
@ -409,7 +409,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
throw new IllegalArgumentException("No uniqueId in class");
|
||||
}
|
||||
|
||||
((FlatFileDatabaseConnector)databaseConnector).saveYamlFile(config, path, filename, yamlComments);
|
||||
((YamlDatabaseConnector)databaseConnector).saveYamlFile(config, path, filename, yamlComments);
|
||||
}
|
||||
|
||||
private void setComment(ConfigComment comment, YamlConfiguration config, Map<String, String> yamlComments, String parent) {
|
||||
@ -540,7 +540,7 @@ public class FlatFileDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
try {
|
||||
Files.delete(file.toPath());
|
||||
} catch (IOException e) {
|
||||
plugin.logError("Could not delete yaml database object! " + file.getName() + " - " + e.getMessage());
|
||||
plugin.logError("Could not delete yml database object! " + file.getName() + " - " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user