From 21132b4edba1bec41a45d84946a8fcaae781fc75 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 4 Mar 2010 07:01:07 +0000 Subject: [PATCH] Be stricter about our primary key requirements here. --- .../samskivert/depot/impl/DepotMarshaller.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/java/com/samskivert/depot/impl/DepotMarshaller.java b/src/java/com/samskivert/depot/impl/DepotMarshaller.java index 3a53e86..2dbe7f4 100644 --- a/src/java/com/samskivert/depot/impl/DepotMarshaller.java +++ b/src/java/com/samskivert/depot/impl/DepotMarshaller.java @@ -400,7 +400,6 @@ public class DepotMarshaller { if (requireKey) { checkHasPrimaryKey(); - } else if (!hasPrimaryKey()) { return null; } @@ -453,7 +452,7 @@ public class DepotMarshaller */ public Key makePrimaryKey (Comparable value) { - checkHasPrimaryKey(); + checkHasNonCompositePrimaryKey(); return new Key(_pClass, new Comparable[] { value }); } @@ -462,7 +461,7 @@ public class DepotMarshaller */ public Function, Key> primaryKeyFunction () { - checkHasPrimaryKey(); + checkHasNonCompositePrimaryKey(); return new Function, Key>() { public Key apply (Comparable value) { return new Key(_pClass, new Comparable[] { value }); @@ -1002,9 +1001,6 @@ public class DepotMarshaller } } - /** - * Check to see if we have a primary key, otherwise throw an UnsupportedOperationException. - */ protected void checkHasPrimaryKey () { if (!hasPrimaryKey()) { @@ -1013,6 +1009,14 @@ public class DepotMarshaller } } + protected void checkHasNonCompositePrimaryKey () + { + if (_pkColumns == null || _pkColumns.size() != 1) { + throw new UnsupportedOperationException( + getClass().getName() + " does not define a single column primary key"); + } + } + protected static class TableMetaData { public boolean tableExists;