diff options
author | James Moger <james.moger@gmail.com> | 2011-08-30 19:26:27 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-30 19:26:27 -0400 |
commit | 69f2302c957a737564988aff2d9ae7b66287fe9d (patch) | |
tree | 7a454ca375a961b4fca57e275c37c348d2cb5181 /docs | |
parent | 5b1113a29cc76253351616a9893b486b2996ea85 (diff) | |
download | iciql-69f2302c957a737564988aff2d9ae7b66287fe9d.tar.gz iciql-69f2302c957a737564988aff2d9ae7b66287fe9d.zip |
Undeprecated interface configuration. Added more Define methods.
I've revised my thinking about interface configuration. I think its a
good option and should be supported. Field scope is now ignored across
the board. If the developer does not want to map a field and is using
the interface configuration approach, then the field should be annotated
with IQIgnore.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/01_model_classes.mkd | 120 | ||||
-rw-r--r-- | docs/05_releases.mkd | 14 | ||||
-rw-r--r-- | docs/06_jaqu_comparison.mkd | 9 |
3 files changed, 126 insertions, 17 deletions
diff --git a/docs/01_model_classes.mkd b/docs/01_model_classes.mkd index 94fdcc2..5babdcc 100644 --- a/docs/01_model_classes.mkd +++ b/docs/01_model_classes.mkd @@ -1,15 +1,15 @@ ## Model Classes
A model class represents a single table within your database. Fields within your model class represent columns in the table. The object types of your fields are reflectively mapped to SQL types by iciql at runtime.
-Models can be manually written using one of two approaches: *annotation configuration* or *interface configuration*. Both approaches can be used within a project and both can be used within a single model class, although that is discouraged.
+Models can be manually written using one of three approaches: *annotation configuration*, *interface configuration*, or *POJO configuration*. All approaches can be used within a project and all can be used within a single model class, although that is discouraged.
Alternatively, model classes can be automatically generated by iciql using the model generation tool. Please see the [tools](tools.html) page for details.
### Configuration Requirements and Limitations
1. Your model class **must** provide a public default constructor.
-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)*.
+2. All **Object** fields are assumed NULLABLE unless explicitly set *@IQColumn(nullable = false)* or *Define.nullable(field, false)*.
+3. All **Primitive** fields are assumed NOT NULLABLE unless explicitly set *@IQColumn(nullable = true)* or *Define.nullable(field, 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.
@@ -89,8 +89,6 @@ The recommended approach to setup a model class is to annotate the class and fie ### advantages
-- annotated fields may have any scope
-- annotated fields may specify default values
- annotated models support annotated field inheritance making it possible to design a single base class that defines the fields and then create table subclasses that specify the table mappings.
- model runtime dependency is limited to the small, portable `com.iciql.Iciql` class file which contains the annotation definitions
@@ -100,9 +98,15 @@ The recommended approach to setup a model class is to annotate the class and fie - indexes are defined using "fragile" string column names
- compound primary keys are defined using "fragile" string column names
+### field mapping
+
+- By default, **ONLY** fields annotated with *@IQColumn* are mapped.<br/>
+- scope is irrelevant.<br/>
+- transient is irrelevant.
+
### default values
-You may specify default values for an @IQColumn by either:
+You may specify default values for an *@IQColumn* by either:
1. specifying the default value string within your annotation<br/>
**NOTE:**<br/>
@@ -123,7 +127,7 @@ Date myDate = new Date(100, 0, 1); 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.
+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%
@@ -173,6 +177,9 @@ public class Product { @IQColumn
private Availability availability;
+
+ // ignored because it is not annotated AND the class is @IQTable annotated
+ private Integer ignoredField;
public Product() {
// default constructor
@@ -180,16 +187,20 @@ public class Product { }
%ENDCODE%
-## Interface Configuration (deprecated)
-Alternatively, you may map your model classes using the original JaQu interface approach by implementing the `com.iciql.Iciql` interface.
+## Interface Configuration
+Alternatively, you may map your model classes using the interface approach by implementing the `com.iciql.Iciql` interface.
This is a less verbose configuration style, but it comes at the expense of introducing a compile-time dependency on the logic of the iciql library. This might be a deterrent, for example, if you were serializing your model classes to another process that may not have the iciql library.
The `com.iciql.Iciql` interface specifies a single method, *defineIQ()*. In your implementation of *defineIQ()* you would use static method calls to set:
+- the schema name
- the table name (if it's not the class name)
- the column name (if it's not the field name)
-- the max length of a string field
+- the max length and trim of a string field
+- the precision and scale of a decimal field
+- the autoincrement flag of a long or integer field
+- the nullable flag of a field
- the primaryKey (single field or compound)
- any indexes (single field or compound)
@@ -201,13 +212,43 @@ The `com.iciql.Iciql` interface specifies a single method, *defineIQ()*. In you ### disadvantages
-- <u>only **public** fields of the model class are reflectively mapped as columns</u>. all other scoped fields and inherited fields are ignored.
- model runtime dependency on entire iciql library
- *defineIQ()* is called from a static synchronized block which may be a bottleneck for highly concurrent systems
+### field mapping
+
+- **ALL** fields are mapped unless annotated with *@IQIgnore*.<br/>
+- scope is irrelevant.<br/>
+- transient is irrelevant.
+
+### default values
+
+You may specify default values for an field by either:
+
+1. specifying the default value string within your *defineIQ()* method<br/>
+**NOTE:**<br/>
+The defineIQ() value always takes priority over a field default value.
+%BEGINCODE%
+Date myDate;
+
+public void defineIQ() {
+ // notice the single ticks!
+ Define.defaultValue(myDate, "'2000-01-01 00:00:00'");
+}
+%ENDCODE%
+2. setting a default value on the field<br/>
+**NOTE:**<br/>
+Primitive types have an implicit default value of *0* or *false*.
+%BEGINCODE%
+Date myDate = new Date(100, 0, 1);
+
+int myId;
+%ENDCODE%
+
### Example Interface Model
%BEGINCODE%
import com.iciql.Iciql;
+import com.iciql.Iciql.IQIgnore;
public class Product implements Iciql {
public Integer productId;
@@ -216,7 +257,7 @@ public class Product implements Iciql { public Double unitPrice;
public Integer unitsInStock;
- // this field is ignored because it is not public
+ @IQIgnore
Integer reorderQuantity;
public Product() {
@@ -231,4 +272,59 @@ public class Product implements Iciql { com.iciql.Define.index(productName, category);
}
}
+%ENDCODE%
+
+## POJO (Plain Old Java Object) Configuration
+
+This approach is very similar to the *interface configuration* approach; it is the least verbose and also the least useful.
+
+This approach would be suitable for quickly modeling an existing table where only SELECT and INSERT statements will be generated.
+
+### advantages
+
+- nearly zero-configuration
+
+### disadvantages
+
+- can not execute DELETE, UPDATE, or MERGE statements (they require a primary key specification)
+- table name MUST MATCH model class name
+- column names MUST MATCH model field names
+- can not specify any column attributes
+- can not specify indexes
+
+### field mapping
+
+- **ALL** fields are mapped unless annotated with *@IQIgnore*.<br/>
+- scope is irrelevant.<br/>
+- transient is irrelevant.
+
+### default values
+
+You may specify a default value on the field.
+
+**NOTE:**<br/>
+Primitive types have an implicit default value of *0* or *false*.
+%BEGINCODE%
+Date myDate = new Date(100, 0, 1);
+
+int myId;
+%ENDCODE%
+
+### Example POJO Model
+%BEGINCODE%
+import com.iciql.Iciql.IQIgnore;
+
+public class Product {
+ public Integer productId;
+ public String productName;
+ public String category;
+ public Double unitPrice;
+ public Integer units;
+
+ @IQIgnore
+ Integer reorderQuantity;
+
+ public Product() {
+ }
+}
%ENDCODE%
\ No newline at end of file diff --git a/docs/05_releases.mkd b/docs/05_releases.mkd index bd3c853..3d50a5b 100644 --- a/docs/05_releases.mkd +++ b/docs/05_releases.mkd @@ -6,6 +6,18 @@ **%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 v7)
+- Undeprecated interface configuration
+- Interface configuration now maps ALL fields, not just public fields
+- Added @IQIgnore annotation to explicitly skip fields for interface configuration
+- Created additional Define static methods to bring interface configuration to near-parity with annotation configuration
+- Documented POJO configuration option (limited subset of interface configuration)
+- Fix to PostgreSQL dialect when creating autoincrement columns
+
+### Older Releases
+
+**0.7.0** *released 2011-08-17*
+
- api change release (API v6)
- Finished MySQL dialect implementation. MySQL 5.0.51b passes 100% of tests.
- Added PostgreSQL dialect. PostgreSQL 9.0 passes all but the boolean-as-int tests.
@@ -15,8 +27,6 @@ - Added IciqlLogger.warn method
- Added IciqlLogger.drop method
-### Older Releases
-
**0.6.6** *released 2011-08-15*
- api change release (API v5)
diff --git a/docs/06_jaqu_comparison.mkd b/docs/06_jaqu_comparison.mkd index da7da41..33ca975 100644 --- a/docs/06_jaqu_comparison.mkd +++ b/docs/06_jaqu_comparison.mkd @@ -7,8 +7,8 @@ This is an overview of the fundamental differences between the original JaQu pro <tr><th></th><th>Iciql</th><th>JaQu</th></tr>
<tr><th colspan="3">core</th></tr>
<tr><td>deployment</td><td>small, discrete library</td><td>depends on H2 database jar file</td></tr>
-<tr><td>databases</td><td>supports H2, HSQL, Derby, MySQL, and PostreSQL</td><td>supports H2 only</td></tr>
-<tr><td>logging</td><td>supports console, SLF4J, or custom logging</td><td>supports console logging</td></tr>
+<tr><td>databases</td><td>H2, HSQL, Derby, MySQL, and PostreSQL</td><td>H2 only</td></tr>
+<tr><td>logging</td><td>console, SLF4J, or custom logging</td><td>console logging</td></tr>
<tr><td>exceptions</td><td>always includes generated statement in exception, when available</td><td>--</td></tr>
<tr><th colspan="3">syntax and api</th></tr>
<tr><td>dynamic queries</td><td>methods and where clauses for dynamic queries that build iciql objects</td><td>--</td></tr>
@@ -21,5 +21,8 @@ This is an overview of the fundamental differences between the original JaQu pro <tr><td>BOOLEAN</td><td>flexible mapping of boolean as bool, varchar, or int</td><td>--</td></tr>
<tr><td>BLOB</td><td>partially supported *(can not be used in a WHERE clause)*</td><td>--</td></tr>
<tr><td>UUID</td><td>fully supported *(H2 only)* </td><td>--</td></tr>
-<tr><td>DEFAULT values</td><td>set from annotations or *default object values*</td><td>set from annotations</td></tr>
+<tr><th colspan="3">configuration</th></tr>
+<tr><td>DEFAULT values</td><td>set from annotation, *default object values*, or Define.defaultValue()</td><td>set from annotations</td></tr>
+<tr><td>Interface Configuration<br/>Mapped Fields</td><td>*all fields* are mapped regardless of scope<br/>fields are ignored by annotating with @IQIgnore</td><td>*all public fields* are mapped<br/>fields are ignored by reducing their scope</td></tr>
+<tr><td>Index names</td><td>can be set</td><td>--</td></tr>
</table>
\ No newline at end of file |