X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FdbObjects%2FName.java;h=df9e1ff6f19660005f115cd63b23624bba06697b;hb=c9ed09f0007fc2c813815be927a5a24b23dab83c;hp=f9099cec596e7e880cbfe5b73609e60844cd707a;hpb=9def69bd08ea69eb27786d5b34f00e154e09e9f3;p=gigi.git diff --git a/src/org/cacert/gigi/dbObjects/Name.java b/src/org/cacert/gigi/dbObjects/Name.java index f9099cec..df9e1ff6 100644 --- a/src/org/cacert/gigi/dbObjects/Name.java +++ b/src/org/cacert/gigi/dbObjects/Name.java @@ -4,6 +4,7 @@ import java.io.PrintWriter; import java.util.Map; import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.database.DBEnum; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.dbObjects.NamePart.NamePartType; @@ -13,6 +14,16 @@ import org.cacert.gigi.util.HTMLEncoder; public class Name implements Outputable, IdCachable { + public static enum NameSchemaType implements DBEnum { + SINGLE, WESTERN; + + @Override + public String getDBName() { + return toString().toLowerCase(); + } + + } + private abstract static class SchemedName { /** @@ -27,7 +38,7 @@ public class Name implements Outputable, IdCachable { */ public abstract String toAbbreviatedString(); - public abstract String getSchemeName(); + public abstract NameSchemaType getSchemeName(); /** * @see Name#output(PrintWriter, Language, Map) @@ -60,13 +71,13 @@ public class Name implements Outputable, IdCachable { } @Override - public String getSchemeName() { - return "single"; + public NameSchemaType getSchemeName() { + return NameSchemaType.SINGLE; } @Override public void output(PrintWriter out) { - out.println(""); + out.print(""); out.print(HTMLEncoder.encodeHTML(singlePart.getValue())); out.println(""); } @@ -201,8 +212,8 @@ public class Name implements Outputable, IdCachable { } @Override - public String getSchemeName() { - return "western"; + public NameSchemaType getSchemeName() { + return NameSchemaType.WESTERN; } @Override @@ -226,7 +237,7 @@ public class Name implements Outputable, IdCachable { private SchemedName scheme; /** - * This name should not get assured anymore and therefore not be displayed + * This name should not get verifed anymore and therefore not be displayed * to the RA-Agent. This state is irrevocable. */ private boolean deprecated; @@ -260,7 +271,7 @@ public class Name implements Outputable, IdCachable { } try (GigiPreparedStatement inserter = new GigiPreparedStatement("INSERT INTO `names` SET `uid`=?, `type`=?::`nameSchemaType`")) { inserter.setInt(1, u.getId()); - inserter.setString(2, scheme.getSchemeName()); + inserter.setEnum(2, scheme.getSchemeName()); inserter.execute(); id = inserter.lastInsertId(); } @@ -268,7 +279,7 @@ public class Name implements Outputable, IdCachable { inserter.setInt(1, id); for (int i = 0; i < np.length; i++) { inserter.setInt(2, i); - inserter.setString(3, np[i].getType().getDbValue()); + inserter.setEnum(3, np[i].getType()); inserter.setString(4, np[i].getValue()); inserter.execute(); } @@ -374,7 +385,7 @@ public class Name implements Outputable, IdCachable { } public int getAssurancePoints() { - try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(`points`) FROM (SELECT DISTINCT ON (`from`) `points` FROM `notary` WHERE `to`=? AND `deleted` IS NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) ORDER BY `from`, `when` DESC) AS p")) { + try (GigiPreparedStatement query = new GigiPreparedStatement("SELECT SUM(`points`) FROM (SELECT DISTINCT ON (`from`, `method`) `points` FROM `notary` WHERE `to`=? AND `deleted` IS NULL AND (`expire` IS NULL OR `expire` > CURRENT_TIMESTAMP) ORDER BY `from`, `method`, `when` DESC) AS p")) { query.setInt(1, getId()); GigiResultSet rs = query.executeQuery();