From 0932e559b420d46f8394a464c466804c1df0ede1 Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 4 Jan 2012 22:12:56 -0500 Subject: Disallow multiple instances of an enum within a model class --- src/com/iciql/TableDefinition.java | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/com/iciql/TableDefinition.java') diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java index f7bbc13..b85b941 100644 --- a/src/com/iciql/TableDefinition.java +++ b/src/com/iciql/TableDefinition.java @@ -415,7 +415,30 @@ public class TableDefinition { void checkMultipleBooleans() { if (multiplePrimitiveBools) { throw new IciqlException( - "Can not explicitly reference multiple primitive booleans in a model class!"); + "Can not explicitly reference a primitive boolean if there are multiple boolean fields in your model class!"); + } + } + + void checkMultipleEnums(Object o) { + if (o == null) { + return; + } + Class clazz = o.getClass(); + if (!clazz.isEnum()) { + return; + } + + int fieldCount = 0; + for (FieldDefinition fieldDef : fields) { + Class targetType = fieldDef.field.getType(); + if (clazz.equals(targetType)) { + fieldCount++; + } + } + + if (fieldCount > 1) { + throw new IciqlException( + "Can not explicitly reference {0} because there are {1} {0} fields in your model class!", clazz.getSimpleName(), fieldCount); } } -- cgit v1.2.3