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;
// Rehashing, other = newer config
other.serverinfo = this.serverinfo;
- other.database = this.database;
}
public String getChannelNamed(String name)
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());
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
{
this.url = url;
this.username = username;
this.password = password;
- this.referenceCount = 1;
this.connect();
this.start();
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...");
}
}
}
-
- public void increaseReferenceCount()
- {
- this.referenceCount++;
- }
private static long lastWarn = 0;
public static void handleException(final String reason, SQLException ex)
}
}
- 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;
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)