title: ${project.name} ${project.version} released
id: ${project.version}
date: ${project.buildDate}
- note: ~
+ note: "If you are upgrading and using EnumId mapping you will have to update your models to define the target class for the enumid mapping."
html: ~
text: ~
security: ~
- Return null NPE in selectFirst() if list is empty (pr-5)
- Fix Moxie toolkit download URL (pr-6)
- Be more careful with primitive numeric type rollovers
- changes: ~
+ changes:
+ - Revised EnumId interface to support generic types
additions:
- Add syntax for IN and NOT IN (pr-7)
- Add support for nested AND/OR conditions (pr-8)
- Add support for mapping SQL BOOLEAN to primitive numeric types, not just object numeric types
+ - Add support for customizing EnumId mapping, you can now map enum constants to values of your choice as long as they are a standard type
dependencyChanges:
- H2 1.4
- HSQLDB 2.3
* <p>\r
* Automatic model generation: you may automatically generate model classes as\r
* strings with the Db and DbInspector objects:\r
- * \r
+ *\r
* <pre>\r
* Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
* DbInspector inspector = new DbInspector(db);\r
* inspector.generateModel(schema, table, packageName,\r
* annotateSchema, trimStrings)\r
* </pre>\r
- * \r
+ *\r
* Or you may use the GenerateModels tool to generate and save your classes to\r
* the file system:\r
- * \r
+ *\r
* <pre>\r
* java -jar iciql.jar\r
* -url "jdbc:h2:mem:"\r
* -package packageName -folder destination\r
* -annotateSchema false -trimStrings true\r
* </pre>\r
- * \r
+ *\r
* Model validation: you may validate your model class with DbInspector object.\r
* The DbInspector will report errors, warnings, and suggestions:\r
- * \r
+ *\r
* <pre>\r
* Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
* DbInspector inspector = new DbInspector(db);\r
/**\r
* An annotation for an iciql version.\r
* <p>\r
- * \r
+ *\r
* @IQVersion(1)\r
*/\r
@Retention(RetentionPolicy.RUNTIME)\r
/**\r
* An annotation for a schema.\r
* <p>\r
- * \r
+ *\r
* @IQSchema("PUBLIC")\r
*/\r
@Retention(RetentionPolicy.RUNTIME)\r
* <li>com.iciql.iciql.IndexType.HASH\r
* <li>com.iciql.iciql.IndexType.UNIQUE_HASH\r
* </ul>\r
- * \r
+ *\r
* HASH indexes may only be valid for single column indexes.\r
- * \r
+ *\r
*/\r
IndexType type() default IndexType.STANDARD;\r
\r
public static enum ConstraintUpdateType {\r
UNSET, CASCADE, RESTRICT, SET_NULL, NO_ACTION, SET_DEFAULT;\r
}\r
- \r
+\r
/**\r
* Enumeration defining the deferrability.\r
*/\r
public static enum ConstraintDeferrabilityType {\r
UNSET, DEFERRABLE_INITIALLY_DEFERRED, DEFERRABLE_INITIALLY_IMMEDIATE, NOT_DEFERRABLE;\r
}\r
- \r
+\r
/**\r
* A foreign key constraint annotation.\r
* <p>\r
* <ul>\r
* <li>@IQContraintForeignKey(\r
- * foreignColumns = { "idaccount"}, \r
- * referenceName = "account", \r
+ * foreignColumns = { "idaccount"},\r
+ * referenceName = "account",\r
* referenceColumns = { "id" },\r
* deleteType = ConstrainDeleteType.CASCADE,\r
* updateType = ConstraintUpdateType.NO_ACTION )\r
* </ul>\r
*/\r
ConstraintDeferrabilityType deferrabilityType() default ConstraintDeferrabilityType.UNSET;\r
- \r
+\r
/**\r
* The source table for the columns defined as foreign.\r
*/\r
* The reference table for the columns defined as references.\r
*/\r
String referenceName() default "";\r
- \r
+\r
/**\r
* Columns defined as 'references'.\r
* <ul>\r
public @interface IQContraintsForeignKey {\r
IQContraintForeignKey[] value() default {};\r
}\r
- \r
+\r
/**\r
* A unique constraint annotation.\r
* <p>\r
public @interface IQContraintsUnique {\r
IQContraintUnique[] value() default {};\r
}\r
- \r
+\r
/**\r
* Annotation to define a view.\r
*/\r
* model class is not annotated with IQView. Default: unspecified.\r
*/\r
String name() default "";\r
- \r
+\r
/**\r
* The source table for the view.\r
* <p>\r
*/\r
boolean annotationsOnly() default true;\r
}\r
- \r
+\r
/**\r
* String snippet defining SQL constraints for a field. Use "this" as\r
* a placeholder for the column name. "this" will be substituted at\r
public @interface IQConstraint {\r
\r
String value() default "";\r
- } \r
- \r
+ }\r
+\r
/**\r
* Annotation to specify multiple indexes.\r
*/\r
*/\r
String defaultValue() default "";\r
\r
- } \r
+ }\r
\r
/**\r
* Interface for using the EnumType.ENUMID enumeration mapping strategy.\r
* Enumerations wishing to use EnumType.ENUMID must implement this\r
* interface.\r
*/\r
- public interface EnumId {\r
- int enumId();\r
+ public interface EnumId<X> {\r
+ X enumId();\r
+ Class<X> enumIdClass();\r
}\r
\r
+\r
+\r
/**\r
* Enumeration representing how to map a java.lang.Enum to a column.\r
* <p>\r
* <ul>\r
* <li>NAME - name() : string\r
* <li>ORDINAL - ordinal() : int\r
- * <li>ENUMID - enumId() : int\r
+ * <li>ENUMID - enumId() : X\r
* </ul>\r
- * \r
+ *\r
* @see com.iciql.Iciql.EnumId interface\r
*/\r
public enum EnumType {\r
* annotation.\r
* <p>\r
* The default mapping is by NAME.\r
- * \r
+ *\r
* <pre>\r
* IQEnum(EnumType.NAME)\r
* </pre>\r
- * \r
+ *\r
* A string mapping will generate either a VARCHAR, if IQColumn.length > 0\r
* or a TEXT column if IQColumn.length == 0\r
- * \r
+ *\r
*/\r
@Retention(RetentionPolicy.RUNTIME)\r
@Target({ ElementType.FIELD, ElementType.TYPE })\r
*/\r
@Retention(RetentionPolicy.RUNTIME)\r
@Target(ElementType.FIELD)\r
- public @interface IQIgnore{ \r
+ public @interface IQIgnore{\r
}\r
- \r
+\r
/**\r
* This method is called to let the table define the primary key, indexes,\r
* and the table name.\r
/**
* Returns a SQL type mapping for a Java class.
- *
+ *
* @param fieldDef
* the field to map
* @return
if (fieldClass.isEnum()) {
switch (fieldDef.enumType) {
case ORDINAL:
- case ENUMID:
return "INT";
+ case ENUMID:
+ String sqlType = SUPPORTED_TYPES.get(fieldDef.enumTypeClass);
+ if (sqlType == null) {
+ throw new IciqlException("Unsupported enum mapping type {0} for {1}",
+ fieldDef.enumTypeClass, fieldDef.columnName);
+ }
+ return sqlType;
case NAME:
default:
return "VARCHAR";
/**
* Returns the Java class for a given SQL type.
- *
+ *
* @param sqlType
* @param dateTimeClass
* the preferred date class (java.util.Date or
/**
* Tries to create a convert a SQL table name to a camel case class name.
- *
+ *
* @param tableName
* the SQL table name
* @return the class name
/**
* Ensures that SQL column names don't collide with Java keywords.
- *
+ *
* @param columnName
* the column name
* @return the Java field name
/**
* Converts a DEFAULT clause value into an object.
- *
+ *
* @param field
* definition
* @return object
/**
* Converts the object into a DEFAULT clause value.
- *
+ *
* @param o
* the default object
* @return the value formatted for a DEFAULT clause
/**
* Checks the formatting of IQColumn.defaultValue().
- *
+ *
* @param defaultValue
* the default value
* @return true if it is
/**
* Checks to see if the default value matches the class.
- *
+ *
* @param modelClass
* the class
* @param defaultValue
import com.iciql.Iciql.EnumType;\r
import com.iciql.Iciql.IQColumn;\r
import com.iciql.Iciql.IQConstraint;\r
+import com.iciql.Iciql.IQContraintForeignKey;\r
import com.iciql.Iciql.IQContraintUnique;\r
+import com.iciql.Iciql.IQContraintsForeignKey;\r
import com.iciql.Iciql.IQContraintsUnique;\r
import com.iciql.Iciql.IQEnum;\r
-import com.iciql.Iciql.IQContraintForeignKey;\r
-import com.iciql.Iciql.IQContraintsForeignKey;\r
import com.iciql.Iciql.IQIgnore;\r
import com.iciql.Iciql.IQIndex;\r
import com.iciql.Iciql.IQIndexes;\r
/**\r
* A table definition contains the index definitions of a table, the field\r
* definitions, the table name, and other meta data.\r
- * \r
+ *\r
* @param <T>\r
* the table type\r
*/\r
/**\r
* The meta data of a constraint on foreign key.\r
*/\r
- \r
+\r
public static class ConstraintForeignKeyDefinition {\r
\r
public String constraintName;\r
public ConstraintUpdateType updateType = ConstraintUpdateType.UNSET;\r
public ConstraintDeferrabilityType deferrabilityType = ConstraintDeferrabilityType.UNSET;\r
}\r
- \r
+\r
/**\r
* The meta data of a unique constraint.\r
*/\r
- \r
+\r
public static class ConstraintUniqueDefinition {\r
\r
public String constraintName;\r
public List<String> uniqueColumns;\r
}\r
- \r
- \r
+\r
+\r
/**\r
* The meta data of a field.\r
*/\r
boolean nullable;\r
String defaultValue;\r
EnumType enumType;\r
+ Class<?> enumTypeClass;\r
boolean isPrimitive;\r
String constraint;\r
\r
throw new IciqlException(e);\r
}\r
}\r
- \r
+\r
@Override\r
public int hashCode() {\r
return columnName.hashCode();\r
}\r
- \r
+\r
@Override\r
public boolean equals(Object o) {\r
if (o instanceof FieldDefinition) {\r
\r
/**\r
* Define a primary key by the specified model fields.\r
- * \r
+ *\r
* @param modelFields\r
* the ordered list of model fields\r
*/\r
\r
/**\r
* Define a primary key by the specified column names.\r
- * \r
+ *\r
* @param columnNames\r
* the ordered list of column names\r
*/\r
\r
/**\r
* Defines an index with the specified model fields.\r
- * \r
+ *\r
* @param name\r
* the index name (optional)\r
* @param type\r
\r
/**\r
* Defines an index with the specified column names.\r
- * \r
+ *\r
* @param type\r
* the index type (STANDARD, HASH, UNIQUE, UNIQUE_HASH)\r
* @param columnNames\r
\r
/**\r
* Defines an unique constraint with the specified model fields.\r
- * \r
+ *\r
* @param name\r
* the constraint name (optional)\r
* @param modelFields\r
\r
/**\r
* Defines an unique constraint.\r
- * \r
+ *\r
* @param name\r
* @param columnNames\r
*/\r
\r
/**\r
* Defines a foreign key constraint with the specified model fields.\r
- * \r
+ *\r
* @param name\r
* the constraint name (optional)\r
* @param modelFields\r
if (inheritColumns) {\r
Class<?> superClass = clazz.getSuperclass();\r
classFields.addAll(Arrays.asList(superClass.getDeclaredFields()));\r
- \r
+\r
if (superClass.isAnnotationPresent(IQView.class)) {\r
IQView superView = superClass.getAnnotation(IQView.class);\r
if (superView.inheritColumns()) {\r
boolean trim = false;\r
boolean nullable = !f.getType().isPrimitive();\r
EnumType enumType = null;\r
+ Class<?> enumTypeClass = null;\r
String defaultValue = "";\r
String constraint = "";\r
// configure Java -> SQL enum mapping\r
IQEnum iqenum = f.getAnnotation(IQEnum.class);\r
enumType = iqenum.value();\r
}\r
+\r
+ if (EnumId.class.isAssignableFrom(f.getType())) {\r
+ // custom enumid mapping\r
+ enumTypeClass = ((EnumId<?>) f.getType().getEnumConstants()[0]).enumIdClass();\r
+ }\r
}\r
\r
// try using default object\r
defaultValue = col.defaultValue();\r
}\r
}\r
- \r
+\r
boolean hasConstraint = f.isAnnotationPresent(IQConstraint.class);\r
if (hasConstraint) {\r
IQConstraint con = f.getAnnotation(IQConstraint.class);\r
fieldDef.nullable = nullable;\r
fieldDef.defaultValue = defaultValue;\r
fieldDef.enumType = enumType;\r
+ fieldDef.enumTypeClass = enumTypeClass;\r
fieldDef.dataType = ModelUtils.getDataType(fieldDef);\r
fieldDef.constraint = constraint;\r
uniqueFields.add(fieldDef);\r
}\r
}\r
fields.addAll(uniqueFields);\r
- \r
+\r
List<String> primaryKey = Utils.newArrayList();\r
int primitiveBoolean = 0;\r
for (FieldDefinition fieldDef : fields) {\r
if (!EnumId.class.isAssignableFrom(value.getClass())) {\r
throw new IciqlException(field.field.getName() + " does not implement EnumId!");\r
}\r
- EnumId enumid = (EnumId) value;\r
+ EnumId<?> enumid = (EnumId<?>) value;\r
return enumid.enumId();\r
}\r
}\r
// return the value unchanged\r
return value;\r
}\r
- \r
+\r
PreparedStatement createInsertStatement(Db db, Object obj, boolean returnKey) {\r
SQLStatement stat = new SQLStatement(db);\r
StatementBuilder buff = new StatementBuilder("INSERT INTO ");\r
}\r
}\r
}\r
- \r
+\r
// create foreign keys constraints\r
for (ConstraintForeignKeyDefinition constraint : constraintsForeignKey) {\r
stat = new SQLStatement(db);\r
viewTableName = parentView.tableName();\r
}\r
}\r
- \r
+\r
if (StringUtils.isNullOrEmpty(viewTableName)) {\r
// still missing view table name\r
throw new IciqlException("View model class \"{0}\" is missing a table name!", tableName);\r
}\r
}\r
- \r
+\r
// allow control over createTableIfRequired()\r
createIfRequired = viewAnnotation.create();\r
}\r
- \r
+\r
if (clazz.isAnnotationPresent(IQIndex.class)) {\r
// single table index\r
IQIndex index = clazz.getAnnotation(IQIndex.class);\r
addIndex(index);\r
}\r
}\r
- \r
+\r
if (clazz.isAnnotationPresent(IQContraintUnique.class)) {\r
// single table unique constraint\r
IQContraintUnique constraint = clazz.getAnnotation(IQContraintUnique.class);\r
addConstraintUnique(constraint);\r
}\r
}\r
- \r
+\r
if (clazz.isAnnotationPresent(IQContraintForeignKey.class)) {\r
// single table constraint\r
IQContraintForeignKey constraint = clazz.getAnnotation(IQContraintForeignKey.class);\r
addConstraintForeignKey(constraint);\r
}\r
}\r
- \r
+\r
}\r
\r
private void addConstraintForeignKey(IQContraintForeignKey constraint) {\r
List<String> referenceColumns = Arrays.asList(constraint.referenceColumns());\r
addConstraintForeignKey(constraint.name(), foreignColumns, constraint.referenceName(), referenceColumns, constraint.deleteType(), constraint.updateType(), constraint.deferrabilityType());\r
}\r
- \r
+\r
private void addConstraintUnique(IQContraintUnique constraint) {\r
List<String> uniqueColumns = Arrays.asList(constraint.uniqueColumns());\r
addConstraintUnique(constraint.name(), uniqueColumns);\r
}\r
- \r
+\r
/**\r
* Defines a foreign key constraint with the specified parameters.\r
- * \r
+ *\r
* @param name\r
* name of the constraint\r
* @param foreignColumns\r
List<ConstraintUniqueDefinition> getContraintsUnique() {\r
return constraintsUnique;\r
}\r
- \r
+\r
List<ConstraintForeignKeyDefinition> getContraintsForeignKey() {\r
return constraintsForeignKey;\r
}\r
- \r
+\r
private void initObject(Object obj, Map<Object, FieldDefinition> map) {\r
for (FieldDefinition def : fields) {\r
Object newValue = def.initWithNewObject(obj);\r
* JaQu assumed that you can always use the integer index of the\r
* reflectively mapped field definition to determine position in the result\r
* set.\r
- * \r
+ *\r
* This is not always true.\r
- * \r
+ *\r
* iciql identifies when a select * query is executed and maps column names\r
* to a column index from the result set. If the select statement is\r
* explicit, then the standard assumed column index is used instead.\r
- * \r
+ *\r
* @param rs\r
* @return\r
*/\r
}\r
}\r
throw new IciqlException(e,\r
- "Missing default constructor? Exception trying to instantiate {0}: {1}",\r
- clazz.getName(), e.getMessage());\r
+ "Missing default constructor? Exception trying to instantiate {0}: {1}", clazz.getName(),\r
+ e.getMessage());\r
}\r
}\r
};\r
}\r
}\r
}\r
- throw new IciqlException(e,\r
- "Missing default constructor?! Exception trying to instantiate {0}: {1}",\r
+ throw new IciqlException(e, "Missing default constructor?! Exception trying to instantiate {0}: {1}",\r
clazz.getName(), e.getMessage());\r
}\r
}\r
if (!EnumId.class.isAssignableFrom(o.getClass())) {\r
throw new IciqlException("Can not convert the enum {0} using ENUMID", o);\r
}\r
- EnumId enumid = (EnumId) o;\r
+ EnumId<?> enumid = (EnumId<?>) o;\r
return enumid.enumId();\r
case NAME:\r
default:\r
}\r
\r
// find name match\r
- for (Enum<?> value : values) {\r
- if (value.name().equalsIgnoreCase(name)) {\r
- return value;\r
+ if (type.equals(EnumType.ENUMID)) {\r
+ // ENUMID mapping\r
+ for (Enum<?> value : values) {\r
+ EnumId<?> enumid = (EnumId<?>) value;\r
+ if (enumid.enumId().equals(name)) {\r
+ return value;\r
+ }\r
+ }\r
+ } else if (type.equals(EnumType.NAME)) {\r
+ // standard Enum.name() mapping\r
+ for (Enum<?> value : values) {\r
+ if (value.name().equalsIgnoreCase(name)) {\r
+ return value;\r
+ }\r
}\r
}\r
} else if (String.class.isAssignableFrom(currentType)) {\r
// VARCHAR field\r
String name = (String) o;\r
- for (Enum<?> value : values) {\r
- if (value.name().equalsIgnoreCase(name)) {\r
- return value;\r
+ if (type.equals(EnumType.ENUMID)) {\r
+ // ENUMID mapping\r
+ for (Enum<?> value : values) {\r
+ EnumId<?> enumid = (EnumId<?>) value;\r
+ if (enumid.enumId().equals(name)) {\r
+ return value;\r
+ }\r
+ }\r
+ } else if (type.equals(EnumType.NAME)) {\r
+ // standard Enum.name() mapping\r
+ for (Enum<?> value : values) {\r
+ if (value.name().equalsIgnoreCase(name)) {\r
+ return value;\r
+ }\r
}\r
}\r
} else if (Number.class.isAssignableFrom(currentType)) {\r
}\r
// ENUMID mapping\r
for (Enum<?> value : values) {\r
- EnumId enumid = (EnumId) value;\r
- if (enumid.enumId() == n) {\r
+ EnumId<?> enumid = (EnumId<?>) value;\r
+ if (enumid.enumId().equals(n)) {\r
+ return value;\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ // custom object mapping\r
+ if (type.equals(EnumType.ENUMID)) {\r
+ if (!EnumId.class.isAssignableFrom(targetType)) {\r
+ throw new IciqlException("Can not convert the value {0} from {1} to {2} using ENUMID", o,\r
+ currentType, targetType);\r
+ }\r
+ // ENUMID mapping\r
+ for (Enum<?> value : values) {\r
+ EnumId<?> enumid = (EnumId<?>) value;\r
+ if (enumid.enumId().equals(o)) {\r
return value;\r
}\r
}\r
length = Integer.MAX_VALUE;\r
}\r
int block = Math.min(BUFFER_BLOCK_SIZE, length);\r
- ByteArrayOutputStream out = new ByteArrayOutputStream(length == Integer.MAX_VALUE ? block\r
- : length);\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream(length == Integer.MAX_VALUE ? block : length);\r
byte[] buff = new byte[block];\r
while (length > 0) {\r
int len = Math.min(block, length);\r
import com.iciql.test.models.EnumModels.EnumIdModel;\r
import com.iciql.test.models.EnumModels.EnumOrdinalModel;\r
import com.iciql.test.models.EnumModels.EnumStringModel;\r
+import com.iciql.test.models.EnumModels.Genus;\r
import com.iciql.test.models.EnumModels.Tree;\r
\r
/**\r
testIntEnums(new EnumIdModel());\r
testIntEnums(new EnumOrdinalModel());\r
testStringEnums(new EnumStringModel());\r
+ testStringEnumIds(new EnumStringModel());\r
}\r
\r
private void testIntEnums(EnumModels e) {\r
list = db.from(e).where(e.tree()).between(Tree.MAPLE).and(Tree.PINE).select();\r
assertEquals(3, list.size());\r
}\r
- \r
+\r
+ private void testStringEnumIds(EnumModels e) {\r
+ // ensure all records inserted\r
+ long count = db.from(e).selectCount();\r
+ assertEquals(5, count);\r
+\r
+ // special case:\r
+ // value is first enum constant which is also the alias object.\r
+ // the first enum constant is used as the alias because we can not\r
+ // instantiate an enum reflectively.\r
+ EnumModels firstEnumValue = db.from(e).where(e.genus()).is(Genus.PINUS).selectFirst();\r
+ assertEquals(Tree.PINE, firstEnumValue.tree());\r
+ assertEquals(Genus.PINUS, firstEnumValue.genus());\r
+\r
+ EnumModels model = db.from(e).where(e.genus()).is(Genus.JUGLANS).selectFirst();\r
+\r
+ assertEquals(400, model.id.intValue());\r
+ assertEquals(Tree.WALNUT, model.tree());\r
+ assertEquals(Genus.JUGLANS, model.genus());\r
+\r
+ List<EnumModels> list = db.from(e).where(e.genus()).isNot(Genus.BETULA).select();\r
+ assertEquals(count - 1, list.size());\r
+\r
+ }\r
+\r
@Test\r
public void testMultipleEnumInstances() {\r
BadEnums b = new BadEnums();\r
assertTrue(e.getMessage(), e.getMessage().startsWith("Can not explicitly reference Tree"));\r
}\r
}\r
- \r
+\r
public static class BadEnums {\r
Tree tree1 = Tree.BIRCH;\r
Tree tree2 = Tree.MAPLE;\r
/**\r
* Test of @IQEnum annotated enumeration. This strategy is the default\r
* strategy for all fields of the Tree enum.\r
- * \r
+ *\r
* Individual Tree field declarations can override this strategy by\r
* specifying a different @IQEnum annotation.\r
- * \r
+ *\r
* Here ORDINAL specifies that this enum will be mapped to an INT column.\r
*/\r
@IQEnum(EnumType.ENUMID)\r
- public enum Tree implements EnumId {\r
+ public enum Tree implements EnumId<Integer> {\r
PINE(10), OAK(20), BIRCH(30), WALNUT(40), MAPLE(50);\r
\r
private int enumid;\r
}\r
\r
@Override\r
- public int enumId() {\r
+ public Integer enumId() {\r
return enumid;\r
}\r
+\r
+ @Override\r
+ public Class<Integer> enumIdClass() {\r
+ return Integer.class;\r
+ }\r
+\r
+ }\r
+\r
+ /**\r
+ * Enum for testing custom ENUMID mapping.\r
+ */\r
+ @IQEnum(EnumType.ENUMID)\r
+ public enum Genus implements EnumId<String> {\r
+ PINUS("pinaceae"), QUERCUS("fagaceae"), BETULA("betulaceae"), JUGLANS("juglandaceae"), ACER("aceraceae");\r
+\r
+ private String family;\r
+\r
+ Genus(String id) {\r
+ this.family = id;\r
+ }\r
+\r
+ @Override\r
+ public String enumId() {\r
+ return family;\r
+ }\r
+\r
+ @Override\r
+ public Class<String> enumIdClass() {\r
+ return String.class;\r
+ }\r
}\r
\r
@IQColumn(primaryKey = true)\r
\r
public abstract Tree tree();\r
\r
+ public abstract Genus genus();\r
+\r
/**\r
* Test model for enum-as-enumid.\r
*/\r
@IQColumn\r
private Tree tree;\r
\r
+ // no need to specify ENUMID type as the enumeration definition\r
+ // specifies it.\r
+ @IQColumn\r
+ private Genus genus;\r
+\r
public EnumIdModel() {\r
}\r
\r
- public EnumIdModel(int id, Tree tree) {\r
+ public EnumIdModel(int id, Tree tree, Genus genus) {\r
this.id = id;\r
this.tree = tree;\r
+ this.genus = genus;\r
}\r
\r
@Override\r
return tree;\r
}\r
\r
+ @Override\r
+ public Genus genus() {\r
+ return genus;\r
+ }\r
+\r
public static List<EnumIdModel> createList() {\r
- return Arrays.asList(new EnumIdModel(400, Tree.WALNUT), new EnumIdModel(200, Tree.OAK),\r
- new EnumIdModel(500, Tree.MAPLE), new EnumIdModel(300, Tree.BIRCH), new EnumIdModel(100,\r
- Tree.PINE));\r
+ return Arrays.asList(new EnumIdModel(400, Tree.WALNUT, Genus.JUGLANS),\r
+ new EnumIdModel(200, Tree.OAK, Genus.QUERCUS),\r
+ new EnumIdModel(500, Tree.MAPLE, Genus.ACER),\r
+ new EnumIdModel(300, Tree.BIRCH, Genus.BETULA),\r
+ new EnumIdModel(100, Tree.PINE, Genus.PINUS));\r
}\r
}\r
\r
@IQColumn\r
private Tree tree;\r
\r
+ @IQColumn\r
+ private Genus genus;\r
+\r
public EnumOrdinalModel() {\r
}\r
\r
- public EnumOrdinalModel(int id, Tree tree) {\r
+ public EnumOrdinalModel(int id, Tree tree, Genus genus) {\r
this.id = id;\r
this.tree = tree;\r
}\r
return tree;\r
}\r
\r
+ @Override\r
+ public Genus genus() {\r
+ return genus;\r
+ }\r
+\r
public static List<EnumOrdinalModel> createList() {\r
- return Arrays.asList(new EnumOrdinalModel(400, Tree.WALNUT), new EnumOrdinalModel(200, Tree.OAK),\r
- new EnumOrdinalModel(500, Tree.MAPLE), new EnumOrdinalModel(300, Tree.BIRCH),\r
- new EnumOrdinalModel(100, Tree.PINE));\r
+ return Arrays.asList(new EnumOrdinalModel(400, Tree.WALNUT, Genus.JUGLANS),\r
+ new EnumOrdinalModel(200, Tree.OAK, Genus.QUERCUS),\r
+ new EnumOrdinalModel(500, Tree.MAPLE, Genus.ACER),\r
+ new EnumOrdinalModel(300, Tree.BIRCH, Genus.BETULA),\r
+ new EnumOrdinalModel(100, Tree.PINE, Genus.PINUS));\r
}\r
}\r
\r
@IQColumn(length = 25)\r
private Tree tree;\r
\r
+ @IQColumn(trim = true, length = 25)\r
+ private Genus genus;\r
+\r
public EnumStringModel() {\r
}\r
\r
- public EnumStringModel(int id, Tree tree) {\r
+ public EnumStringModel(int id, Tree tree, Genus genus) {\r
this.id = id;\r
this.tree = tree;\r
+ this.genus = genus;\r
}\r
\r
@Override\r
return tree;\r
}\r
\r
+ @Override\r
+ public Genus genus() {\r
+ return genus;\r
+ }\r
+\r
public static List<EnumStringModel> createList() {\r
- return Arrays.asList(new EnumStringModel(400, Tree.WALNUT), new EnumStringModel(200, Tree.OAK),\r
- new EnumStringModel(500, Tree.MAPLE), new EnumStringModel(300, Tree.BIRCH),\r
- new EnumStringModel(100, Tree.PINE));\r
+ return Arrays.asList(new EnumStringModel(400, Tree.WALNUT, Genus.JUGLANS),\r
+ new EnumStringModel(200, Tree.OAK, Genus.QUERCUS),\r
+ new EnumStringModel(500, Tree.MAPLE, Genus.ACER),\r
+ new EnumStringModel(300, Tree.BIRCH, Genus.BETULA),\r
+ new EnumStringModel(100, Tree.PINE, Genus.PINUS));\r
}\r
}\r
}\r