From b3758a8296174a03dcc7804080f7b78644831431 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 29 Oct 2024 00:29:37 +0900 Subject: [PATCH] Better logging load platform --- ndatabase-api/pom.xml | 2 +- .../com/nivixx/ndatabase/api/NDatabase.java | 4 +- ndatabase-core/pom.xml | 22 ++--- .../core/config/NDatabaseConfig.java | 89 +++++++++++++++++++ ndatabase-dbms-api/pom.xml | 8 +- ndatabase-dbms-core/pom.xml | 10 +-- ndatabase-dbms-jdbc/pom.xml | 6 +- ndatabase-dbms-mariadb/pom.xml | 6 +- ndatabase-dbms-mongodb/pom.xml | 6 +- ndatabase-dbms-mysql/pom.xml | 6 +- ndatabase-dbms-sqlite/pom.xml | 6 +- ndatabase-expressiontree/pom.xml | 4 +- ndatabase-packaging-jar/pom.xml | 10 +-- .../src/main/resources/plugin.yml | 2 +- ndatabase-platforms/app-platform/pom.xml | 8 +- ndatabase-platforms/bukkit-platform/pom.xml | 6 +- .../bukkitplatform/NDatabasePlugin.java | 5 ++ ndatabase-platforms/core-platform/pom.xml | 6 +- ndatabase-platforms/pom.xml | 4 +- ndatabase-tests/pom.xml | 6 +- pom.xml | 2 +- 21 files changed, 156 insertions(+), 62 deletions(-) create mode 100644 ndatabase-core/src/main/java/com/nivixx/ndatabase/core/config/NDatabaseConfig.java diff --git a/ndatabase-api/pom.xml b/ndatabase-api/pom.xml index edc372b..d9cc978 100644 --- a/ndatabase-api/pom.xml +++ b/ndatabase-api/pom.xml @@ -5,7 +5,7 @@ ndatabase com.nivixx - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT 4.0.0 diff --git a/ndatabase-api/src/main/java/com/nivixx/ndatabase/api/NDatabase.java b/ndatabase-api/src/main/java/com/nivixx/ndatabase/api/NDatabase.java index bcb4182..962a46f 100644 --- a/ndatabase-api/src/main/java/com/nivixx/ndatabase/api/NDatabase.java +++ b/ndatabase-api/src/main/java/com/nivixx/ndatabase/api/NDatabase.java @@ -19,14 +19,14 @@ public class NDatabase { public static NDatabaseAPI api() { NDatabaseAPI instance = NDatabase.instance; if (instance == null) { - throw new IllegalStateException("NDatabase has not loaded yet"); + throw new IllegalStateException("NDatabase has not loaded yet. Verify that your plugin configuration include NDatabase in dependencies."); } else { return instance; } } // Note: the NDatabaseAPI instance is set by the core module after loaded - private static void set(NDatabaseAPI nDatabaseAPI) { + static void set(NDatabaseAPI nDatabaseAPI) { Objects.requireNonNull(nDatabaseAPI, "The NDatabase instance is null, probably due to a Google Guice incompatibility issue with java/spigot or other plugin."); instance = nDatabaseAPI; diff --git a/ndatabase-core/pom.xml b/ndatabase-core/pom.xml index faee1b6..f6ccf4c 100644 --- a/ndatabase-core/pom.xml +++ b/ndatabase-core/pom.xml @@ -5,7 +5,7 @@ ndatabase com.nivixx - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT 4.0.0 @@ -20,52 +20,52 @@ com.nivixx ndatabase-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-expressiontree - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-core - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-jdbc - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-mysql - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-sqlite - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-mongodb - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-mariadb - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx core-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-core/src/main/java/com/nivixx/ndatabase/core/config/NDatabaseConfig.java b/ndatabase-core/src/main/java/com/nivixx/ndatabase/core/config/NDatabaseConfig.java new file mode 100644 index 0000000..fdf4598 --- /dev/null +++ b/ndatabase-core/src/main/java/com/nivixx/ndatabase/core/config/NDatabaseConfig.java @@ -0,0 +1,89 @@ +package com.nivixx.ndatabase.core.config; + +import com.nivixx.ndatabase.dbms.mariadb.MariaDBConfig; +import com.nivixx.ndatabase.dbms.mongodb.MongoDBConfig; +import com.nivixx.ndatabase.dbms.mysql.MysqlConfig; +import com.nivixx.ndatabase.dbms.sqlite.SqliteConfig; + +import java.util.Objects; + +public class NDatabaseConfig { + + protected DatabaseType databaseType = DatabaseType.SQLITE; + + protected MariaDBConfig mariaDBConfig; + protected MysqlConfig mysqlConfig; + protected SqliteConfig sqliteConfig; + protected MongoDBConfig mongoDBConfig; + + protected boolean isDebugMode = false; + protected int idleThreadPoolSize = 1; + + public void verifyConfig() { + if(databaseType == null) { + throw new IllegalArgumentException("Database Type not provided in the configuration"); + } + if(databaseType == DatabaseType.MYSQL) { + Objects.requireNonNull(mysqlConfig.getHost(), "mysql host is null, check your mysql configuration"); + Objects.requireNonNull(mysqlConfig.getDatabaseName(), "mysql database name is null, check your mysql configuration"); + Objects.requireNonNull(mysqlConfig.getUser(), "mysql user is null, check your mysql configuration"); + Objects.requireNonNull(mysqlConfig.getPass(), "mysql pass is null, check your mysql configuration"); + } + } + + public MariaDBConfig getMariaDBConfig() { + return mariaDBConfig; + } + + public void setMariaDBConfig(MariaDBConfig mariaDBConfig) { + this.mariaDBConfig = mariaDBConfig; + } + + public MongoDBConfig getMongoDBConfig() { + return mongoDBConfig; + } + + public void setMongoDBConfig(MongoDBConfig mongoDBConfig) { + this.mongoDBConfig = mongoDBConfig; + } + + public boolean isDebugMode() { + return isDebugMode; + } + + public void setDebugMode(boolean debugMode) { + isDebugMode = debugMode; + } + + public DatabaseType getDatabaseType() { + return databaseType; + } + + public void setDatabaseType(DatabaseType databaseType) { + this.databaseType = databaseType; + } + + public MysqlConfig getMysqlConfig() { + return mysqlConfig; + } + + public void setMysqlConfig(MysqlConfig mysqlConfig) { + this.mysqlConfig = mysqlConfig; + } + + public SqliteConfig getSqliteConfig() { + return sqliteConfig; + } + + public void setSqliteConfig(SqliteConfig sqliteConfig) { + this.sqliteConfig = sqliteConfig; + } + + public int getIdleThreadPoolSize() { + return idleThreadPoolSize; + } + + public void setIdleThreadPoolSize(int idleThreadPoolSize) { + this.idleThreadPoolSize = idleThreadPoolSize; + } +} \ No newline at end of file diff --git a/ndatabase-dbms-api/pom.xml b/ndatabase-dbms-api/pom.xml index 0944103..8b4051b 100644 --- a/ndatabase-dbms-api/pom.xml +++ b/ndatabase-dbms-api/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-dbms-api @@ -21,19 +21,19 @@ com.nivixx ndatabase-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-expressiontree - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx core-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-dbms-core/pom.xml b/ndatabase-dbms-core/pom.xml index c44b7ac..768ef05 100644 --- a/ndatabase-dbms-core/pom.xml +++ b/ndatabase-dbms-core/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-dbms-core @@ -21,24 +21,24 @@ com.nivixx ndatabase-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-expressiontree - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx core-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-dbms-jdbc/pom.xml b/ndatabase-dbms-jdbc/pom.xml index d16497f..3e1bb99 100644 --- a/ndatabase-dbms-jdbc/pom.xml +++ b/ndatabase-dbms-jdbc/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-dbms-jdbc @@ -21,13 +21,13 @@ com.nivixx ndatabase-dbms-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-core - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-dbms-mariadb/pom.xml b/ndatabase-dbms-mariadb/pom.xml index e7ed411..ea5b516 100644 --- a/ndatabase-dbms-mariadb/pom.xml +++ b/ndatabase-dbms-mariadb/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-dbms-mariadb @@ -21,13 +21,13 @@ com.nivixx ndatabase-dbms-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-jdbc - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-dbms-mongodb/pom.xml b/ndatabase-dbms-mongodb/pom.xml index 400fba3..ecb3109 100644 --- a/ndatabase-dbms-mongodb/pom.xml +++ b/ndatabase-dbms-mongodb/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-dbms-mongodb @@ -20,13 +20,13 @@ com.nivixx ndatabase-dbms-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-core - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-dbms-mysql/pom.xml b/ndatabase-dbms-mysql/pom.xml index 3f0c74a..8779c29 100644 --- a/ndatabase-dbms-mysql/pom.xml +++ b/ndatabase-dbms-mysql/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-dbms-mysql @@ -21,13 +21,13 @@ com.nivixx ndatabase-dbms-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-jdbc - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-dbms-sqlite/pom.xml b/ndatabase-dbms-sqlite/pom.xml index 94735cc..caba2d0 100644 --- a/ndatabase-dbms-sqlite/pom.xml +++ b/ndatabase-dbms-sqlite/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-dbms-sqlite @@ -22,13 +22,13 @@ com.nivixx ndatabase-dbms-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-dbms-jdbc - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-expressiontree/pom.xml b/ndatabase-expressiontree/pom.xml index 2482a63..5c496db 100644 --- a/ndatabase-expressiontree/pom.xml +++ b/ndatabase-expressiontree/pom.xml @@ -6,7 +6,7 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-expressiontree @@ -21,7 +21,7 @@ com.nivixx ndatabase-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-packaging-jar/pom.xml b/ndatabase-packaging-jar/pom.xml index 8b9a88e..ff6f128 100644 --- a/ndatabase-packaging-jar/pom.xml +++ b/ndatabase-packaging-jar/pom.xml @@ -7,11 +7,11 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT jar ndatabase-packaging-jar - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT @@ -51,17 +51,17 @@ com.nivixx ndatabase-core - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx app-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx bukkit-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-packaging-jar/src/main/resources/plugin.yml b/ndatabase-packaging-jar/src/main/resources/plugin.yml index 042d3d1..486f609 100644 --- a/ndatabase-packaging-jar/src/main/resources/plugin.yml +++ b/ndatabase-packaging-jar/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: NDatabase main: com.nivixx.ndatabase.platforms.bukkitplatform.NDatabasePlugin -version: 1.4.0 +version: 1.4.1 description: A lightweight centralised Key-value style database api-version: 1.13 authors: [NivixX] diff --git a/ndatabase-platforms/app-platform/pom.xml b/ndatabase-platforms/app-platform/pom.xml index 75cf935..a1d6136 100644 --- a/ndatabase-platforms/app-platform/pom.xml +++ b/ndatabase-platforms/app-platform/pom.xml @@ -7,24 +7,24 @@ com.nivixx ndatabase-platforms - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx app-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-core - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-core - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-platforms/bukkit-platform/pom.xml b/ndatabase-platforms/bukkit-platform/pom.xml index 31b4fc1..0210a4e 100644 --- a/ndatabase-platforms/bukkit-platform/pom.xml +++ b/ndatabase-platforms/bukkit-platform/pom.xml @@ -7,11 +7,11 @@ com.nivixx ndatabase-platforms - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT bukkit-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT @@ -23,7 +23,7 @@ com.nivixx ndatabase-core - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-platforms/bukkit-platform/src/main/java/com/nivixx/ndatabase/platforms/bukkitplatform/NDatabasePlugin.java b/ndatabase-platforms/bukkit-platform/src/main/java/com/nivixx/ndatabase/platforms/bukkitplatform/NDatabasePlugin.java index 6a8852f..d558254 100644 --- a/ndatabase-platforms/bukkit-platform/src/main/java/com/nivixx/ndatabase/platforms/bukkitplatform/NDatabasePlugin.java +++ b/ndatabase-platforms/bukkit-platform/src/main/java/com/nivixx/ndatabase/platforms/bukkitplatform/NDatabasePlugin.java @@ -1,10 +1,13 @@ package com.nivixx.ndatabase.platforms.bukkitplatform; +import com.nivixx.ndatabase.api.NDatabase; import com.nivixx.ndatabase.core.PlatformLoader; import com.nivixx.ndatabase.core.config.NDatabaseConfig; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; +import java.util.Objects; + public class NDatabasePlugin extends JavaPlugin { private static NDatabasePlugin instance; @@ -34,6 +37,8 @@ public void onEnable() { ); try { plaformLoader.load(); + Objects.requireNonNull(NDatabase.api(), "NDatabase instance is null after platform load."); + Bukkit.getLogger().info("NDatabase platform (bukkit) has been loaded with success and the api is usable."); } catch (Throwable e) { throw new IllegalStateException("Could not init NDatabase bukkit plugin.", e); } diff --git a/ndatabase-platforms/core-platform/pom.xml b/ndatabase-platforms/core-platform/pom.xml index 18d7933..8cb1f79 100644 --- a/ndatabase-platforms/core-platform/pom.xml +++ b/ndatabase-platforms/core-platform/pom.xml @@ -7,17 +7,17 @@ com.nivixx ndatabase-platforms - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT core-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT com.nivixx ndatabase-api - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT diff --git a/ndatabase-platforms/pom.xml b/ndatabase-platforms/pom.xml index f176eae..2c73a1d 100644 --- a/ndatabase-platforms/pom.xml +++ b/ndatabase-platforms/pom.xml @@ -5,9 +5,9 @@ ndatabase com.nivixx - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT pom 4.0.0 diff --git a/ndatabase-tests/pom.xml b/ndatabase-tests/pom.xml index 4ef31de..e06aa73 100644 --- a/ndatabase-tests/pom.xml +++ b/ndatabase-tests/pom.xml @@ -7,11 +7,11 @@ com.nivixx ndatabase - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT ndatabase-tests - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT @@ -30,7 +30,7 @@ com.nivixx app-platform - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT de.flapdoodle.embed diff --git a/pom.xml b/pom.xml index 3fbed52..62939ab 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.nivixx ndatabase pom - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT