\r
Alternatively, model classes can be automatically generated by iciql using the model generation tool. Please see the [tools](tools.html) page for details.\r
\r
-### Supported Data Types\r
-<table>\r
+### Configuration Requirements and Limitations\r
+\r
+1. Your model class **must** provide a public default constructor.\r
+2. Only the specified types are supported. Other types such as arrays and custom types are not supported.\r
+3. Triggers, views, and other advanced database features are not supported.\r
\r
+### Fully Supported Data Types\r
+The following data types can be used for all iciql expressions.\r
+<table>\r
+<tr><th colspan="2">All Databases</th></tr>\r
<tr><td>java.lang.String</td>\r
<td>VARCHAR *(length > 0)* or TEXT *(length == 0)*</td></tr>\r
\r
<tr><td>java.util.Date</td>\r
<td>TIMESTAMP</td></tr>\r
\r
-<tr><td>byte []</td>\r
-<td>BLOB</td></tr>\r
-\r
-<tr><td>java.lang.Enum.name()</td>\r
-<td>VARCHAR *(length > 0)* or TEXT *(length == 0)*<br/>*EnumType.STRING*</td></tr>\r
+<tr><td>java.lang.Enum.name()<br/>*default type*</td>\r
+<td>VARCHAR *(length > 0)* or TEXT *(length == 0)*<br/>*EnumType.NAME*</td></tr>\r
\r
<tr><td>java.lang.Enum.ordinal()</td>\r
<td>INT<br/>*EnumType.ORDINAL*</td></tr>\r
<tr><td>java.lang.Enum implements<br/>*com.iciql.Iciql.EnumId.enumId()*</td>\r
<td>INT<br/>*EnumType.ENUMID*</td></tr>\r
\r
+<tr><th colspan="2">H2 Databases</th></tr>\r
+<tr><td>java.util.UUID</td>\r
+<td>UUID</td><tr/>\r
+\r
</table>\r
\r
**NOTE:**<br/>\r
The reverse lookup used for model generation, SQL type -> Java type, contains more mappings.<br/>\r
Please consult the `com.iciql.ModelUtils` class for details. \r
\r
-### Unsupported Types\r
-- Java primitives (use their object counterparts instead)\r
-- array types\r
-- custom types\r
+### Partially Supported Data Types\r
+The following data types can be mapped to columns for all general statements <u>BUT</u> these field types may **not** be used to specify **compile-time** *clauses or constraints*.\r
+\r
+<table>\r
+<tr><td>byte []</td>\r
+<td>BLOB</td></tr>\r
+\r
+<tr><td>boolean</td>\r
+<td>BIT</td></tr>\r
+ \r
+<tr><td>byte</td>\r
+<td>TINYINT</td></tr>\r
+ \r
+<tr><td>short</td>\r
+<td>SMALLINT</td></tr>\r
+ \r
+<tr><td>int</td>\r
+<td>INT</td></tr>\r
+ \r
+<tr><td>long</td>\r
+<td>BIGINT</td></tr>\r
+ \r
+<tr><td>float</td>\r
+<td>REAL</td></tr>\r
+ \r
+<tr><td>double</td>\r
+<td>DOUBLE</td></tr>\r
+\r
+</table>\r
\r
-### Configuration Rules\r
-1. field mappings must be Objects not primitives\r
-2. the model class must have a default public constructor\r
+#### Partially Supported Data Types Example\r
+%BEGINCODE%\r
+class Primitives {\r
+ @IQColumn(primaryKey = true)\r
+ int id;\r
+ \r
+ @IQColumn\r
+ String name;\r
+ \r
+ public Primitives() {\r
+ }\r
+ \r
+ public Primitives(int id, String name) {\r
+ this.id = id;\r
+ this.name = name;\r
+ } \r
+}\r
+ \r
+Primitives p = new Primitives();\r
+\r
+// the following expressions compile, but will throw iciql runtime exceptions\r
+db.from(p).where(p.id).is(100).selectFirst();\r
+db.from(p).where(p.id).atLeast(10).select();\r
+\r
+// the following expressions will work as expected\r
+db.from(p).select();\r
+db.from(p).where("id = ?", 100).selectFirst();\r
+db.from(p).where("id >= ?", 10).select();\r
+db.insert(new Primitives(150, "test"));\r
+db.update(new Primitives(150, "modified"));\r
+db.delete(new Primitives(150, "test"));\r
+%ENDCODE%\r
\r
-### Configuration Limitations\r
-Triggers, views, and other advanced database features are unimplemented.\r
\r
## Annotation Configuration\r
The recommended approach to setup a model class is to annotate the class and field declarations.\r
### How does it work?\r
If you choose to use versioning, iciql will maintain a table within your database named *_iq_versions* which is defined as:\r
\r
- CREATE TABLE _IQ_VERSIONS(SCHEMANAME TEXT NOT NULL, TABLENAME TEXT NOT NULL, VERSION INT NOT NULL)\r
+ CREATE TABLE _IQ_VERSIONS(SCHEMANAME VARCHAR(255) NOT NULL, TABLENAME VARCHAR(255) NOT NULL, VERSION INT NOT NULL)\r
\r
This database table is automatically created if and only if at least one of your model classes specifies a *version* > 0.\r
\r
#### Db.executeQuery Approaches\r
There may be times when the hybrid approach is still too restrictive and you'd prefer to write straight SQL. You can do that too and use iciql to build objects from your ResultSet, but be careful:\r
\r
-1. Make sure to _select *_ in your query otherwise db.bindResultSet() will throw a RuntimeException\r
+1. Make sure to _select *_ in your query otherwise db.buildObjects() will throw a RuntimeException\r
2. There is no model class type checking nor field type checking. \r
\r
%BEGINCODE%\r
## Release History\r
\r
### Current Release\r
+\r
**%VERSION%** ([zip](http://code.google.com/p/iciql/downloads/detail?name=%ZIP%)|[jar](http://code.google.com/p/iciql/downloads/detail?name=%JAR%)) *released %BUILDDATE%*\r
\r
+- api change release (API v3)\r
+- finished enum support (issue 4)\r
+- added UUID type support (H2 databases only)\r
+- added partial primitives support *(primitives may not be used for compile-time condition clauses)*\r
+- added *between(A y).and(A z)* condition syntax\r
+\r
+### Older Releases\r
+\r
+**0.6.2** *released 2011-08-05*\r
+\r
- api change release (API v2)\r
- fix to versioning to support H2 1.3.158+\r
- added BLOB support (issue 1)\r
%ENDCODE%\r
- @IQColumn(maxLength=20) -> @IQColumn(length=20)\r
- @IQColumn(trimString=true) -> @IQColumn(trim=true)\r
-\r
-### Older Releases\r
-\r
-**0.5.0** ([zip](http://code.google.com/p/iciql/downloads/detail?name=iciql-0.5.0.zip)|[jar](http://code.google.com/p/iciql/downloads/detail?name=iciql-0.5.0.jar)) *released 2011-08-03*\r
+ \r
+**0.5.0** *released 2011-08-03*\r
\r
- initial release (API v1)\r
\r
* If a class is annotated with IQTable and at the same time implements Table,\r
* the define() method is not called.\r
* <p>\r
- * Supported data types:\r
+ * Fully Supported Data Types:\r
* <table>\r
+ * <tr><th colspan="2">All Databases</th></tr>\r
* <tr>\r
* <td>java.lang.String</td>\r
* <td>VARCHAR (length > 0) or TEXT (length == 0)</td>\r
* <td>TIMESTAMP</td>\r
* </tr>\r
* <tr>\r
- * <td>byte []</td>\r
- * <td>BLOB</td>\r
- * </tr>\r
- * <tr>\r
* <td>java.lang.Enum.name()</td>\r
* <td>VARCHAR (length > 0) or TEXT (length == 0)<br/>\r
- * EnumType.STRING</td>\r
+ * EnumType.NAME</td>\r
* </tr>\r
* <tr>\r
* <td>java.lang.Enum.ordinal()</td>\r
* <td>INT<br/>\r
* EnumType.ENUMID</td>\r
* </tr>\r
+ * <tr><th colspan="2">H2 Databases</th></tr>\r
+ * <tr>\r
+ * <td>java.util.UUID</td>\r
+ * <td>UUID</td>\r
* </tr>\r
* </table>\r
* <p>\r
- * Unsupported data types: primitives, Array Types, and custom types.\r
+ * Partially Supported Data Types:\r
+ * <p>\r
+ * The following data types can be mapped to columns for all general statements\r
+ * BUT these field types may not be used to specify compile-time clauses or\r
+ * constraints.\r
+ * <table>\r
+ * <tr><td>byte []</td>\r
+ * <td>BLOB</td></tr>\r
+ * <tr><td>boolean</td>\r
+ * <td>BIT</td></tr>\r
+ * <tr><td>byte</td>\r
+ * <td>TINYINT</td></tr>\r
+ * <tr><td>short</td>\r
+ * <td>SMALLINT</td></tr>\r
+ * <tr><td>int</td>\r
+ * <td>INT</td></tr>\r
+ * <tr><td>long</td>\r
+ * <td>BIGINT</td></tr>\r
+ * <tr><td>float</td>\r
+ * <td>REAL</td></tr>\r
+ * <tr><td>double</td>\r
+ * <td>DOUBLE</td></tr>\r
+ * </table>\r
* <p>\r
* Table and field mapping: by default, the mapped table name is the class name\r
* and the public fields are reflectively mapped, by their name, to columns. As\r
* Enumeration representing how to map a java.lang.Enum to a column.\r
* <p>\r
* <ul>\r
- * <li>STRING - name() : string\r
+ * <li>NAME - name() : string\r
* <li>ORDINAL - ordinal() : int\r
* <li>ENUMID - enumId() : int\r
* </ul>\r
* @see com.iciql.Iciql.EnumId interface\r
*/\r
public enum EnumType {\r
- STRING, ORDINAL, ENUMID;\r
+ NAME, ORDINAL, ENUMID;\r
+ \r
+ public static final EnumType DEFAULT_TYPE = NAME;\r
}\r
\r
/**\r
* be overridden for an individual field by specifying the IQEnum\r
* annotation.\r
* <p>\r
- * The default mapping is by STRING.\r
+ * The default mapping is by NAME.\r
* \r
* <pre>\r
- * IQEnum(EnumType.STRING)\r
+ * IQEnum(EnumType.NAME)\r
* </pre>\r
* \r
- * A string mapping will generate either a VARCHAR, if IQColumn.length >\r
- * 0 or a TEXT column if IQColumn.length == 0\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
@Retention(RetentionPolicy.RUNTIME)\r
@Target({ ElementType.FIELD, ElementType.TYPE })\r
public @interface IQEnum {\r
- EnumType value() default EnumType.STRING;\r
+ EnumType value() default EnumType.NAME;\r
}\r
\r
/**\r
import java.util.UUID;
import java.util.regex.Pattern;
+import com.iciql.Iciql.EnumType;
import com.iciql.TableDefinition.FieldDefinition;
import com.iciql.util.StringUtils;
static String getDataType(FieldDefinition fieldDef, boolean strictTypeMapping) {
Class<?> fieldClass = fieldDef.field.getType();
if (fieldClass.isEnum()) {
- if (fieldDef.enumType == null) {
- throw new IciqlException(fieldDef.field.getName() + " enum field does not specify @IQEnum!");
- }
switch (fieldDef.enumType) {
- case STRING:
+ case ORDINAL:
+ case ENUMID:
+ return "INT";
+ case NAME:
+ default:
if (fieldDef.maxLength <= 0) {
return "TEXT";
}
return "VARCHAR";
- case ORDINAL:
- case ENUMID:
- return "INT";
}
}
if (SUPPORTED_TYPES.containsKey(fieldClass)) {
\r
// configure Java -> SQL enum mapping\r
if (f.getType().isEnum()) {\r
+ enumType = EnumType.DEFAULT_TYPE;\r
if (f.getType().isAnnotationPresent(IQEnum.class)) {\r
// enum definition is annotated for all instances\r
IQEnum iqenum = f.getType().getAnnotation(IQEnum.class);\r
// convert enumeration to INT or STRING\r
Enum<?> iqenum = (Enum<?>) value;\r
switch (field.enumType) {\r
- case STRING:\r
+ case NAME:\r
if (field.trimString && field.maxLength > 0) {\r
if (iqenum.name().length() > field.maxLength) {\r
return iqenum.name().substring(0, field.maxLength);\r
import java.util.HashMap;\r
import java.util.HashSet;\r
import java.util.IdentityHashMap;\r
-import java.util.List;\r
import java.util.Map;\r
import java.util.UUID;\r
import java.util.concurrent.atomic.AtomicLong;\r
return clazz.getEnumConstants()[0];\r
} else if (clazz == java.util.UUID.class) {\r
return (T) UUID.randomUUID();\r
- } else if (clazz == List.class) {\r
- return (T) new ArrayList();\r
}\r
try {\r
return clazz.newInstance();\r
}\r
\r
public static Object convertEnum(Enum<?> o, EnumType type) {\r
- if (o == null || type == null) {\r
+ if (o == null) {\r
return null;\r
}\r
switch (type) {\r
}\r
EnumId enumid = (EnumId) o;\r
return enumid.enumId();\r
- case STRING:\r
+ case NAME:\r
default:\r
return o.name();\r
}\r
if (targetType.isAssignableFrom(currentType)) {\r
return o;\r
}\r
-\r
// convert from VARCHAR/TEXT/INT to Enum\r
Enum<?>[] values = (Enum[]) targetType.getEnumConstants();\r
if (Clob.class.isAssignableFrom(currentType)) {\r
true);
assertEquals(1, models.size());
// a poor test, but a start
- assertEquals(1697, models.get(0).length());
+ assertEquals(1780, models.get(0).length());
}
@Test
db.insert(model);\r
\r
PrimitivesModel p = new PrimitivesModel();\r
- \r
+\r
// retrieve model and compare\r
PrimitivesModel retrievedModel = db.from(p).selectFirst();\r
assertTrue(model.equivalentTo(retrievedModel));\r
\r
- // retrieve with conditions and compare \r
-// StatementLogger.activateConsoleLogger();\r
-// retrievedModel = db.from(p).where(p.myLong).is(model.myLong).and(p.myInteger).is(model.myInteger)\r
-// .selectFirst();\r
-// assertTrue(model.equivalentTo(retrievedModel));\r
-// \r
-// // update myInteger and compare\r
-// db.from(p).set(p.myInteger).to(10).where(p.myLong).is(model.myLong).update();\r
-// retrievedModel = db.from(p).selectFirst();\r
- \r
-// assertEquals(10, retrievedModel.myInteger);\r
+ retrievedModel = db.from(p).where("mylong = ? and myinteger = ?", model.myLong, model.myInteger)\r
+ .selectFirst();\r
+ assertTrue(model.equivalentTo(retrievedModel));\r
+\r
+ // retrieve with conditions and compare\r
+ // StatementLogger.activateConsoleLogger();\r
+ // retrievedModel =\r
+ // db.from(p).where(p.myLong).is(model.myLong).and(p.myInteger).is(model.myInteger)\r
+ // .selectFirst();\r
+ // assertTrue(model.equivalentTo(retrievedModel));\r
+ //\r
+ // // update myInteger and compare\r
+ // db.from(p).set(p.myInteger).to(10).where(p.myLong).is(model.myLong).update();\r
+ // retrievedModel = db.from(p).selectFirst();\r
+\r
+ // assertEquals(10, retrievedModel.myInteger);\r
\r
db.close();\r
}\r
\r
// override the enumtype to string\r
// ensure that we specify a length so that the column is VARCHAR\r
- @IQEnum(EnumType.STRING)\r
+ @IQEnum(EnumType.NAME)\r
@IQColumn(length = 25)\r
private Tree tree;\r
\r
@IQColumn
private byte[] myBlob;
- @IQEnum(EnumType.STRING)
+ // test default enum type NAME
+ @IQColumn(trim = true, length = 25)
+ private Flower myDefaultFlower;
+
+ @IQEnum(EnumType.NAME)
@IQColumn(trim = true, length = 25)
private Flower myFavoriteFlower;
s.mySqlTime = new java.sql.Time(rand.nextLong());
s.mySqlTimestamp = new java.sql.Timestamp(rand.nextLong());
s.myBlob = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ s.myDefaultFlower = Flower.DAFFODIL;
s.myFavoriteFlower = Flower.MUM;
s.myOtherFavoriteFlower = Flower.MARIGOLD;
s.myFavoriteTree = Tree.BIRCH;
same &= mySqlTime.toString().equals(s.mySqlTime.toString());
same &= myString.equals(s.myString);
same &= compare(myBlob, s.myBlob);
+ same &= myDefaultFlower.equals(s.myDefaultFlower);
same &= myFavoriteFlower.equals(s.myFavoriteFlower);
same &= myOtherFavoriteFlower.equals(s.myOtherFavoriteFlower);
same &= myFavoriteTree.equals(s.myFavoriteTree);