aboutsummaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/iciql/Iciql.java53
-rw-r--r--src/com/iciql/ModelUtils.java13
-rw-r--r--src/com/iciql/TableDefinition.java3
-rw-r--r--src/com/iciql/util/Utils.java8
4 files changed, 49 insertions, 28 deletions
diff --git a/src/com/iciql/Iciql.java b/src/com/iciql/Iciql.java
index 6abe97d..64c2158 100644
--- a/src/com/iciql/Iciql.java
+++ b/src/com/iciql/Iciql.java
@@ -33,8 +33,9 @@ import java.lang.annotation.Target;
* If a class is annotated with IQTable and at the same time implements Table,
* the define() method is not called.
* <p>
- * Supported data types:
+ * Fully Supported Data Types:
* <table>
+ * <tr><th colspan="2">All Databases</th></tr>
* <tr>
* <td>java.lang.String</td>
* <td>VARCHAR (length > 0) or TEXT (length == 0)</td>
@@ -88,13 +89,9 @@ import java.lang.annotation.Target;
* <td>TIMESTAMP</td>
* </tr>
* <tr>
- * <td>byte []</td>
- * <td>BLOB</td>
- * </tr>
- * <tr>
* <td>java.lang.Enum.name()</td>
* <td>VARCHAR (length > 0) or TEXT (length == 0)<br/>
- * EnumType.STRING</td>
+ * EnumType.NAME</td>
* </tr>
* <tr>
* <td>java.lang.Enum.ordinal()</td>
@@ -107,10 +104,36 @@ import java.lang.annotation.Target;
* <td>INT<br/>
* EnumType.ENUMID</td>
* </tr>
+ * <tr><th colspan="2">H2 Databases</th></tr>
+ * <tr>
+ * <td>java.util.UUID</td>
+ * <td>UUID</td>
* </tr>
* </table>
* <p>
- * Unsupported data types: primitives, Array Types, and custom types.
+ * Partially Supported Data Types:
+ * <p>
+ * The following data types can be mapped to columns for all general statements
+ * BUT these field types may not be used to specify compile-time clauses or
+ * constraints.
+ * <table>
+ * <tr><td>byte []</td>
+ * <td>BLOB</td></tr>
+ * <tr><td>boolean</td>
+ * <td>BIT</td></tr>
+ * <tr><td>byte</td>
+ * <td>TINYINT</td></tr>
+ * <tr><td>short</td>
+ * <td>SMALLINT</td></tr>
+ * <tr><td>int</td>
+ * <td>INT</td></tr>
+ * <tr><td>long</td>
+ * <td>BIGINT</td></tr>
+ * <tr><td>float</td>
+ * <td>REAL</td></tr>
+ * <tr><td>double</td>
+ * <td>DOUBLE</td></tr>
+ * </table>
* <p>
* Table and field mapping: by default, the mapped table name is the class name
* and the public fields are reflectively mapped, by their name, to columns. As
@@ -403,7 +426,7 @@ public interface Iciql {
* Enumeration representing how to map a java.lang.Enum to a column.
* <p>
* <ul>
- * <li>STRING - name() : string
+ * <li>NAME - name() : string
* <li>ORDINAL - ordinal() : int
* <li>ENUMID - enumId() : int
* </ul>
@@ -411,7 +434,9 @@ public interface Iciql {
* @see com.iciql.Iciql.EnumId interface
*/
public enum EnumType {
- STRING, ORDINAL, ENUMID;
+ NAME, ORDINAL, ENUMID;
+
+ public static final EnumType DEFAULT_TYPE = NAME;
}
/**
@@ -427,20 +452,20 @@ public interface Iciql {
* be overridden for an individual field by specifying the IQEnum
* annotation.
* <p>
- * The default mapping is by STRING.
+ * The default mapping is by NAME.
*
* <pre>
- * IQEnum(EnumType.STRING)
+ * IQEnum(EnumType.NAME)
* </pre>
*
- * A string mapping will generate either a VARCHAR, if IQColumn.length >
- * 0 or a TEXT column if IQColumn.length == 0
+ * A string mapping will generate either a VARCHAR, if IQColumn.length > 0
+ * or a TEXT column if IQColumn.length == 0
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.TYPE })
public @interface IQEnum {
- EnumType value() default EnumType.STRING;
+ EnumType value() default EnumType.NAME;
}
/**
diff --git a/src/com/iciql/ModelUtils.java b/src/com/iciql/ModelUtils.java
index 51c2d6c..4607e30 100644
--- a/src/com/iciql/ModelUtils.java
+++ b/src/com/iciql/ModelUtils.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;
+import com.iciql.Iciql.EnumType;
import com.iciql.TableDefinition.FieldDefinition;
import com.iciql.util.StringUtils;
@@ -150,18 +151,16 @@ class ModelUtils {
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)) {
diff --git a/src/com/iciql/TableDefinition.java b/src/com/iciql/TableDefinition.java
index f0ee4fa..f506484 100644
--- a/src/com/iciql/TableDefinition.java
+++ b/src/com/iciql/TableDefinition.java
@@ -293,6 +293,7 @@ class TableDefinition<T> {
// configure Java -> SQL enum mapping
if (f.getType().isEnum()) {
+ enumType = EnumType.DEFAULT_TYPE;
if (f.getType().isAnnotationPresent(IQEnum.class)) {
// enum definition is annotated for all instances
IQEnum iqenum = f.getType().getAnnotation(IQEnum.class);
@@ -343,7 +344,7 @@ class TableDefinition<T> {
// convert enumeration to INT or STRING
Enum<?> iqenum = (Enum<?>) value;
switch (field.enumType) {
- case STRING:
+ case NAME:
if (field.trimString && field.maxLength > 0) {
if (iqenum.name().length() > field.maxLength) {
return iqenum.name().substring(0, field.maxLength);
diff --git a/src/com/iciql/util/Utils.java b/src/com/iciql/util/Utils.java
index 3846c32..3237742 100644
--- a/src/com/iciql/util/Utils.java
+++ b/src/com/iciql/util/Utils.java
@@ -33,7 +33,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
@@ -162,8 +161,6 @@ public class Utils {
return clazz.getEnumConstants()[0];
} else if (clazz == java.util.UUID.class) {
return (T) UUID.randomUUID();
- } else if (clazz == List.class) {
- return (T) new ArrayList();
}
try {
return clazz.newInstance();
@@ -282,7 +279,7 @@ public class Utils {
}
public static Object convertEnum(Enum<?> o, EnumType type) {
- if (o == null || type == null) {
+ if (o == null) {
return null;
}
switch (type) {
@@ -294,7 +291,7 @@ public class Utils {
}
EnumId enumid = (EnumId) o;
return enumid.enumId();
- case STRING:
+ case NAME:
default:
return o.name();
}
@@ -308,7 +305,6 @@ public class Utils {
if (targetType.isAssignableFrom(currentType)) {
return o;
}
-
// convert from VARCHAR/TEXT/INT to Enum
Enum<?>[] values = (Enum[]) targetType.getEnumConstants();
if (Clob.class.isAssignableFrom(currentType)) {