1 package org.cacert.gigi.dbObjects;
3 import java.sql.Timestamp;
5 import java.util.HashMap;
7 import org.cacert.gigi.database.GigiPreparedStatement;
8 import org.cacert.gigi.database.GigiResultSet;
12 private static HashMap<String, Integer> names = new HashMap<>();
14 public static final String ASSURER_CHALLANGE_NAME = "Assurer's Challange";
16 public static final int ASSURER_CHALLANGE_ID;
23 try (GigiPreparedStatement st = new GigiPreparedStatement("SELECT `id`, `type_text` FROM `cats_type`")) {
24 GigiResultSet res = st.executeQuery();
26 names.put(res.getString(2), res.getInt(1));
29 ASSURER_CHALLANGE_ID = getID(ASSURER_CHALLANGE_NAME);
32 public static synchronized int getID(String name) {
33 Integer i = names.get(name);
35 try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `cats_type` SET `type_text`=?")) {
36 ps.setString(1, name);
38 i = ps.lastInsertId();
45 public static void enterResult(User user, String testType, Date passDate) {
46 try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `cats_passed` SET `user_id`=?, `variant_id`=?, `pass_date`=?")) {
47 ps.setInt(1, user.getId());
48 ps.setInt(2, getID(testType));
49 ps.setTimestamp(3, new Timestamp(passDate.getTime()));