From: James Moger Date: Tue, 9 Aug 2011 17:56:44 +0000 (-0400) Subject: All columns are assumed NULLABLE. IQColumn.allowNull->IQColumn.nullable X-Git-Tag: v0.6.4~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=01ec38ed904bd24c9075edfc12c2b41c1e13d249;p=iciql.git All columns are assumed NULLABLE. IQColumn.allowNull->IQColumn.nullable --- diff --git a/docs/01_model_classes.mkd b/docs/01_model_classes.mkd index 274cb92..bdddd80 100644 --- a/docs/01_model_classes.mkd +++ b/docs/01_model_classes.mkd @@ -8,8 +8,9 @@ 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. Only the specified types are supported. Other types such as arrays and custom types are not supported. -3. Triggers, views, and other advanced database features are not supported. +2. All columns are assumed NULLABLE unless explicitly set *@IQColumn(nullable = false)*. +3. Only the specified types are supported. Other types such as arrays and custom types are not supported. +4. Triggers, views, and other advanced database features are not supported. ### Fully Supported Data Types The following data types can be used for all iciql expressions. diff --git a/docs/05_releases.mkd b/docs/05_releases.mkd index 8d1295b..e889f2f 100644 --- a/docs/05_releases.mkd +++ b/docs/05_releases.mkd @@ -7,6 +7,8 @@ **%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) +- @IQColumn(allowNull=true) -> @IQColumn(nullable=true) +- All columns are assumed NULLABLE unless explicitly set *@IQColumn(nullable = false)* - allow using objects to assign default values
%BEGINCODE% // CREATE TABLE ... myDate DATETIME DEFAULT '2000-02-01 00:00:00' diff --git a/src/com/iciql/Db.java b/src/com/iciql/Db.java index 621e825..cae384d 100644 --- a/src/com/iciql/Db.java +++ b/src/com/iciql/Db.java @@ -236,7 +236,7 @@ public class Db { DbVersion v = new DbVersion(); DbVersion dbVersion = // (SCHEMA="" && TABLE="") == DATABASE - from(v).where(v.schema).is("").and(v.table).is("").selectFirst(); + from(v).where(v.schemaName).is("").and(v.tableName).is("").selectFirst(); if (dbVersion == null) { // database has no version registration, but model specifies // version: insert DbVersion entry and return. @@ -268,14 +268,14 @@ public class Db { // table is using iciql version tracking. DbVersion v = new DbVersion(); String schema = StringUtils.isNullOrEmpty(model.schemaName) ? "" : model.schemaName; - DbVersion dbVersion = from(v).where(v.schema).like(schema).and(v.table).like(model.tableName) + DbVersion dbVersion = from(v).where(v.schemaName).like(schema).and(v.tableName).like(model.tableName) .selectFirst(); if (dbVersion == null) { // table has no version registration, but model specifies // version: insert DbVersion entry DbVersion newTable = new DbVersion(model.tableVersion); - newTable.schema = schema; - newTable.table = model.tableName; + newTable.schemaName = schema; + newTable.tableName = model.tableName; insert(newTable); } else { // table has a version registration: diff --git a/src/com/iciql/DbVersion.java b/src/com/iciql/DbVersion.java index 2a8aa44..8ccf66f 100644 --- a/src/com/iciql/DbVersion.java +++ b/src/com/iciql/DbVersion.java @@ -26,13 +26,13 @@ import com.iciql.Iciql.IQTable; @IQTable(name = "_iq_versions", primaryKey = { "schemaName", "tableName"}, memoryTable = true) public class DbVersion { - @IQColumn(name = "schemaName", length = 255, allowNull = false) - String schema = ""; + @IQColumn(length = 255) + String schemaName = ""; - @IQColumn(name = "tableName", length = 255, allowNull = false) - String table = ""; + @IQColumn(length = 255) + String tableName = ""; - @IQColumn(name = "version") + @IQColumn Integer version; public DbVersion() { @@ -47,8 +47,8 @@ public class DbVersion { * the database version */ public DbVersion(int version) { - this.schema = ""; - this.table = ""; + this.schemaName = ""; + this.tableName = ""; this.version = version; } diff --git a/src/com/iciql/Iciql.java b/src/com/iciql/Iciql.java index 2eaf783..40c412a 100644 --- a/src/com/iciql/Iciql.java +++ b/src/com/iciql/Iciql.java @@ -408,9 +408,9 @@ public interface Iciql { /** * If false, iciql will set the column NOT NULL during the CREATE TABLE - * phase. Default: false. + * phase. Default: true. */ - boolean allowNull() default false; + boolean nullable() default true; /** * The default value assigned to the column during the CREATE TABLE diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java index 6e25c91..eb018bc 100644 --- a/src/com/iciql/TableDefinition.java +++ b/src/com/iciql/TableDefinition.java @@ -75,7 +75,7 @@ public class TableDefinition { boolean isPrimaryKey; boolean isAutoIncrement; boolean trimString; - boolean allowNull; + boolean nullable; String defaultValue; EnumType enumType; @@ -275,7 +275,7 @@ public class TableDefinition { boolean isPrimaryKey = false; int maxLength = 0; boolean trimString = false; - boolean allowNull = true; + boolean nullable = true; EnumType enumType = null; String defaultValue = ""; // configure Java -> SQL enum mapping @@ -303,7 +303,7 @@ public class TableDefinition { isPrimaryKey = col.primaryKey(); maxLength = col.length(); trimString = col.trim(); - allowNull = col.allowNull(); + nullable = col.nullable(); // try using default object try { @@ -340,7 +340,7 @@ public class TableDefinition { fieldDef.isPrimaryKey = isPrimaryKey; fieldDef.maxLength = maxLength; fieldDef.trimString = trimString; - fieldDef.allowNull = allowNull; + fieldDef.nullable = nullable; fieldDef.defaultValue = defaultValue; fieldDef.enumType = enumType; fieldDef.dataType = ModelUtils.getDataType(fieldDef, strictTypeMapping); @@ -562,7 +562,7 @@ public class TableDefinition { buff.append(" AUTO_INCREMENT"); } - if (!field.allowNull) { + if (!field.nullable) { buff.append(" NOT NULL"); } diff --git a/src/com/iciql/TableInspector.java b/src/com/iciql/TableInspector.java index 6ec848d..51b2d69 100644 --- a/src/com/iciql/TableInspector.java +++ b/src/com/iciql/TableInspector.java @@ -139,7 +139,7 @@ public class TableInspector { col.type = rs.getString("TYPE_NAME"); col.clazz = ModelUtils.getClassForSqlType(col.type, dateTimeClass); col.size = rs.getInt("COLUMN_SIZE"); - col.allowNull = rs.getInt("NULLABLE") == DatabaseMetaData.columnNullable; + col.nullable = rs.getInt("NULLABLE") == DatabaseMetaData.columnNullable; col.isAutoIncrement = rs.getBoolean("IS_AUTOINCREMENT"); if (primaryKeys.size() == 1) { if (col.name.equalsIgnoreCase(primaryKeys.get(0))) { @@ -158,7 +158,7 @@ public class TableInspector { /** * Generates a model (class definition) from this table. The model includes - * indexes, primary keys, default values, maxLengths, and allowNull + * indexes, primary keys, default values, lengths, and nullables. * information. *

