Commit 726cbe18 authored by Donald H. (Donnie) Pinkston, III's avatar Donald H. (Donnie) Pinkston, III
Browse files

More detailed errors when constraint enforcement fails

parent 69f0be2a
No related merge requests found
Showing with 12 additions and 10 deletions
+12 -10
...@@ -112,8 +112,8 @@ public class DatabaseConstraintEnforcer implements RowEventListener { ...@@ -112,8 +112,8 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
List<KeyColumnRefs> candKeyList = schema.getCandidateKeys(); List<KeyColumnRefs> candKeyList = schema.getCandidateKeys();
for (KeyColumnRefs candKey : candKeyList) { for (KeyColumnRefs candKey : candKeyList) {
if (hasCandidateKeyValue(tableInfo, candKey, newTuple)) { if (hasCandidateKeyValue(tableInfo, candKey, newTuple)) {
String msg = makeErrorMessage( String msg = makeErrorMessage("Cannot insert tuple " +
"Cannot insert tuple due to unique constraint", newTuple + " due to unique constraint",
candKey.getConstraintName()); candKey.getConstraintName());
throw new ConstraintViolationException(msg); throw new ConstraintViolationException(msg);
...@@ -125,8 +125,8 @@ public class DatabaseConstraintEnforcer implements RowEventListener { ...@@ -125,8 +125,8 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
List<ForeignKeyColumnRefs> foreignKeys = schema.getForeignKeys(); List<ForeignKeyColumnRefs> foreignKeys = schema.getForeignKeys();
for (ForeignKeyColumnRefs foreignKey : foreignKeys) { for (ForeignKeyColumnRefs foreignKey : foreignKeys) {
if (!referencedTableHasValue(foreignKey, newTuple)) { if (!referencedTableHasValue(foreignKey, newTuple)) {
String msg = makeErrorMessage( String msg = makeErrorMessage("Cannot insert tuple " +
"Cannot insert tuple due to foreign key constraint", newTuple + " due to foreign key constraint",
foreignKey.getConstraintName()); foreignKey.getConstraintName());
throw new ConstraintViolationException(msg); throw new ConstraintViolationException(msg);
...@@ -388,9 +388,10 @@ public class DatabaseConstraintEnforcer implements RowEventListener { ...@@ -388,9 +388,10 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
if (existsOp.evaluatePredicate(null)) { if (existsOp.evaluatePredicate(null)) {
throw new ConstraintViolationException(String.format( throw new ConstraintViolationException(String.format(
"Cannot update tuple on table %s due to ON UPDATE " + "Cannot update tuple %s on table %s due to " +
"RESTRICT constraint %s from referencing table %s", "ON UPDATE RESTRICT constraint %s from " +
tableName, fk.getConstraintName(), referencingTableName)); "referencing table %s", oldTuple, tableName,
fk.getConstraintName(), referencingTableName));
} }
} }
break; break;
...@@ -460,9 +461,10 @@ public class DatabaseConstraintEnforcer implements RowEventListener { ...@@ -460,9 +461,10 @@ public class DatabaseConstraintEnforcer implements RowEventListener {
if (existsOp.evaluatePredicate(null)) { if (existsOp.evaluatePredicate(null)) {
throw new ConstraintViolationException(String.format( throw new ConstraintViolationException(String.format(
"Cannot delete tuple on table %s due to ON DELETE " + "Cannot delete tuple %s on table %s due to " +
"RESTRICT constraint %s from referencing table %s", "ON DELETE RESTRICT constraint %s from " +
tableName, fk.getConstraintName(), referencingTableName)); "referencing table %s", oldTuple, tableName,
fk.getConstraintName(), referencingTableName));
} }
} }
break; break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment