diff options
author | James Moger <james.moger@gmail.com> | 2011-08-05 11:04:29 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-05 11:04:29 -0400 |
commit | b865898879f0d0eb1e752b41562b463b0c31c517 (patch) | |
tree | 08c7204795719e9ca554203bb1310c1724c4f205 /src/com | |
parent | a1ab11053107c8995b3f3e850fa14a2374c2013a (diff) | |
download | iciql-b865898879f0d0eb1e752b41562b463b0c31c517.tar.gz iciql-b865898879f0d0eb1e752b41562b463b0c31c517.zip |
Simplified annotations. Interchangeable int-boolean runtime mapping.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/iciql/Define.java | 2 | ||||
-rw-r--r-- | src/com/iciql/Iciql.java | 31 | ||||
-rw-r--r-- | src/com/iciql/Query.java | 1 | ||||
-rw-r--r-- | src/com/iciql/TableDefinition.java | 4 | ||||
-rw-r--r-- | src/com/iciql/TableInspector.java | 8 | ||||
-rw-r--r-- | src/com/iciql/util/Utils.java | 16 |
6 files changed, 42 insertions, 20 deletions
diff --git a/src/com/iciql/Define.java b/src/com/iciql/Define.java index 54e435f..d7b42ba 100644 --- a/src/com/iciql/Define.java +++ b/src/com/iciql/Define.java @@ -59,7 +59,7 @@ public class Define { currentTableDefinition.setColumnName(column, columnName);
}
- public static void maxLength(Object column, int length) {
+ public static void length(Object column, int length) {
checkInDefine();
currentTableDefinition.setMaxLength(column, length);
}
diff --git a/src/com/iciql/Iciql.java b/src/com/iciql/Iciql.java index ff2452e..6abe97d 100644 --- a/src/com/iciql/Iciql.java +++ b/src/com/iciql/Iciql.java @@ -37,7 +37,7 @@ import java.lang.annotation.Target; * <table>
* <tr>
* <td>java.lang.String</td>
- * <td>VARCHAR (maxLength > 0) or TEXT (maxLength == 0)</td>
+ * <td>VARCHAR (length > 0) or TEXT (length == 0)</td>
* </tr>
* <tr>
* <td>java.lang.Boolean</td>
@@ -93,15 +93,19 @@ import java.lang.annotation.Target; * </tr>
* <tr>
* <td>java.lang.Enum.name()</td>
- * <td>VARCHAR (maxLength > 0) or TEXT (maxLength == 0)<br/>EnumType.STRING</td>
+ * <td>VARCHAR (length > 0) or TEXT (length == 0)<br/>
+ * EnumType.STRING</td>
* </tr>
* <tr>
* <td>java.lang.Enum.ordinal()</td>
- * <td>INT<br/>EnumType.ORDINAL</td>
+ * <td>INT<br/>
+ * EnumType.ORDINAL</td>
* </tr>
* <tr>
- * <td>java.lang.Enum implements<br/>com.iciql.Iciql.EnumID.enumId()</td>
- * <td>INT<br/>EnumType.ENUMID</td>
+ * <td>java.lang.Enum implements<br/>
+ * com.iciql.Iciql.EnumID.enumId()</td>
+ * <td>INT<br/>
+ * EnumType.ENUMID</td>
* </tr>
* </tr>
* </table>
@@ -346,18 +350,18 @@ public interface Iciql { /**
* If larger than zero, it is used during the CREATE TABLE phase. It may
* also be used to prevent database exceptions on INSERT and UPDATE
- * statements (see trimString).
+ * statements (see trim).
* <p>
- * Any maxLength set in define() may override this annotation setting if
+ * Any length set in define() may override this annotation setting if
* the model class is not annotated with IQTable. Default: 0.
*/
- int maxLength() default 0;
+ int length() default 0;
/**
* If true, iciql will automatically trim the string if it exceeds
- * maxLength (value.substring(0, maxLength)). Default: false.
+ * length (value.substring(0, length)). Default: false.
*/
- boolean trimString() default false;
+ boolean trim() default false;
/**
* If false, iciql will set the column NOT NULL during the CREATE TABLE
@@ -403,7 +407,8 @@ public interface Iciql { * <li>ORDINAL - ordinal() : int
* <li>ENUMID - enumId() : int
* </ul>
- * @see com.iciql.Iciql.EnumId interface
+ *
+ * @see com.iciql.Iciql.EnumId interface
*/
public enum EnumType {
STRING, ORDINAL, ENUMID;
@@ -428,8 +433,8 @@ public interface Iciql { * IQEnum(EnumType.STRING)
* </pre>
*
- * A string mapping will generate either a VARCHAR, if IQColumn.maxLength >
- * 0 or a TEXT column if IQColumn.maxLength == 0
+ * A string mapping will generate either a VARCHAR, if IQColumn.length >
+ * 0 or a TEXT column if IQColumn.length == 0
*
*/
@Retention(RetentionPolicy.RUNTIME)
diff --git a/src/com/iciql/Query.java b/src/com/iciql/Query.java index d9dc84f..0611ffa 100644 --- a/src/com/iciql/Query.java +++ b/src/com/iciql/Query.java @@ -222,6 +222,7 @@ public class Query<T> { try {
X value;
Object o = rs.getObject(1);
+ // Convert CLOB and BLOB now because we close the resultset
if (Clob.class.isAssignableFrom(o.getClass())) {
value = (X) Utils.convert(o, String.class);
} else if (Blob.class.isAssignableFrom(o.getClass())) {
diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java index 72b5348..5d9b9c4 100644 --- a/src/com/iciql/TableDefinition.java +++ b/src/com/iciql/TableDefinition.java @@ -285,8 +285,8 @@ class TableDefinition<T> { }
isAutoIncrement = col.autoIncrement();
isPrimaryKey = col.primaryKey();
- maxLength = col.maxLength();
- trimString = col.trimString();
+ maxLength = col.length();
+ trimString = col.trim();
allowNull = col.allowNull();
defaultValue = col.defaultValue();
}
diff --git a/src/com/iciql/TableInspector.java b/src/com/iciql/TableInspector.java index 879e23a..82b732a 100644 --- a/src/com/iciql/TableInspector.java +++ b/src/com/iciql/TableInspector.java @@ -346,13 +346,13 @@ public class TableInspector { ap.addParameter("primaryKey=true"); } - // IQColumn.maxLength + // IQColumn.length if ((clazz == String.class) && (col.size > 0) && (col.size < Integer.MAX_VALUE)) { - ap.addParameter("maxLength", col.size); + ap.addParameter("length", col.size); - // IQColumn.trimStrings + // IQColumn.trim if (trimStrings) { - ap.addParameter("trimString=true"); + ap.addParameter("trim=true"); } } else { // IQColumn.AutoIncrement diff --git a/src/com/iciql/util/Utils.java b/src/com/iciql/util/Utils.java index 302dd4d..dac30fc 100644 --- a/src/com/iciql/util/Utils.java +++ b/src/com/iciql/util/Utils.java @@ -226,6 +226,22 @@ public class Utils { return o.toString();
}
+ // convert from number to boolean
+ if (Boolean.class.isAssignableFrom(targetType)) {
+ if (Number.class.isAssignableFrom(currentType)) {
+ Number n = (Number) o;
+ return n.intValue() > 0;
+ }
+ }
+
+ // convert from boolean to number
+ if (Boolean.class.isAssignableFrom(currentType)) {
+ if (Number.class.isAssignableFrom(targetType)) {
+ Boolean b = (Boolean) o;
+ return b ? 1 : 0;
+ }
+ }
+
// convert from number to number
if (Number.class.isAssignableFrom(currentType)) {
Number n = (Number) o;
|