X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fdatabase%2FDatabaseConnection.java;h=abeb78d0d765d7888af97e79a8bd1550e65a869e;hb=91bfb697cacaf050e772472f20efea8988acf04a;hp=21d701cb4bc4048589fcd845040e5660a405912d;hpb=fb38a9c8b9d86289213a36bd3d2afddc58ec7d3f;p=gigi.git diff --git a/src/org/cacert/gigi/database/DatabaseConnection.java b/src/org/cacert/gigi/database/DatabaseConnection.java index 21d701cb..abeb78d0 100644 --- a/src/org/cacert/gigi/database/DatabaseConnection.java +++ b/src/org/cacert/gigi/database/DatabaseConnection.java @@ -15,7 +15,7 @@ public class DatabaseConnection { private Connection c; - private HashMap statements = new HashMap(); + private HashMap statements = new HashMap(); private static Properties credentials; @@ -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 instances = new ThreadLocal() { @Override