From 658fb079577d97747f81022a326ddc0ad8501b72 Mon Sep 17 00:00:00 2001 From: chenson42 Date: Mon, 3 Feb 2014 23:49:26 +0000 Subject: [PATCH] Fixed 0001559: If there are no primary keys defined when the database writer is processing an update or delete report an error. --- .../io/data/writer/DatabaseWriter.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java index b6bbd64e61..27975bf166 100644 --- a/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java +++ b/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java @@ -596,6 +596,18 @@ protected LoadStatus delete(CsvData data, boolean useConflictDetection) { } } } + + int lookupKeyCountBeforeLobRemoval = lookupKeys.size(); + + if (lookupKeys.size() == 0) { + String msg = "There are no keys defined for " + + targetTable.getFullyQualifiedTableName() + + ". Cannot build an update statement. "; + if (lookupKeyCountBeforeLobRemoval > 0) { + msg += "The only keys defined are binary and they have been removed."; + } + throw new IllegalStateException(msg); + } lookupDataMap = getLookupDataMap(data); @@ -723,6 +735,8 @@ protected LoadStatus update(CsvData data, boolean applyChangesOnly, boolean useC lookupKeys = targetTable.getColumnsAsList(); } + int lookupKeyCountBeforeLobRemoval = lookupKeys.size(); + if (!platform.getDatabaseInfo().isBlobsWorkInWhereClause() || data.isNoBinaryOldData()) { Iterator it = lookupKeys.iterator(); @@ -733,6 +747,16 @@ protected LoadStatus update(CsvData data, boolean applyChangesOnly, boolean useC } } } + + if (lookupKeys.size() == 0) { + String msg = "There are no keys defined for " + + targetTable.getFullyQualifiedTableName() + + ". Cannot build an update statement. "; + if (lookupKeyCountBeforeLobRemoval > 0) { + msg += "The only keys defined are binary and they have been removed."; + } + throw new IllegalStateException(msg); + } lookupDataMap = getLookupDataMap(data);