Be stricter about our primary key requirements here.

This commit is contained in:
Michael Bayne
2010-03-04 07:01:07 +00:00
parent a970856aae
commit 21132b4edb
@@ -400,7 +400,6 @@ public class DepotMarshaller<T extends PersistentRecord>
{
if (requireKey) {
checkHasPrimaryKey();
} else if (!hasPrimaryKey()) {
return null;
}
@@ -453,7 +452,7 @@ public class DepotMarshaller<T extends PersistentRecord>
*/
public Key<T> makePrimaryKey (Comparable<?> value)
{
checkHasPrimaryKey();
checkHasNonCompositePrimaryKey();
return new Key<T>(_pClass, new Comparable<?>[] { value });
}
@@ -462,7 +461,7 @@ public class DepotMarshaller<T extends PersistentRecord>
*/
public Function<Comparable<?>, Key<T>> primaryKeyFunction ()
{
checkHasPrimaryKey();
checkHasNonCompositePrimaryKey();
return new Function<Comparable<?>, Key<T>>() {
public Key<T> apply (Comparable<?> value) {
return new Key<T>(_pClass, new Comparable<?>[] { value });
@@ -1002,9 +1001,6 @@ public class DepotMarshaller<T extends PersistentRecord>
}
}
/**
* 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<T extends PersistentRecord>
}
}
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;