]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/database/DatabaseConnection.java
inopiae-dob: replaced some magic numbers by constants
[gigi.git] / src / org / cacert / gigi / database / DatabaseConnection.java
index 2552ed90e2ef3abe5ac65d585f76476cec694dfe..c85b5348d6e253c2dd96d1219723b9913751db23 100644 (file)
@@ -48,7 +48,7 @@ public class DatabaseConnection {
 
         }
 
-        public PreparedStatement getTarget() {
+        public synchronized PreparedStatement getTarget() {
             return target;
         }
 
@@ -99,7 +99,7 @@ public class DatabaseConnection {
 
     }
 
-    public static final int CURRENT_SCHEMA_VERSION = 6;
+    public static final int CURRENT_SCHEMA_VERSION = 9;
 
     public static final int CONNECTION_TIMEOUT = 24 * 60 * 60;
 
@@ -183,15 +183,11 @@ public class DatabaseConnection {
         lastAction = System.currentTimeMillis();
     }
 
-    private static DatabaseConnection instance;
+    private static volatile DatabaseConnection instance;
 
-    public static DatabaseConnection getInstance() {
+    public static synchronized DatabaseConnection getInstance() {
         if (instance == null) {
-            synchronized (DatabaseConnection.class) {
-                if (instance == null) {
-                    instance = new DatabaseConnection();
-                }
-            }
+            instance = new DatabaseConnection();
         }
         return instance;
     }
@@ -221,10 +217,6 @@ public class DatabaseConnection {
         upgrade(version);
     }
 
-    public void beginTransaction() throws SQLException {
-        c.setAutoCommit(false);
-    }
-
     private static void upgrade(int version) {
         try {
             Statement s = getInstance().c.createStatement();
@@ -252,22 +244,6 @@ public class DatabaseConnection {
         }
     }
 
-    public void commitTransaction() throws SQLException {
-        c.commit();
-        c.setAutoCommit(true);
-    }
-
-    public void quitTransaction() {
-        try {
-            if ( !c.getAutoCommit()) {
-                c.rollback();
-                c.setAutoCommit(true);
-            }
-        } catch (SQLException e) {
-            e.printStackTrace();
-        }
-    }
-
     public static final String preprocessQuery(String originalQuery) {
         originalQuery = originalQuery.replace('`', '"');
         if (originalQuery.matches("^INSERT INTO [^ ]+ SET .*")) {
@@ -313,7 +289,7 @@ public class DatabaseConnection {
         return underUse.size();
     }
 
-    public void lockedStatements(PrintWriter writer) {
+    public synchronized void lockedStatements(PrintWriter writer) {
         writer.println(underUse.size());
         for (PreparedStatement ps : underUse) {
             for (Entry<StatementDescriptor, PreparedStatement> e : statements.entrySet()) {