33import com .bencodez .simpleapi .file .velocity .VelocityYMLFile ;
44import com .bencodez .simpleapi .sql .mysql .DbType ;
55
6+ import ninja .leaping .configurate .ConfigurationNode ;
7+
68public class MysqlConfigVelocity extends MysqlConfig {
79
810 public MysqlConfigVelocity (String prePath , VelocityYMLFile config ) {
@@ -15,54 +17,65 @@ public MysqlConfigVelocity(VelocityYMLFile config) {
1517
1618 private void load (String prePath , VelocityYMLFile config ) {
1719 // --- Basic Table Info ---
18- setTablePrefix (config .getString (config . getNode ( prePath , "Prefix" ), "" ));
19- String name = config .getString (config . getNode ( prePath , "Name" ), "" );
20+ setTablePrefix (config .getString (node ( config , prePath , "Prefix" ), "" ));
21+ String name = config .getString (node ( config , prePath , "Name" ), "" );
2022 if (name != null && !name .isEmpty ()) {
2123 setTableName (name );
2224 }
2325
2426 // --- Connection Info ---
25- setHostName (config .getString (config . getNode ( prePath , "Host" ), "" ));
26- setPort (config .getInt (config . getNode ( prePath , "Port" ), 0 ));
27- setUser (config .getString (config . getNode ( prePath , "Username" ), "" ));
28- setPass (config .getString (config . getNode ( prePath , "Password" ), "" ));
29- setDatabase (config .getString (config . getNode ( prePath , "Database" ), "" ));
27+ setHostName (config .getString (node ( config , prePath , "Host" ), "" ));
28+ setPort (config .getInt (node ( config , prePath , "Port" ), 0 ));
29+ setUser (config .getString (node ( config , prePath , "Username" ), "" ));
30+ setPass (config .getString (node ( config , prePath , "Password" ), "" ));
31+ setDatabase (config .getString (node ( config , prePath , "Database" ), "" ));
3032
3133 // --- Pool Settings ---
32- setLifeTime (config .getLong (config . getNode ( prePath , "MaxLifeTime" ), -1 ));
33- setMaxThreads (config .getInt (config . getNode ( prePath , "MaxConnections" ), 1 ));
34+ setLifeTime (config .getLong (node ( config , prePath , "MaxLifeTime" ), -1 ));
35+ setMaxThreads (config .getInt (node ( config , prePath , "MaxConnections" ), 1 ));
3436 if (getMaxThreads () < 1 ) {
3537 setMaxThreads (1 );
3638 }
3739
3840 // Recommended tuning defaults
39- setMinimumIdle (config .getInt (config . getNode ( prePath , "MinimumIdle" ), 2 )); // 2
40- setIdleTimeoutMs (config .getLong (config . getNode ( prePath , "IdleTimeoutMs" ), 10 * 60_000L )); // 10 min
41- setKeepaliveMs (config .getLong (config . getNode ( prePath , "KeepaliveMs" ), 5 * 60_000L )); // 5 min
42- setValidationMs (config .getLong (config . getNode ( prePath , "ValidationMs" ), 5_000L )); // 5 s
43- setLeakDetectMs (config .getLong (config . getNode ( prePath , "LeakDetectMs" ), 20_000L )); // 20 s
44- setConnectionTimeout (config .getInt (config . getNode ( prePath , "ConnectionTimeout" ), 50_000 )); // 50 s
41+ setMinimumIdle (config .getInt (node ( config , prePath , "MinimumIdle" ), 2 )); // 2
42+ setIdleTimeoutMs (config .getLong (node ( config , prePath , "IdleTimeoutMs" ), 10 * 60_000L )); // 10 min
43+ setKeepaliveMs (config .getLong (node ( config , prePath , "KeepaliveMs" ), 5 * 60_000L )); // 5 min
44+ setValidationMs (config .getLong (node ( config , prePath , "ValidationMs" ), 5_000L )); // 5 s
45+ setLeakDetectMs (config .getLong (node ( config , prePath , "LeakDetectMs" ), 20_000L )); // 20 s
46+ setConnectionTimeout (config .getInt (node ( config , prePath , "ConnectionTimeout" ), 50_000 )); // 50 s
4547
4648 // --- Driver / DB Selection ---
47- String dbTypeStr = config .getString (config . getNode ( prePath , "DbType" ), "" );
49+ String dbTypeStr = config .getString (node ( config , prePath , "DbType" ), "" );
4850 if (dbTypeStr != null && !dbTypeStr .isEmpty ()) {
4951 setDbType (DbType .fromString (dbTypeStr ));
5052 } else {
51- boolean maria = config .getBoolean (config . getNode ( prePath , "UseMariaDB" ), false );
53+ boolean maria = config .getBoolean (node ( config , prePath , "UseMariaDB" ), false );
5254 setDbType (maria ? DbType .MARIADB : DbType .MYSQL );
5355 }
5456
5557 // Optional explicit JDBC driver override
56- setDriver (config .getString (config . getNode ( prePath , "Driver" ), "" ));
58+ setDriver (config .getString (node ( config , prePath , "Driver" ), "" ));
5759
5860 // --- Driver / Behavior Options ---
59- setUseSSL (config .getBoolean (config . getNode ( prePath , "UseSSL" ), false ));
60- setPublicKeyRetrieval (config .getBoolean (config . getNode ( prePath , "PublicKeyRetrieval" ), false ));
61- setUseMariaDB (config .getBoolean (config . getNode ( prePath , "UseMariaDB" ), false ));
61+ setUseSSL (config .getBoolean (node ( config , prePath , "UseSSL" ), false ));
62+ setPublicKeyRetrieval (config .getBoolean (node ( config , prePath , "PublicKeyRetrieval" ), false ));
63+ setUseMariaDB (config .getBoolean (node ( config , prePath , "UseMariaDB" ), false ));
6264
6365 // --- Additional Settings ---
64- setLine (config .getString (config .getNode (prePath , "Line" ), "" ));
65- setDebug (config .getBoolean (config .getNode (prePath , "Debug" ), false ));
66- setPoolName (config .getString (config .getNode (prePath , "PoolName" ), "" ));
66+ setLine (config .getString (node (config , prePath , "Line" ), "" ));
67+ setDebug (config .getBoolean (node (config , prePath , "Debug" ), false ));
68+ setPoolName (config .getString (node (config , prePath , "PoolName" ), "" ));
69+ }
70+
71+ /**
72+ * Returns a valid config node. - If prePath is empty/null -> root-level key -
73+ * Otherwise -> prePath.key
74+ */
75+ private ConfigurationNode node (VelocityYMLFile config , String prePath , String key ) {
76+ if (prePath == null || prePath .isEmpty ()) {
77+ return config .getNode (key );
78+ }
79+ return config .getNode (prePath , key );
6780 }
6881}
0 commit comments