aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java
diff options
context:
space:
mode:
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java123
1 files changed, 123 insertions, 0 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java
new file mode 100644
index 00000000..b0f957a5
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/authmodule_eIDASv2/DAO/eIDASPersonalIdStoreDAO.java
@@ -0,0 +1,123 @@
+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;
+
+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<Pair<String, T>> TABLE_COLS;
+ static {
+ List<Pair<String, T>> cols = new ArrayList<Pair<String, T>>();
+ 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<Pair<String, T>> cols) {
+ String sql = "";
+
+ for (Pair<String, T> 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<Pair<String, T>> cols) {
+ String sql = "";
+
+ for (Pair<String, T> 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<Pair<String, T>> cols) {
+ String sql = "";
+
+ for (Pair<String, T> el : cols) {
+ sql += "?,";
+
+ }
+
+ return sql.substring(0, sql.length()-1);
+ }
+
+}