From 76c7d79a71550633d4a36a5e60280bd1a1c34a52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Sun, 8 Nov 2015 12:50:12 +0100 Subject: [PATCH] upd: cleanup in Certificate class --- .../cacert/gigi/dbObjects/Certificate.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/org/cacert/gigi/dbObjects/Certificate.java b/src/org/cacert/gigi/dbObjects/Certificate.java index 7512712d..f15a299b 100644 --- a/src/org/cacert/gigi/dbObjects/Certificate.java +++ b/src/org/cacert/gigi/dbObjects/Certificate.java @@ -354,26 +354,21 @@ public class Certificate implements IdCachable { if (serial == null || "".equals(serial)) { return null; } - try { - String concat = "string_agg(concat('/', `name`, '=', REPLACE(REPLACE(value, '\\\\', '\\\\\\\\'), '/', '\\\\/')), '')"; - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT certs.id, " + concat + " as `subject`, `md`, `csr_name`, `crt_name`,`memid`, `profile`, `certs`.`serial` FROM `certs` LEFT JOIN `certAvas` ON `certAvas`.`certId`=`certs`.`id` WHERE `serial`=? GROUP BY `certs`.`id`"); - ps.setString(1, serial); - GigiResultSet rs = ps.executeQuery(); - if ( !rs.next()) { - return null; - } - int id = rs.getInt(1); - Certificate c1 = cache.get(id); - if (c1 != null) { - return c1; - } - Certificate certificate = new Certificate(rs); - cache.put(certificate); - return certificate; - } catch (IllegalArgumentException e) { - + String concat = "string_agg(concat('/', `name`, '=', REPLACE(REPLACE(value, '\\\\', '\\\\\\\\'), '/', '\\\\/')), '')"; + GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT certs.id, " + concat + " as `subject`, `md`, `csr_name`, `crt_name`,`memid`, `profile`, `certs`.`serial` FROM `certs` LEFT JOIN `certAvas` ON `certAvas`.`certId`=`certs`.`id` WHERE `serial`=? GROUP BY `certs`.`id`"); + ps.setString(1, serial); + GigiResultSet rs = ps.executeQuery(); + if ( !rs.next()) { + return null; } - return null; + int id = rs.getInt(1); + Certificate c1 = cache.get(id); + if (c1 != null) { + return c1; + } + Certificate certificate = new Certificate(rs); + cache.put(certificate); + return certificate; } private static ObjectCache cache = new ObjectCache<>(); -- 2.39.2