diff options
author | James Moger <james.moger@gmail.com> | 2011-08-09 11:28:48 -0400 |
---|---|---|
committer | James Moger <james.moger@gmail.com> | 2011-08-09 11:28:48 -0400 |
commit | 1a2339a9f1f96ddca64ab392dd7f9e1621e6c201 (patch) | |
tree | 413631f6e46e2bb2826e67f98df5b5180468833b /src/com/iciql/ModelUtils.java | |
parent | fec6df5eaac334540e220d7f7c05c9d21357f554 (diff) | |
download | iciql-1a2339a9f1f96ddca64ab392dd7f9e1621e6c201.tar.gz iciql-1a2339a9f1f96ddca64ab392dd7f9e1621e6c201.zip |
IQTable.primaryKey is now an array. Default values from objects.
Also fixed an error with allowing null objects. Noted rapid churn of
iciql in documentation. Changed build constants for next release.
Diffstat (limited to 'src/com/iciql/ModelUtils.java')
-rw-r--r-- | src/com/iciql/ModelUtils.java | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/com/iciql/ModelUtils.java b/src/com/iciql/ModelUtils.java index 579c7f6..2e42a7d 100644 --- a/src/com/iciql/ModelUtils.java +++ b/src/com/iciql/ModelUtils.java @@ -21,14 +21,16 @@ import static com.iciql.util.StringUtils.isNullOrEmpty; import java.lang.reflect.Method; import java.math.BigDecimal; +import java.text.MessageFormat; +import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Date; import java.util.HashMap; import java.util.List; 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; @@ -61,7 +63,7 @@ class ModelUtils { m.put(java.sql.Time.class, "TIME"); m.put(byte[].class, "BLOB"); m.put(UUID.class, "UUID"); - + // map primitives m.put(boolean.class, m.get(Boolean.class)); m.put(byte.class, m.get(Byte.class)); @@ -201,9 +203,9 @@ class ModelUtils { // do not map from SQL TYPE to primitive type continue; } - if (SUPPORTED_TYPES.get(clazz).equalsIgnoreCase(sqlType)) { + if (SUPPORTED_TYPES.get(clazz).equalsIgnoreCase(sqlType)) { mappedClass = clazz; - + break; } } @@ -253,6 +255,41 @@ class ModelUtils { } /** + * Converts the object into a DEFAULT clause value. + * + * @param o + * the default object + * @return the value formatted for a DEFAULT clause + */ + static String formatDefaultValue(Object o) { + Class<?> objectClass = o.getClass(); + String value = null; + if (Number.class.isAssignableFrom(objectClass)) { + // NUMBER + value = ((Number) o).toString(); + } else if (java.sql.Date.class.isAssignableFrom(objectClass)) { + // DATE + value = new SimpleDateFormat("yyyy-MM-dd").format((Date) o); + } else if (java.sql.Time.class.isAssignableFrom(objectClass)) { + // TIME + value = new SimpleDateFormat("HH:mm:ss").format((Date) o); + } else if (Date.class.isAssignableFrom(objectClass)) { + // DATETIME + value = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((Date) o); + } else if (String.class.isAssignableFrom(objectClass)) { + // STRING + value = o.toString(); + } else if (Boolean.class.isAssignableFrom(objectClass)) { + // BOOLEAN + value = o.toString(); + } + if (value == null) { + return "''"; + } + return MessageFormat.format("''{0}''", value); + } + + /** * Checks the formatting of IQColumn.defaultValue(). * * @param defaultValue |