From 27ccb36e11953d1bbe8eadef68e99b5ca3e09cab Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 12 Aug 2011 14:05:54 -0400 Subject: Primitive default: NOT NULL. Autoincrement primitive = 0 skip on insert. --- docs/01_model_classes.mkd | 21 +++++++++++++++++---- docs/02_usage.mkd | 2 +- docs/05_releases.mkd | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/01_model_classes.mkd b/docs/01_model_classes.mkd index 1b370d8..7e050bb 100644 --- a/docs/01_model_classes.mkd +++ b/docs/01_model_classes.mkd @@ -8,8 +8,8 @@ Alternatively, model classes can be automatically generated by iciql using the m ### Configuration Requirements and Limitations 1. Your model class **must** provide a public default constructor. -2. All **Object** columns are assumed NULLABLE unless explicitly set *@IQColumn(nullable = false)*. -3. All **Primitive** columns are assumed NOT NULLABLE unless explicitly set *@IQColumn(nullable = true)*. +2. All **Object** fields are assumed NULLABLE unless explicitly set *@IQColumn(nullable = false)*. +3. All **Primitive** fields are assumed NOT NULLABLE unless explicitly set *@IQColumn(nullable = true)*. 4. Only the specified types are supported. Any other types are not supported. 5. Triggers, views, and other advanced database features are not supported. @@ -110,14 +110,27 @@ You may specify default values for an @IQColumn by either: @IQColumn(defaultValue="'2000-01-01 00:00:00'") Date myDate; %ENDCODE% -2. setting a default object on the field
+2. setting a default value on the field
+**NOTE:**
+Primitive types have an implicit default value of *0* or *false*. %BEGINCODE% @IQColumn Date myDate = new Date(100, 0, 1); + +@IQColumn +int myId; %ENDCODE% If you want to specify a database-specific variable or function as your default value (e.g. CURRENT_TIMESTAMP) you must do that within the annotation. Also note that the IQColumn.defaultValue must be a well-formatted SQL DEFAULT expression whereas object defaults will be automatically converted to an SQL DEFAULT expression. - + +### Special Case: primitive autoincrement fields and 0 +%BEGINCODE% +@IQColumn(autoIncrement = true) +int myId; +%ENDCODE% + +Because primitive types have implicit default values, this field will be excluded from an INSERT statement if its value is 0. Iciql can not differentiate an implicit/uninitialized 0 from a explicitly assigned 0. + ### Example Annotated Model %BEGINCODE% import com.iciql.Iciql.EnumType; diff --git a/docs/02_usage.mkd b/docs/02_usage.mkd index 4cca129..4f823b5 100644 --- a/docs/02_usage.mkd +++ b/docs/02_usage.mkd @@ -113,7 +113,7 @@ The Product model class instance named **p** is an *alias* object. An *alias* i 1. *Alias* instances are **NOT** thread-safe and must not be used concurrently. 2. *Alias* instances have no other purpose than to provide a compile-time/runtime map of your table. -3. If you inspected an *alias* instance after using one you would find that it's fields have been assigned numeric values.
These values have no meaning. They are assigned from a static counter in `com.iciql.Utils.newObject()` during execution of the *db.from()* method. +3. If you inspected an *alias* instance after using one you would find that it's fields have been assigned numeric values.
These values are assigned from a static counter in `com.iciql.Utils.newObject()` during execution of the *db.from()* method.

For *Object* fields, these values are meaningless since objects are mapped by reference. These values do matter for *primitive* fields where they are mapped by value. If your statement is a query, like in the above example, iciql will generate new instances of your *alias* model class and return them as a list where each entry of the list represents a row from the JDBC `ResultSet`. diff --git a/docs/05_releases.mkd b/docs/05_releases.mkd index 22ebb2e..3266ba9 100644 --- a/docs/05_releases.mkd +++ b/docs/05_releases.mkd @@ -7,6 +7,7 @@ **%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%* - api change release (API v4) +- don't INSERT primitive autoIncrement primaryKey fields, let database assign value - full support for primitives in all clauses - DECIMAL(length, scale) support - unspecified length String fields are now CLOB instead of TEXT. dialects can intercept this and convert to another type. e.g. MySQL dialect can change CLOB to TEXT. -- cgit v1.2.3