aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'mdbc-server/src/main')
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java4
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java29
2 files changed, 25 insertions, 8 deletions
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java b/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java
index fd8651a..8ca8517 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java
@@ -123,9 +123,9 @@ public class MdbcTestClient {
}
try {
- //execute = insertStmt.execute(insertSQL);
+ execute = insertStmt.execute(insertSQL);
execute = insertStmt.execute(insertSQL1);
- //execute = insertStmt.execute(insertSQL2);
+ execute = insertStmt.execute(insertSQL2);
//execute = insertStmt.execute(insertSQL3);
//execute = insertStmt.execute(insertSQL4);
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java
index 0afacea..aecee24 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java
@@ -346,10 +346,10 @@ NEW.field refers to the new value
.append("'").append(col).append("', ")
.append(isdelete ? "OLD." : "NEW.")
.append(col);
- if (isupdate && (ti.iskey(col) || !ti.hasKey())) {
+ if (!isdelete && (ti.iskey(col) || !ti.hasKey())) {
keyJson.append(kfx)
.append("'").append(col).append("', ")
- .append("OLD.")
+ .append(isupdate ? "OLD." : "NEW.")
.append(col);
kfx = ", ";
}
@@ -373,7 +373,7 @@ NEW.field refers to the new value
.append("', ")
.append(isdelete ? "'D'" : (op.equals("INSERT") ? "'I'" : "'U'"))
.append(", ")
- .append(isupdate ? keyJson.toString() : "NULL")
+ .append(!isdelete ? keyJson.toString() : "NULL")
.append(", ")
.append(newJson.toString())
.append(", ")
@@ -904,21 +904,38 @@ NEW.field refers to the new value
buildAndExecuteSQLInverse(jdbcStmt, op, cols, vals);
}
} catch (SQLException sqlE) {
- // This applies only for replaying transactions involving Eventually Consistent tables
- logger.warn("Error Replaying operation: " + sql.toString() + "; Replacing insert/replace/viceversa and replaying ");
+ // This applies for replaying transactions involving Eventually Consistent tables
+ // or transactions that replay on top of existing keys
+ logger.warn("Error Replaying operation: " + sql.toString() + ";"
+ + "Replacing insert/replace/viceversa and replaying ");
buildAndExecuteSQLInverse(jdbcStmt, op, cols, vals);
}
}
+
protected void buildAndExecuteSQLInverse(Statement jdbcStmt, Operation op,
ArrayList<String> cols, ArrayList<Object> vals) throws SQLException, MDBCServiceException {
- StringBuilder sqlInverse = constructSQLInverse( op, cols, vals);
+ StringBuilder sqlInverse = constructSQLInverse(op, cols, vals);
if(sqlInverse == null)
return;
logger.info("Replaying operation: " + sqlInverse.toString());
jdbcStmt.executeUpdate(sqlInverse.toString());
}
+
+ /**
+ * Construct an update statement from an insert, or
+ * construct an insert statement from an update
+ *
+ * useful when replaying logic, if the primary key value is already present/not present
+ *
+ * @param op
+ * @param cols
+ * @param vals
+ * @return
+ * @throws MDBCServiceException
+ */
+
protected StringBuilder constructSQLInverse(Operation op, ArrayList<String> cols,
ArrayList<Object> vals) throws MDBCServiceException {
StringBuilder sqlInverse = null;