]> jfr.im git - irc/rizon/acid.git/commitdiff
Remove strange sql refcounting, allow reloading database connections
authorAdam <redacted>
Wed, 24 Sep 2014 03:54:46 +0000 (23:54 -0400)
committerAdam <redacted>
Wed, 24 Sep 2014 03:54:46 +0000 (23:54 -0400)
acid/src/main/java/net/rizon/acid/conf/Config.java
acid/src/main/java/net/rizon/acid/core/Acidictive.java
acid/src/main/java/net/rizon/acid/sql/SQL.java

index 082c4ae4bfb13b7f1447a4e098eae7a344dbe524..4b21c6b04dff19075895ba170dd858430c4a3186 100644 (file)
@@ -1,12 +1,12 @@
 package net.rizon.acid.conf;
 
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor;
+
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.List;
 
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor;
-
 public class Config extends Configuration
 {
        public boolean debug, protocol_debug;
@@ -40,7 +40,6 @@ public class Config extends Configuration
                // Rehashing, other = newer config
                
                other.serverinfo = this.serverinfo;
-               other.database = this.database;
        }
        
        public String getChannelNamed(String name)
index b6069b255b197367402679e9be5d955ac9f23a09..0e5a7d61a16b16bed2d2f0aa6155b6dd2d382fd2 100644 (file)
@@ -99,6 +99,8 @@ public class Acidictive extends AcidCore
                        System.exit(-1);
                }
 
+               acidcore_sql.shutdown();
+
                System.exit(0);
        }
 
index be374eb443361d00fa26f5789a81fb9c8cb9ba7f..701901274f1fecb870c01c00a528bd22cd4f2924 100644 (file)
@@ -1,18 +1,17 @@
 package net.rizon.acid.sql;
 
+import net.rizon.acid.conf.Database;
+import net.rizon.acid.core.Acidictive;
+import net.rizon.acid.core.Logger;
+
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.logging.Level;
 
-import net.rizon.acid.conf.Database;
-import net.rizon.acid.core.Acidictive;
-import net.rizon.acid.core.Logger;
-
 public class SQL extends Thread
 {
        private static final Logger log = Logger.getLogger(SQL.class.getName());
@@ -24,8 +23,6 @@ public class SQL extends Thread
        private long last_connect = 0;
        private volatile Object queryLock = new Object();
        private volatile LinkedList<PreparedStatement> pendingQueries = new LinkedList<PreparedStatement>();
-       private static final HashMap<String, SQL> connections = new HashMap<String, SQL>();
-       private int referenceCount;
 
        public SQL(final String url, final String username, final String password) throws ClassNotFoundException, SQLException
        {
@@ -34,7 +31,6 @@ public class SQL extends Thread
                this.url = url;
                this.username = username;
                this.password = password;
-               this.referenceCount = 1;
 
                this.connect();
                this.start();
@@ -53,10 +49,6 @@ public class SQL extends Thread
 
        public void shutdown()
        {
-               if (--this.referenceCount > 0)
-                       /* Another plugin still needs the connection here */
-                       return;
-               
                this.shuttingDown = true;
 
                log.log(Level.INFO, "Flushing pending SQL queries...");
@@ -211,11 +203,6 @@ public class SQL extends Thread
                        }
                }
        }
-       
-       public void increaseReferenceCount()
-       {
-               this.referenceCount++;
-       }
 
        private static long lastWarn = 0;
        public static void handleException(final String reason, SQLException ex)
@@ -228,14 +215,6 @@ public class SQL extends Thread
                }
        }
        
-       public static void shutdownAllConnections()
-       {
-               for (final SQL conn : SQL.connections.values())
-                       conn.shutdown();
-               
-               SQL.connections.clear();
-       }
-       
        public static SQL getConnection(final String name)
        {
                SQL sql = null;
@@ -247,15 +226,7 @@ public class SQL extends Thread
                                if (!d.name.equals(name))
                                        continue;
                                
-                               if (SQL.connections.containsKey(name))
-                               {
-                                       sql = SQL.connections.get(name);
-                                       sql.increaseReferenceCount();
-                                       return sql;
-                               }
-                               
-                               sql = new SQL(d.host, d.user, d.pass);
-                               SQL.connections.put(d.name, sql);
+                               return sql = new SQL(d.host, d.user, d.pass);
                        }
                }
                catch (ClassNotFoundException ex)