package at.asitplus.eidas.specific.modules.authmodule_eIDASv2.DAO; import java.util.ArrayList; import java.util.Collections; import java.util.List; import at.gv.egiz.eaaf.core.impl.data.Pair; @Deprecated public class eIDASPersonalIdStoreDAO { public static final String NAME = "foreigneIDMap"; //Enum with all cols of this table public enum COLS { timestamp, transactionId, eidasId, eidasSourceCountry, eidasDestinationCountry, ernbId } public enum T { ID("INTEGER"), BIGINT("VARCHAR(265)"), URI("VARCHAR(256)"), DATE("Long"), TEXT("TEXT"), Long("BIGINT"), Int("INTEGER"), BLOB("BLOB"), CC("CHAR(2)"), BOOL("INTEGER"); public String s_; private T(String s) { s_ = s; } @Override public String toString() { return s_; } } //define Cols of the table public static final List> TABLE_COLS; static { List> cols = new ArrayList>(); cols.add(Pair.newInstance(COLS.timestamp.name(), T.DATE)); cols.add(Pair.newInstance(COLS.transactionId.name(), T.TEXT)); cols.add(Pair.newInstance(COLS.eidasId.name(), T.TEXT)); cols.add(Pair.newInstance(COLS.eidasSourceCountry.name(), T.CC)); cols.add(Pair.newInstance(COLS.eidasDestinationCountry.name(), T.CC)); cols.add(Pair.newInstance(COLS.ernbId.name(), T.TEXT)); TABLE_COLS = Collections.unmodifiableList(cols); } public static final String CREATE = "CREATE TABLE " + NAME + " (" + "id" + " " + T.ID.toString() + " PRIMARY KEY AUTOINCREMENT, " + buildCreateTableQuery(TABLE_COLS) + ")"; public static final String INSERT = "INSERT INTO " + NAME + "(" + buildInsertQueryKeys(TABLE_COLS) + ")" + " VALUES (" + buildInsertQueryValues(TABLE_COLS) + ");"; public static final String SELECT_BY_ERNB_ID = "SELECT * FROM " + NAME + " WHERE " + COLS.ernbId.name() + "=?;"; public static final String SELECT_BY_EIDAS_RAW_ID = "SELECT * FROM " + NAME + " WHERE " + COLS.eidasId.name() + "=?" + " and " + COLS.eidasSourceCountry.name() + "=?" + ";"; /** * Build a part of a SQL query, which contains the cols of a table that should be created * * @param cols List of DB col definitions {@link Pair} * @return Part of a SQL query, which contains cols that should be created */ private static String buildCreateTableQuery(List> cols) { String sql = ""; for (Pair el : cols) { sql += el.getFirst() + " " + el.getSecond().toString() + ","; } return sql.substring(0, sql.length()-1); } /** * Build a part of a SQL query, which contains the cols keys of a table for insert operation * * @param cols List of DB col definitions {@link Pair} * @return Part of a SQL query, which contains cols that should be created */ protected static String buildInsertQueryKeys(List> cols) { String sql = ""; for (Pair el : cols) { sql += el.getFirst() + ","; } return sql.substring(0, sql.length()-1); } /** * Build a part of a SQL query, which contains the cols values of a table for insert operation * * @param cols List of DB col definitions {@link Pair} * @return Part of a SQL query, which contains cols that should be created */ protected static String buildInsertQueryValues(List> cols) { String sql = ""; for (Pair el : cols) { sql += "?,"; } return sql.substring(0, sql.length()-1); } }