Add primary key for delete in tx replay 42/83642/1
authorArthur Martella <arthur.martella.1@att.com>
Thu, 28 Mar 2019 18:00:03 +0000 (14:00 -0400)
committerArthur Martella <arthur.martella.1@att.com>
Thu, 28 Mar 2019 18:00:03 +0000 (14:00 -0400)
Change-Id: Ic8a2e8c311dd657fbdb5936568bc8d168458d3b2
Issue-ID: MUSIC-371
Signed-off-by: Arthur Martella <arthur.martella.1@att.com>
mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java

index 820817b..338839a 100755 (executable)
@@ -344,6 +344,7 @@ NEW.field refers to the new value
 */
        private String generateTrigger(String tableName, String op) {
                boolean isdelete = op.equals("DELETE");
+               boolean isinsert = op.equals("INSERT");
                boolean isupdate = op.equals("UPDATE");
                TableInfo ti = getTableInfo(tableName);
                StringBuilder newJson = new StringBuilder("JSON_OBJECT(");              // JSON_OBJECT(key, val, key, val) page 1766
@@ -355,10 +356,10 @@ NEW.field refers to the new value
                        .append("'").append(col).append("', ")
                        .append(isdelete ? "OLD." : "NEW.")
                        .append(col);
-                       if (!isdelete && (ti.iskey(col) || !ti.hasKey())) {
+                       if (ti.iskey(col) || !ti.hasKey()) {
                                keyJson.append(kfx)
                                        .append("'").append(col).append("', ")
-                                       .append(isupdate ? "OLD." : "NEW.")
+                                       .append(isinsert ? "NEW." : "OLD.")
                                        .append(col);
                                kfx = ", ";
                        }
@@ -382,7 +383,7 @@ NEW.field refers to the new value
                  .append("', ")
                  .append(isdelete ? "'D'" : (op.equals("INSERT") ? "'I'" : "'U'"))
                  .append(", ")
-                 .append(!isdelete ? keyJson.toString() : "NULL")
+                 .append( (keyJson.length()>"JSON_OBJECT()".length()) ? keyJson.toString() : "NULL")
                  .append(", ")
                  .append(newJson.toString())
                  .append(", ")