X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FDatabaseConnection.java;h=abeb78d0d765d7888af97e79a8bd1550e65a869e;hb=91bfb697cacaf050e772472f20efea8988acf04a;hp=389a82cfe84bb43fbe1b0a1b8ac39448389778e0;hpb=943d8e7ed0ea5a9d56e7e694a3cbd849c52bad16;p=gigi.git diff --git a/src/org/cacert/gigi/database/DatabaseConnection.java b/src/org/cacert/gigi/database/DatabaseConnection.java index 389a82cf..abeb78d0 100644 --- a/src/org/cacert/gigi/database/DatabaseConnection.java +++ b/src/org/cacert/gigi/database/DatabaseConnection.java @@ -5,21 +5,21 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Statement; import java.util.HashMap; import java.util.Properties; -import java.sql.Statement; public class DatabaseConnection { public static final int CONNECTION_TIMEOUT = 24 * 60 * 60; - Connection c; + private Connection c; - HashMap statements = new HashMap(); + private HashMap statements = new HashMap(); private static Properties credentials; - Statement adHoc; + private Statement adHoc; public DatabaseConnection() { try { @@ -44,17 +44,21 @@ public class DatabaseConnection { } } - public PreparedStatement prepare(String query) throws SQLException { + public GigiPreparedStatement prepare(String query) { ensureOpen(); - PreparedStatement statement = statements.get(query); + GigiPreparedStatement statement = statements.get(query); if (statement == null) { - statement = c.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); + try { + statement = new GigiPreparedStatement(c.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)); + } catch (SQLException e) { + throw new Error(e); + } statements.put(query, statement); } return statement; } - long lastAction = System.currentTimeMillis(); + private long lastAction = System.currentTimeMillis(); private void ensureOpen() { if (System.currentTimeMillis() - lastAction > CONNECTION_TIMEOUT * 1000L) { @@ -71,15 +75,7 @@ public class DatabaseConnection { lastAction = System.currentTimeMillis(); } - public static int lastInsertId(PreparedStatement query) throws SQLException { - ResultSet rs = query.getGeneratedKeys(); - rs.next(); - int id = rs.getInt(1); - rs.close(); - return id; - } - - static ThreadLocal instances = new ThreadLocal() { + private static ThreadLocal instances = new ThreadLocal() { @Override protected DatabaseConnection initialValue() {