From 6a02a8d69f048592b14db0cfbf412b2fe0db9b24 Mon Sep 17 00:00:00 2001
From: rbygrave
+ * When all the scalar values have been collected then the compound value
+ * object is built and this can be recursive for nested compound types.
+ *
- * When all the scalar values have been collected then the compound value
- * object is built and this can be recursive for nested compound types.
- *
- * If allowNulls is false then an IllegalArgumentException is thrown by - * either the getDBValue or getBeanValue methods if not matching Bean or DB - * value is found. - *
- */ - public EnumToDbValueMap(boolean allowNulls, boolean isIntegerType) { - this.allowNulls = allowNulls; - this.isIntegerType = isIntegerType; - keyMap = new LinkedHashMap+ * If allowNulls is false then an IllegalArgumentException is thrown by + * either the getDBValue or getBeanValue methods if not matching Bean or DB + * value is found. + *
+ */ + public EnumToDbValueMap(boolean allowNulls, boolean isIntegerType) { + this.allowNulls = allowNulls; + this.isIntegerType = isIntegerType; + keyMap = new LinkedHashMap+ * The dbValue will be converted to an Integer if isIntegerType is true; + *
+ */ + protected void addInternal(Object beanValue, T dbValue) { - /** - * Add a bean value and DB value pair. - *- * The dbValue will be converted to an Integer if isIntegerType is true; - *
- */ - protected void addInternal(Object beanValue, T dbValue) { + keyMap.put(beanValue, dbValue); + valueMap.put(dbValue, beanValue); + } - keyMap.put(beanValue, dbValue); - valueMap.put(dbValue, beanValue); - } + /** + * Return the DB value given the bean value. + */ + public T getDbValue(Object beanValue) { + if (beanValue == null) { + return null; + } + T dbValue = keyMap.get(beanValue); + if (dbValue == null && !allowNulls) { + String msg = "DB value for " + beanValue + " not found in " + keyMap; + throw new IllegalArgumentException(msg); + } + return dbValue; + } - /** - * Return the DB value given the bean value. - */ - public T getDbValue(Object beanValue) { - if (beanValue == null) { - return null; - } - T dbValue = keyMap.get(beanValue); - if (dbValue == null && !allowNulls) { - String msg = "DB value for " + beanValue + " not found in " + keyMap; - throw new IllegalArgumentException(msg); - } - return dbValue; - } - - /** - * Return the Bean value given the DB value. - */ - public Object getBeanValue(T dbValue) { - if (dbValue == null) { - return null; - } - Object beanValue = valueMap.get(dbValue); - if (beanValue == null && !allowNulls) { - String msg = "Bean value for " + dbValue + " not found in " + valueMap; - throw new IllegalArgumentException(msg); - } - return beanValue; - } + /** + * Return the Bean value given the DB value. + */ + public Object getBeanValue(T dbValue) { + if (dbValue == null) { + return null; + } + Object beanValue = valueMap.get(dbValue); + if (beanValue == null && !allowNulls) { + String msg = "Bean value for " + dbValue + " not found in " + valueMap; + throw new IllegalArgumentException(msg); + } + return beanValue; + } } diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/LongToTimestampConverter.java b/src/main/java/com/avaje/ebeaninternal/server/type/LongToTimestampConverter.java index 10309d393..b34226875 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/LongToTimestampConverter.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/LongToTimestampConverter.java @@ -4,21 +4,21 @@ import java.sql.Timestamp; import com.avaje.ebean.config.ScalarTypeConverter; -public class LongToTimestampConverter implements ScalarTypeConverter- * If a BeanProperty has no explicit length defined then this length should - * be assigned. - *
- *- * This is primarily to support defining a length on Enum types (to - * supplement defining the length on the BeanProperty directly). - *
- */ - public int getLength(); + boolean isDirty(Object value); - /** - * Return true if the type is native to JDBC. - *- * If it is native to JDBC then its values/instances do not need to be - * converted to and from an associated JDBC type. - *
- */ - public boolean isJdbcNative(); + /** + * Return the default DB column length for this type. + *+ * If a BeanProperty has no explicit length defined then this length should + * be assigned. + *
+ *+ * This is primarily to support defining a length on Enum types (to + * supplement defining the length on the BeanProperty directly). + *
+ */ + int getLength(); - /** - * Return the type as per java.sql.Types that this maps to. - *- * This type should be consistent with the toJdbcType() method in converting - * the type to the appropriate type for binding to preparedStatements. - *
- */ - public int getJdbcType(); + /** + * Return true if the type is native to JDBC. + *+ * If it is native to JDBC then its values/instances do not need to be + * converted to and from an associated JDBC type. + *
+ */ + boolean isJdbcNative(); - /** - * Return the type that matches the bean property type. - *- * This represents the 'logical' type rather than the JDBC type this maps - * to. - *
- */ - public Class+ * This type should be consistent with the toJdbcType() method in converting + * the type to the appropriate type for binding to preparedStatements. + *
+ */ + int getJdbcType(); - /** - * Read the value from the resultSet and convert if necessary to the logical - * bean property value. - */ - public T read(DataReader dataReader) throws SQLException; + /** + * Return the type that matches the bean property type. + *+ * This represents the 'logical' type rather than the JDBC type this maps + * to. + *
+ */ + Class- * value may need to be converted from the logical bean property type to the - * JDBC type. - *
- */ - public void bind(DataBind b, T value) throws SQLException; + /** + * Ignore the reading of this value. Typically this means moving the index + * position in the ResultSet. + */ + void loadIgnore(DataReader dataReader); - /** - * Convert the value as necessary to the JDBC type. - *- * Note that this should also match the type as per the getJdbcType() - * method. - *
- *- * This is typically used when the matching type is used in a where clause - * and we use this to ensure it is an appropriate jdbc type. - *
- */ - public Object toJdbcType(Object value); + /** + * Convert (if necessary) and bind the value to the preparedStatement. + *+ * value may need to be converted from the logical bean property type to the + * JDBC type. + *
+ */ + void bind(DataBind b, T value) throws SQLException; - /** - * Convert the value as necessary to the logical Bean type. - *- * The type as per the bean property. - *
- *- * This is used to automatically convert id values (typically from a string - * to a int, long or UUID). - *
- */ - public T toBeanType(Object value); + /** + * Convert the value as necessary to the JDBC type. + *+ * Note that this should also match the type as per the getJdbcType() + * method. + *
+ *+ * This is typically used when the matching type is used in a where clause + * and we use this to ensure it is an appropriate jdbc type. + *
+ */ + Object toJdbcType(Object value); - /** - * Convert the type into a string representation. - *- * Reciprocal of parse(). - *
- */ - public String formatValue(T v); + /** + * Convert the value as necessary to the logical Bean type. + *+ * The type as per the bean property. + *
+ *+ * This is used to automatically convert id values (typically from a string + * to a int, long or UUID). + *
+ */ + T toBeanType(Object value); - /** - * Convert the type into a string representation. - *- * This assumes the value is of the correct type. - *
- *- * This is so that ScalarType also implements the StringFormatter interface. - *
- */ - public String format(Object v); + /** + * Convert the type into a string representation. + *+ * Reciprocal of parse(). + *
+ */ + String formatValue(T v); - /** - * Convert the string value to the appropriate java object. - *- * Mostly used to support CSV, JSON and XML parsing. - *
- *- * Reciprocal of formatValue(). - *
- */ - public T parse(String value); + /** + * Convert the type into a string representation. + *+ * This assumes the value is of the correct type. + *
+ *+ * This is so that ScalarType also implements the StringFormatter interface. + *
+ */ + String format(Object v); - /** - * Return true if the type can accept long systemTimeMillis input. - *- * This is used to determine if is is sensible to use the - * {@link #convertFromMillis(long)} method. - *
- *- * This includes the Date, Calendar, sql Date, Time, Timestamp, JODA types - * as well as Long, BigDecimal and String (although it generally is not - * expected to parse systemTimeMillis to a String or BigDecimal). - *
- */ - public boolean isDateTimeCapable(); + /** + * Convert the string value to the appropriate java object. + *+ * Mostly used to support CSV, JSON and XML parsing. + *
+ *+ * Reciprocal of formatValue(). + *
+ */ + T parse(String value); + + /** + * Return true if the type can accept long systemTimeMillis input. + *+ * This is used to determine if is is sensible to use the + * {@link #convertFromMillis(long)} method. + *
+ *+ * This includes the Date, Calendar, sql Date, Time, Timestamp, JODA types + * as well as Long, BigDecimal and String (although it generally is not + * expected to parse systemTimeMillis to a String or BigDecimal). + *
+ */ + boolean isDateTimeCapable(); /** * Convert the systemTimeMillis into the appropriate java object. @@ -182,26 +182,26 @@ public interface ScalarType
* Sometimes booleans may be mapped to the JDBC type BIT. To use the BitBoolean specify
* type.boolean.dbtype="bit" in the ebean configuration
@@ -143,11 +143,7 @@ public class ScalarTypeBoolean {
return null;
}
Boolean b = (Boolean) value;
- if (b.booleanValue()) {
- return trueValue;
- } else {
- return falseValue;
- }
+ return b ? trueValue : falseValue;
}
/**
@@ -222,11 +218,7 @@ public class ScalarTypeBoolean {
return null;
}
Boolean b = (Boolean) value;
- if (b.booleanValue()) {
- return trueValue;
- } else {
- return falseValue;
- }
+ return b ? trueValue : falseValue;
}
/**
@@ -293,7 +285,7 @@ public class ScalarTypeBoolean {
}
public void jsonWrite(JsonGenerator ctx, String name, Boolean value) throws IOException {
- ctx.writeBooleanField(name, (Boolean) value);
+ ctx.writeBooleanField(name, value);
}
}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBase.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBase.java
index 0fa8c65a0..405672490 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBase.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBase.java
@@ -20,10 +20,6 @@ public abstract class ScalarTypeBytesBase extends ScalarTypeBase
- * Stored in the DB as DECIMAL value.
+ * Stored in the DB as DECIMAL value.
*