Skip to content

Commit 24b6384

Browse files
o. Updated table validation of non-primary key column to check only kv_json_
o. Updated related tests
1 parent 4ab1f5a commit 24b6384

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/main/java/com/oracle/nosql/spring/data/core/NosqlTemplateBase.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,13 @@ protected boolean doCheckExistingTable(NosqlEntityInformation<?, ?> entityInform
267267
String tableNonShards = "{" + tableNonShardMap.entrySet()
268268
.stream().map(e -> e.getKey() + " " + e.getValue()).
269269
collect(Collectors.joining(",")) + "}";
270-
String tableOthers = "{" + tableOthersMap.entrySet().stream()
271-
.map(e -> e.getKey() + " " + e.getValue()).
272-
collect(Collectors.joining(",")) + "}";
273270

274271
String entityShards = "{" + entityShardMap.entrySet().stream()
275272
.map(e -> e.getKey() + " " + e.getValue()).
276273
collect(Collectors.joining(",")) + "}";
277274
String entityNonShards = "{" + entityNonShardMap.entrySet()
278275
.stream().map(e -> e.getKey() + " " + e.getValue()).
279276
collect(Collectors.joining(",")) + "}";
280-
String entityOthers = "{" + entityOthersMap.entrySet().stream()
281-
.map(e -> e.getKey() + " " + e.getValue()).
282-
collect(Collectors.joining(",")) + "}";
283277

284278
String msg;
285279
// check shard keys and types match
@@ -297,11 +291,15 @@ protected boolean doCheckExistingTable(NosqlEntityInformation<?, ?> entityInform
297291
errors.add(msg);
298292
}
299293

300-
// check non-primary keys and types match
301-
if (!tableOthers.equals(entityOthers)) {
302-
msg = String.format("Non-primary key columns mismatch:" +
303-
"table=%s, entity=%s.", tableOthers,
304-
entityOthers);
294+
// check kv_json_ column exist and it's type is JSON
295+
if (!tableOthersMap.containsKey(JSON_COLUMN.toLowerCase())) {
296+
msg = String.format("'%s' column does not exist in the table",
297+
JSON_COLUMN);
298+
errors.add(msg);
299+
} else if (!tableOthersMap.get(JSON_COLUMN.toLowerCase()).
300+
equalsIgnoreCase("json")) {
301+
msg = String.format("'%s' column type is not JSON in the " +
302+
"table", JSON_COLUMN);
305303
errors.add(msg);
306304
}
307305

@@ -342,7 +340,7 @@ protected boolean doCheckExistingTable(NosqlEntityInformation<?, ?> entityInform
342340
if (LOG.isDebugEnabled()) {
343341
LOG.debug("JSON Schema of the table is " + jsonSchema);
344342
}
345-
throw new IllegalStateException(msg, ex);
343+
LOG.warn(msg);
346344
}
347345

348346
if (!errors.isEmpty()) {

src/test/java/com/oracle/nosql/spring/data/test/composite/TestTableCreation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ public void testTableMismatchMissingJson() {
388388
} catch (IllegalArgumentException iae) {
389389
assertTrue(iae.getMessage().contains("Shard primary keys " +
390390
"mismatch"));
391-
assertTrue(iae.getMessage().contains("Non-primary key columns " +
392-
"mismatch"));
391+
assertTrue(iae.getMessage().contains("'kv_json_' column does not " +
392+
"exist in the table"));
393393
template.dropTableIfExists(domainClass.getSimpleName());
394394
}
395395
}
@@ -409,8 +409,8 @@ public void testTableMismatchMissingJsonType() {
409409
template.createTableIfNotExists(template.getNosqlEntityInformation(domainClass));
410410
fail("Expecting IllegalArgumentException but didn't get");
411411
} catch (IllegalArgumentException iae) {
412-
assertTrue(iae.getMessage().contains("Non-primary key columns " +
413-
"mismatch"));
412+
assertTrue(iae.getMessage().contains("'kv_json_' column type is " +
413+
"not JSON in the table"));
414414
template.dropTableIfExists(domainClass.getSimpleName());
415415
}
416416
}
@@ -435,8 +435,8 @@ public void testTableMismatchAll() {
435435
"mismatch"));
436436
assertTrue(iae.getMessage().contains("Non-shard primary keys " +
437437
"mismatch"));
438-
assertTrue(iae.getMessage().contains("Non-primary key columns " +
439-
"mismatch"));
438+
assertTrue(iae.getMessage().contains("'kv_json_' column type is " +
439+
"not JSON in the table"));
440440
template.dropTableIfExists(domainClass.getSimpleName());
441441
}
442442
}

0 commit comments

Comments
 (0)