1 package org.cacert.gigi.dbObjects;
3 import java.sql.PreparedStatement;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
6 import java.util.HashMap;
8 import org.cacert.gigi.database.DatabaseConnection;
10 public class CertificateProfile {
14 private final String keyName;
16 private final String visibleName;
18 private static HashMap<String, CertificateProfile> byName = new HashMap<>();
20 private static HashMap<Integer, CertificateProfile> byId = new HashMap<>();
22 private CertificateProfile(int id, String keyName, String visibleName) {
24 this.keyName = keyName;
25 this.visibleName = visibleName;
32 public String getKeyName() {
36 public String getVisibleName() {
42 PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id, keyname, name FROM `profiles`");
43 ResultSet rs = ps.executeQuery();
45 CertificateProfile cp = new CertificateProfile(rs.getInt("id"), rs.getString("keyName"), rs.getString("name"));
46 byId.put(cp.getId(), cp);
47 byName.put(cp.getKeyName(), cp);
49 } catch (SQLException e) {
55 public static CertificateProfile getById(int id) {
59 public static CertificateProfile getByName(String name) {
60 return byName.get(name);