]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/database/DatabaseConnection.java
Merge branch 'felix-work'
[gigi.git] / src / org / cacert / gigi / database / DatabaseConnection.java
index 21d701cb4bc4048589fcd845040e5660a405912d..661565d843a0a3f1b428a8f114d6c92cfc34129f 100644 (file)
@@ -15,7 +15,7 @@ public class DatabaseConnection {
 
     private Connection c;
 
-    private HashMap<String, PreparedStatement> statements = new HashMap<String, PreparedStatement>();
+    private HashMap<String, GigiPreparedStatement> statements = new HashMap<String, GigiPreparedStatement>();
 
     private static Properties credentials;
 
@@ -34,7 +34,7 @@ public class DatabaseConnection {
     private void tryConnect() {
         try {
             c = DriverManager.getConnection(credentials.getProperty("sql.url") + "?zeroDateTimeBehavior=convertToNull", credentials.getProperty("sql.user"), credentials.getProperty("sql.password"));
-            PreparedStatement ps = c.prepareStatement("SET SESSION wait_timeout=?;");
+            PreparedStatement ps = c.prepareStatement("SET SESSION wait_timeout=?, time_zone='+0:00';");
             ps.setInt(1, CONNECTION_TIMEOUT);
             ps.execute();
             ps.close();
@@ -44,11 +44,15 @@ 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;
@@ -71,14 +75,6 @@ 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;
-    }
-
     private static ThreadLocal<DatabaseConnection> instances = new ThreadLocal<DatabaseConnection>() {
 
         @Override