+ 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) {
+
+ }
+ return null;
+ }
+
+ private static ObjectCache<Certificate> cache = new ObjectCache<>();
+
+ public synchronized static Certificate getById(int id) {
+ Certificate cacheRes = cache.get(id);
+ if (cacheRes != null) {
+ return cacheRes;
+ }
+
+ 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 certs.id=? GROUP BY certs.id");
+ ps.setInt(1, id);
+ GigiResultSet rs = ps.executeQuery();
+ if ( !rs.next()) {
+ return null;
+ }
+
+ Certificate c = new Certificate(rs);
+ cache.put(c);
+ return c;