Skip to content

Commit

Permalink
Bugfix in Importer class with duplicate entities and attributes from …
Browse files Browse the repository at this point in the history
…DNA 2
  • Loading branch information
leifeld committed Feb 4, 2024
1 parent 38eac00 commit 8118bf9
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions dna/src/main/java/gui/Importer.java
Expand Up @@ -918,6 +918,19 @@ public void run() {
}
documentSelectSql = documentSelectSql + ");";

String d17sql = "";
String d20sql = "";
if (Dna.sql.getConnectionProfile().getType().equals("sqlite")) {
d17sql = "INSERT OR IGNORE INTO ATTRIBUTEVALUES (EntityId, AttributeVariableId, AttributeValue) VALUES (?, ?, ?);";
d20sql = "INSERT OR IGNORE INTO ENTITIES (VariableId, Value, Red, Green, Blue) VALUES (?, ?, ?, ?, ?);";
} else if (Dna.sql.getConnectionProfile().getType().equals("mysql")) {
d17sql = "INSERT IGNORE INTO ATTRIBUTEVALUES (EntityId, AttributeVariableId, AttributeValue) VALUES (?, ?, ?);";
d20sql = "INSERT IGNORE INTO ENTITIES (VariableId, Value, Red, Green, Blue) VALUES (?, ?, ?, ?, ?);";
} else if (Dna.sql.getConnectionProfile().getType().equals("postgresql")) {
d17sql = "INSERT INTO ATTRIBUTEVALUES (EntityId, AttributeVariableId, AttributeValue) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE EntityId = VALUES(EntityId), AttributeVariableId = VALUES(AttributeVariableId);";
d20sql = "INSERT INTO ENTITIES (VariableId, Value, Red, Green, Blue) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE VariableId = VALUES(VariableId), Value = VALUES(Value);";
}

try (Connection connForeign = Importer.this.sql.getDataSource().getConnection();
Connection connDomestic = Dna.sql.getDataSource().getConnection();
PreparedStatement d1 = connDomestic.prepareStatement("INSERT INTO DOCUMENTS (Title, Text, Coder, Author, Source, Section, Notes, Type, Date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);", PreparedStatement.RETURN_GENERATED_KEYS);
Expand All @@ -944,10 +957,10 @@ public void run() {
PreparedStatement d15 = connDomestic.prepareStatement("INSERT INTO DATASHORTTEXT (StatementId, VariableId, Entity) VALUES (?, ?, ?);");
PreparedStatement f15 = connForeign.prepareStatement("SELECT COUNT(ID) FROM STATEMENTS WHERE DocumentId = ?;");
PreparedStatement d16 = connDomestic.prepareStatement("INSERT INTO ATTRIBUTEVARIABLES (VariableId, AttributeVariable) VALUES (?, ?);", PreparedStatement.RETURN_GENERATED_KEYS);
PreparedStatement d17 = connDomestic.prepareStatement("INSERT INTO ATTRIBUTEVALUES (EntityId, AttributeVariableId, AttributeValue) VALUES (?, ?, ?);");
PreparedStatement d17 = connDomestic.prepareStatement(d17sql);
PreparedStatement d18 = connDomestic.prepareStatement("SELECT * FROM ATTRIBUTEVARIABLES WHERE VariableId = ?;");
PreparedStatement d19 = connDomestic.prepareStatement("SELECT ID FROM ATTRIBUTEVARIABLES WHERE VariableId = ? AND AttributeVariable = ?;");
PreparedStatement d20 = connDomestic.prepareStatement("INSERT INTO ENTITIES (VariableId, Value, Red, Green, Blue) VALUES (?, ?, ?, ?, ?);", PreparedStatement.RETURN_GENERATED_KEYS);
PreparedStatement d20 = connDomestic.prepareStatement(d20sql, PreparedStatement.RETURN_GENERATED_KEYS);
PreparedStatement d21 = connDomestic.prepareStatement("SELECT ID FROM ENTITIES WHERE VariableId = ? AND Value = ?;");
PreparedStatement d22 = connDomestic.prepareStatement("UPDATE ATTRIBUTEVALUES SET AttributeValue = ? WHERE EntityId = ? AND AttributeVariableId = ?;");
PreparedStatement d23 = connDomestic.prepareStatement("SELECT AttributeValue FROM ATTRIBUTEVALUES WHERE EntityId = ? AND AttributeVariableId = ?;");
Expand Down Expand Up @@ -1262,10 +1275,10 @@ public void run() {
int entityId = -1;
while (keySetEntity.next()) {
entityId = keySetEntity.getInt(1);
entityMap.put(r2.getInt("ID"), entityId); // may not be valid with DNA 2.0 because there is no entity ID; works only with version 3
entityCount++;
}
keySetEntity.close();
entityMap.put(r2.getInt("ID"), entityId); // may not be valid with DNA 2.0 because there is no entity ID; works only with version 3
entityCount++;
}

// import attributes for DNA 2.0 here already because they are part of ResultSet r2 anyway
Expand Down Expand Up @@ -1426,9 +1439,9 @@ public void run() {
int entityId = -1;
while (keySetEntity.next()) {
entityId = keySetEntity.getInt(1);
entityMap.put(r2.getInt("ID"), entityId); // may not be valid with DNA 2.0 because there is no entity ID
entityCount++;
}
entityMap.put(r2.getInt("ID"), entityId); // may not be valid with DNA 2.0 because there is no entity ID
entityCount++;
}

// import attributes for DNA 2.0 here already because they are part of ResultSet r2 anyway
Expand Down

0 comments on commit 8118bf9

Please sign in to comment.