* The caller may optionally set a destination package name, whether or not @@ -369,9 +369,9 @@ public class TableInspector { } } - // IQColumn.allowNull - if (!col.allowNull) { - ap.addParameter("allowNull=false"); + // IQColumn.nullable + if (!col.nullable) { + ap.addParameter("nullable=false"); } // IQColumn.defaultValue @@ -622,7 +622,7 @@ public class TableInspector { String name; String type; int size; - boolean allowNull; + boolean nullable; Class clazz; boolean isPrimaryKey; boolean isAutoIncrement; diff --git a/tests/com/iciql/test/ModelsTest.java b/tests/com/iciql/test/ModelsTest.java index d5edcfd..652bc4f 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(1780, models.get(0).length()); + assertEquals(1456, models.get(0).length()); } @Test diff --git a/tests/com/iciql/test/models/DefaultValuesModel.java b/tests/com/iciql/test/models/DefaultValuesModel.java index 2669257..ab09186 100644 --- a/tests/com/iciql/test/models/DefaultValuesModel.java +++ b/tests/com/iciql/test/models/DefaultValuesModel.java @@ -50,7 +50,7 @@ public class DefaultValuesModel { @IQEnum(EnumType.ORDINAL) public Tree myOrdinalTree = Tree.PINE; - @IQColumn(allowNull = true) + @IQColumn(nullable = true) public Tree myNullTree; public DefaultValuesModel() {