From 0c5463e7372fe4c47341dcf0c48bdd94682d0c7c Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 5 Aug 2011 17:15:45 -0400 Subject: [PATCH] IndexValidation was broken for single-indexes or non-standard indexes. --- src/com/iciql/Constants.java | 2 +- src/com/iciql/TableInspector.java | 18 ++++++++++++++---- tests/com/iciql/test/ModelsTest.java | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/com/iciql/Constants.java b/src/com/iciql/Constants.java index 63bfeff..d78f1db 100644 --- a/src/com/iciql/Constants.java +++ b/src/com/iciql/Constants.java @@ -25,7 +25,7 @@ public class Constants { // The build script extracts this exact line so be careful editing it // and only use A-Z a-z 0-9 .-_ in the string. - public static final String VERSION = "0.6.1"; + public static final String VERSION = "0.6.2"; // The build script extracts this exact line so be careful editing it // and only use A-Z a-z 0-9 .-_ in the string. diff --git a/src/com/iciql/TableInspector.java b/src/com/iciql/TableInspector.java index 82b732a..a4b3b8f 100644 --- a/src/com/iciql/TableInspector.java +++ b/src/com/iciql/TableInspector.java @@ -180,7 +180,7 @@ public class TableInspector { imports.add(IQTable.class.getCanonicalName()); imports.add(IQIndexes.class.getCanonicalName()); imports.add(IQIndex.class.getCanonicalName()); - imports.add(IQColumn.class.getCanonicalName()); + imports.add(IQColumn.class.getCanonicalName()); imports.add(IndexType.class.getCanonicalName()); // fields @@ -276,7 +276,8 @@ public class TableInspector { AnnotationBuilder ap = new AnnotationBuilder(); if (indexes.size() == 1) { // single index - ap.append(generateIndexAnnotation(indexes.get(0))); + IndexInspector index = indexes.values().toArray(new IndexInspector[1])[0]; + ap.append(generateIndexAnnotation(index)); ap.append(eol); } else { // multiple indexes @@ -301,11 +302,11 @@ public class TableInspector { ap.addParameter("name", index.name); } if (!index.type.equals(IndexType.STANDARD)) { - ap.addParameter("type", IndexType.class.getSimpleName() + "." + index.type.name()); + ap.addEnum("type", index.type); } if (ap.getCount() > 0) { // multiple fields specified - ap.addParameter("values", index.columns); + ap.addParameter("value", index.columns); } else { // default value ap.addParameter(null, index.columns); @@ -685,5 +686,14 @@ public class TableInspector { } } } + + void addEnum(String parameter, Enum value) { + appendExceptFirst(", "); + if (!StringUtils.isNullOrEmpty(parameter)) { + append(parameter); + append('='); + } + append(value.getClass().getSimpleName() + "." + value.name()); + } } } \ No newline at end of file diff --git a/tests/com/iciql/test/ModelsTest.java b/tests/com/iciql/test/ModelsTest.java index 9012296..8fbf219 100644 --- a/tests/com/iciql/test/ModelsTest.java +++ b/tests/com/iciql/test/ModelsTest.java @@ -115,7 +115,7 @@ public class ModelsTest { true); assertEquals(1, models.size()); // a poor test, but a start - assertEquals(1895, models.get(0).length()); + assertEquals(1893, models.get(0).length()); } @Test -- 2.39.5