]> WPIA git - gigi.git/blob - src/org/cacert/gigi/CertificateProfile.java
d2e6b27784344aba482a749648236c7d456e6389
[gigi.git] / src / org / cacert / gigi / CertificateProfile.java
1 package org.cacert.gigi;
2
3 import java.sql.PreparedStatement;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
6 import java.util.HashMap;
7
8 import org.cacert.gigi.database.DatabaseConnection;
9
10 public class CertificateProfile {
11
12     final int id;
13
14     final String keyName;
15
16     final String visibleName;
17
18     static HashMap<String, CertificateProfile> byName = new HashMap<>();
19
20     static HashMap<Integer, CertificateProfile> byId = new HashMap<>();
21
22     private CertificateProfile(int id, String keyName, String visibleName) {
23         this.id = id;
24         this.keyName = keyName;
25         this.visibleName = visibleName;
26     }
27
28     public int getId() {
29         return id;
30     }
31
32     public String getKeyName() {
33         return keyName;
34     }
35
36     public String getVisibleName() {
37         return visibleName;
38     }
39
40     static {
41         try {
42             PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT id, keyname, name FROM `profiles`");
43             ResultSet rs = ps.executeQuery();
44             while (rs.next()) {
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);
48             }
49         } catch (SQLException e) {
50             e.printStackTrace();
51         }
52
53     }
54
55     public static CertificateProfile getById(int id) {
56         return byId.get(id);
57     }
58
59     public static CertificateProfile getByName(String name) {
60         return byName.get(name);
61     }
62
63 }