- * 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();
-
- /**
- * 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 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 the type that matches the bean property type.
- *
- * This represents the 'logical' type rather than the JDBC type this maps
- * to.
- *
- */
- public Class getType();
-
- /**
- * Read the value from the resultSet and convert if necessary to the logical
- * bean property value.
- */
- public T read(DataReader dataReader) throws SQLException;
-
- /**
- * Ignore the reading of this value. Typically this means moving the index
- * position in the ResultSet.
- */
- public void loadIgnore(DataReader dataReader);
-
- /**
- * 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.
- *
- */
- public void bind(DataBind b, T value) throws SQLException;
-
- /**
- * 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 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 type into a string representation.
- *
- * Reciprocal of parse().
- *
- */
- public String formatValue(T v);
-
- /**
- * 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 string value to the appropriate java object.
- *
- * Mostly used to support CSV, JSON and XML parsing.
- *
- *
- * Reciprocal of formatValue().
- *
- */
- public 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).
- *
- */
- public boolean isDateTimeCapable();
-
- /**
- * Convert the systemTimeMillis into the appropriate java object.
- *
- * For non dateTime types this will throw an exception.
- *
- */
- public T convertFromMillis(long dateTime);
-
- /**
- * Read the value from binary input.
- */
- public T readData(DataInput dataInput) throws IOException;
-
- /**
- * Write the value to binary output.
- */
- public void writeData(DataOutput dataOutput, T v) throws IOException;
-
- /**
- * Read the value from JsonParser.
- */
- public T jsonRead(JsonParser ctx, JsonToken event) throws IOException;
-
- /**
- * Write the value to the JsonGenerator.
- */
- public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException;
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import com.avaje.ebean.text.StringFormatter;
+import com.avaje.ebean.text.StringParser;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * Describes a scalar type.
+ *
+ * Scalar in the sense that the types are not compound types. Scalar types only
+ * map to a single database column.
+ *
+ *
+ * These types fall into two categories. Types that are mapped natively to JDBC
+ * types and the rest. Types that map to native JDBC types do not require any
+ * data type conversion to be persisted to the database. These are java types
+ * that map via java.sql.Types.
+ *
+ *
+ * Types that are not native to JDBC require some conversion. These include some
+ * common java types such as java.util.Date, java.util.Calendar,
+ * java.math.BigInteger.
+ *
+ *
+ * Note that Booleans may be native for some databases and require conversion on
+ * other databases.
+ *
+ */
+public interface ScalarType extends StringParser, StringFormatter, ScalarDataReader {
+
+ /**
+ * Return true if this is a mutable scalar type (like hstore).
+ */
+ public boolean isMutable();
+
+ /**
+ * For mutable scalarType's return true if the value is dirty.
+ * Non-dirty properties may be excluded from updates.
+ */
+ public boolean isDirty(Object value);
+
+ /**
+ * 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).
+ *
+ */
+ public int getLength();
+
+ /**
+ * 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 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 the type that matches the bean property type.
+ *
+ * This represents the 'logical' type rather than the JDBC type this maps
+ * to.
+ *
+ */
+ public Class getType();
+
+ /**
+ * Read the value from the resultSet and convert if necessary to the logical
+ * bean property value.
+ */
+ public T read(DataReader dataReader) throws SQLException;
+
+ /**
+ * Ignore the reading of this value. Typically this means moving the index
+ * position in the ResultSet.
+ */
+ public void loadIgnore(DataReader dataReader);
+
+ /**
+ * 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.
+ *
+ */
+ public void bind(DataBind b, T value) throws SQLException;
+
+ /**
+ * 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 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 type into a string representation.
+ *
+ * Reciprocal of parse().
+ *
+ */
+ public String formatValue(T v);
+
+ /**
+ * 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 string value to the appropriate java object.
+ *
+ * Mostly used to support CSV, JSON and XML parsing.
+ *
+ *
+ * Reciprocal of formatValue().
+ *
+ */
+ public 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).
+ *
+ */
+ public boolean isDateTimeCapable();
+
+ /**
+ * Convert the systemTimeMillis into the appropriate java object.
+ *
+ * For non dateTime types this will throw an exception.
+ *
+ */
+ public T convertFromMillis(long dateTime);
+
+ /**
+ * Read the value from binary input.
+ */
+ public T readData(DataInput dataInput) throws IOException;
+
+ /**
+ * Write the value to binary output.
+ */
+ public void writeData(DataOutput dataOutput, T v) throws IOException;
+
+ /**
+ * Read the value from JsonParser.
+ */
+ public T jsonRead(JsonParser ctx, JsonToken event) throws IOException;
+
+ /**
+ * Write the value to the JsonGenerator.
+ */
+ public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException;
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBase.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBase.java
index 97dcff747..856e30334 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBase.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBase.java
@@ -1,68 +1,68 @@
-package com.avaje.ebeaninternal.server.type;
-
-/**
- * Base ScalarType object.
- */
-public abstract class ScalarTypeBase implements ScalarType {
-
- protected final Class type;
-
- protected final boolean jdbcNative;
-
- protected final int jdbcType;
-
- public ScalarTypeBase(Class type, boolean jdbcNative, int jdbcType) {
- this.type = type;
- this.jdbcNative = jdbcNative;
- this.jdbcType = jdbcType;
- }
-
- /**
- * Default implementation of mutable false.
- */
- @Override
- public boolean isMutable() {
- return false;
- }
-
- /**
- * Default to true.
- */
- @Override
- public boolean isDirty(Object value) {
- return true;
- }
-
- /**
- * Just return 0.
- */
- public int getLength() {
- return 0;
- }
-
- public boolean isJdbcNative() {
- return jdbcNative;
- }
-
- public int getJdbcType() {
- return jdbcType;
- }
-
- public Class getType() {
- return type;
- }
-
- @SuppressWarnings("unchecked")
- public String format(Object v) {
- return formatValue((T) v);
- }
-
- public void loadIgnore(DataReader dataReader) {
- dataReader.incrementPos(1);
- }
-
- public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
- list.addScalarType(propName, this);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+/**
+ * Base ScalarType object.
+ */
+public abstract class ScalarTypeBase implements ScalarType {
+
+ protected final Class type;
+
+ protected final boolean jdbcNative;
+
+ protected final int jdbcType;
+
+ public ScalarTypeBase(Class type, boolean jdbcNative, int jdbcType) {
+ this.type = type;
+ this.jdbcNative = jdbcNative;
+ this.jdbcType = jdbcType;
+ }
+
+ /**
+ * Default implementation of mutable false.
+ */
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+
+ /**
+ * Default to true.
+ */
+ @Override
+ public boolean isDirty(Object value) {
+ return true;
+ }
+
+ /**
+ * Just return 0.
+ */
+ public int getLength() {
+ return 0;
+ }
+
+ public boolean isJdbcNative() {
+ return jdbcNative;
+ }
+
+ public int getJdbcType() {
+ return jdbcType;
+ }
+
+ public Class getType() {
+ return type;
+ }
+
+ @SuppressWarnings("unchecked")
+ public String format(Object v) {
+ return formatValue((T) v);
+ }
+
+ public void loadIgnore(DataReader dataReader) {
+ dataReader.incrementPos(1);
+ }
+
+ public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
+ list.addScalarType(propName, this);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDate.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDate.java
index 7e485192d..105441148 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDate.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDate.java
@@ -1,107 +1,107 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.Date;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * Base class for Date types.
- */
-public abstract class ScalarTypeBaseDate extends ScalarTypeBase {
-
- public ScalarTypeBaseDate(Class type, boolean jdbcNative, int jdbcType) {
- super(type, jdbcNative, jdbcType);
- }
-
- /**
- * Convert the target value to millis.
- */
- public abstract long convertToMillis(T value);
-
- /**
- * Convert to java.sql.Date from the target Date type.
- */
- public abstract java.sql.Date convertToDate(T t);
-
- /**
- * Convert from java.sql.Date to the target Date type.
- */
- public abstract T convertFromDate(java.sql.Date ts);
-
- public void bind(DataBind b, T value) throws SQLException {
- if (value == null) {
- b.setNull(Types.DATE);
- } else {
- b.setDate(convertToDate(value));
- }
- }
-
- public T read(DataReader dataReader) throws SQLException {
-
- Date ts = dataReader.getDate();
- return ts == null ? null : convertFromDate(ts);
- }
-
- public String formatValue(T t) {
- Date date = convertToDate(t);
- return date.toString();
- }
-
- public T parse(String value) {
- Date date = Date.valueOf(value);
- return convertFromDate(date);
- }
-
- public T convertFromMillis(long systemTimeMillis) {
- Date ts = new Date(systemTimeMillis);
- return convertFromDate(ts);
- }
-
- public boolean isDateTimeCapable() {
- return true;
- }
-
- @Override
- public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- if (JsonToken.VALUE_NUMBER_INT == event) {
- return convertFromMillis(ctx.getLongValue());
- } else {
- return convertFromDate(Date.valueOf(ctx.getText()));
- }
- }
-
- public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
- long millis = convertToMillis(value);
- ctx.writeNumberField(name, millis);
- }
-
- public T readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- long val = dataInput.readLong();
- Date date = new Date(val);
- return convertFromDate(date);
- }
- }
-
- @SuppressWarnings("unchecked")
- public void writeData(DataOutput dataOutput, T value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- Date date = convertToDate(value);
- dataOutput.writeLong(date.getTime());
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * Base class for Date types.
+ */
+public abstract class ScalarTypeBaseDate extends ScalarTypeBase {
+
+ public ScalarTypeBaseDate(Class type, boolean jdbcNative, int jdbcType) {
+ super(type, jdbcNative, jdbcType);
+ }
+
+ /**
+ * Convert the target value to millis.
+ */
+ public abstract long convertToMillis(T value);
+
+ /**
+ * Convert to java.sql.Date from the target Date type.
+ */
+ public abstract java.sql.Date convertToDate(T t);
+
+ /**
+ * Convert from java.sql.Date to the target Date type.
+ */
+ public abstract T convertFromDate(java.sql.Date ts);
+
+ public void bind(DataBind b, T value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.DATE);
+ } else {
+ b.setDate(convertToDate(value));
+ }
+ }
+
+ public T read(DataReader dataReader) throws SQLException {
+
+ Date ts = dataReader.getDate();
+ return ts == null ? null : convertFromDate(ts);
+ }
+
+ public String formatValue(T t) {
+ Date date = convertToDate(t);
+ return date.toString();
+ }
+
+ public T parse(String value) {
+ Date date = Date.valueOf(value);
+ return convertFromDate(date);
+ }
+
+ public T convertFromMillis(long systemTimeMillis) {
+ Date ts = new Date(systemTimeMillis);
+ return convertFromDate(ts);
+ }
+
+ public boolean isDateTimeCapable() {
+ return true;
+ }
+
+ @Override
+ public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ if (JsonToken.VALUE_NUMBER_INT == event) {
+ return convertFromMillis(ctx.getLongValue());
+ } else {
+ return convertFromDate(Date.valueOf(ctx.getText()));
+ }
+ }
+
+ public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
+ long millis = convertToMillis(value);
+ ctx.writeNumberField(name, millis);
+ }
+
+ public T readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ long val = dataInput.readLong();
+ Date date = new Date(val);
+ return convertFromDate(date);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void writeData(DataOutput dataOutput, T value) throws IOException {
+
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ Date date = convertToDate(value);
+ dataOutput.writeLong(date.getTime());
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDateTime.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDateTime.java
index a4f02d489..708f2d36b 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDateTime.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseDateTime.java
@@ -1,162 +1,162 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebean.config.JsonConfig;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.time.Instant;
-
-/**
- * Base type for DateTime types.
- */
-public abstract class ScalarTypeBaseDateTime extends ScalarTypeBase {
-
-
- protected final DateTimeJsonParser dateTimeParser = new DateTimeJsonParser();
-
- protected final JsonConfig.DateTime mode;
-
- public ScalarTypeBaseDateTime(JsonConfig.DateTime mode, Class type, boolean jdbcNative, int jdbcType) {
- super(type, jdbcNative, jdbcType);
- this.mode = mode;
- }
-
- /**
- * Convert the value to a Timestamp.
- */
- public abstract Timestamp convertToTimestamp(T t);
-
- /**
- * Convert to the value from a Timestamp.
- */
- public abstract T convertFromTimestamp(Timestamp ts);
-
- /**
- * Convert from epoch millis to the value.
- */
- public abstract T convertFromMillis(long systemTimeMillis);
-
- /**
- * Convert from the value to epoch millis.
- */
- public abstract long convertToMillis(T value);
-
- /**
- * Convert the value to time with nanos format.
- */
- protected abstract String toJsonNanos(T value);
-
- /**
- * Convert the value to ISO8601 format.
- */
- protected abstract String toJsonISO8601(T value);
-
- public void bind(DataBind b, T value) throws SQLException {
- if (value == null) {
- b.setNull(Types.TIMESTAMP);
- } else {
- b.setTimestamp(convertToTimestamp(value));
- }
- }
-
- public T read(DataReader dataReader) throws SQLException {
-
- Timestamp ts = dataReader.getTimestamp();
- if (ts == null) {
- return null;
- } else {
- return convertFromTimestamp(ts);
- }
- }
-
- /**
- * Helper method that given epoch seconds and nanos return a JSON nanos formatted string.
- */
- protected String toJsonNanos(long epochSecs, int nanos) {
- return DecimalUtils.toDecimal(epochSecs, nanos);
- }
-
- @Override
- public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
-
- switch (event) {
- case VALUE_NUMBER_INT: {
- return convertFromMillis(ctx.getLongValue());
- }
- case VALUE_NUMBER_FLOAT: {
- BigDecimal value = ctx.getDecimalValue();
- Timestamp timestamp = DecimalUtils.toTimestamp(value);
- return convertFromTimestamp(timestamp);
- }
- default: {
- String jsonDateTime = ctx.getText();
- return convertFromTimestamp(dateTimeParser.parse(jsonDateTime));
- }
- }
- }
-
- @Override
- public void jsonWrite(JsonGenerator generator, String name, T value) throws IOException {
-
- switch (mode) {
- case ISO8601: {
- generator.writeFieldName(name);
- generator.writeString(toJsonISO8601(value));
- break;
- }
- case NANOS: {
- generator.writeFieldName(name);
- generator.writeNumber(toJsonNanos(value));
- break;
- }
- default: {
- generator.writeNumberField(name, convertToMillis(value));
- }
- }
- }
-
- public String formatValue(T t) {
- Timestamp ts = convertToTimestamp(t);
- return ts.toString();
- }
-
- public T parse(String value) {
- Timestamp ts = Timestamp.valueOf(value);
- return convertFromTimestamp(ts);
- }
-
-
- public boolean isDateTimeCapable() {
- return true;
- }
-
- public T readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- long val = dataInput.readLong();
- Timestamp ts = new Timestamp(val);
- return convertFromTimestamp(ts);
- }
- }
-
- public void writeData(DataOutput dataOutput, T value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- Timestamp ts = convertToTimestamp(value);
- dataOutput.writeLong(ts.getTime());
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebean.config.JsonConfig;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.Instant;
+
+/**
+ * Base type for DateTime types.
+ */
+public abstract class ScalarTypeBaseDateTime extends ScalarTypeBase {
+
+
+ protected final DateTimeJsonParser dateTimeParser = new DateTimeJsonParser();
+
+ protected final JsonConfig.DateTime mode;
+
+ public ScalarTypeBaseDateTime(JsonConfig.DateTime mode, Class type, boolean jdbcNative, int jdbcType) {
+ super(type, jdbcNative, jdbcType);
+ this.mode = mode;
+ }
+
+ /**
+ * Convert the value to a Timestamp.
+ */
+ public abstract Timestamp convertToTimestamp(T t);
+
+ /**
+ * Convert to the value from a Timestamp.
+ */
+ public abstract T convertFromTimestamp(Timestamp ts);
+
+ /**
+ * Convert from epoch millis to the value.
+ */
+ public abstract T convertFromMillis(long systemTimeMillis);
+
+ /**
+ * Convert from the value to epoch millis.
+ */
+ public abstract long convertToMillis(T value);
+
+ /**
+ * Convert the value to time with nanos format.
+ */
+ protected abstract String toJsonNanos(T value);
+
+ /**
+ * Convert the value to ISO8601 format.
+ */
+ protected abstract String toJsonISO8601(T value);
+
+ public void bind(DataBind b, T value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.TIMESTAMP);
+ } else {
+ b.setTimestamp(convertToTimestamp(value));
+ }
+ }
+
+ public T read(DataReader dataReader) throws SQLException {
+
+ Timestamp ts = dataReader.getTimestamp();
+ if (ts == null) {
+ return null;
+ } else {
+ return convertFromTimestamp(ts);
+ }
+ }
+
+ /**
+ * Helper method that given epoch seconds and nanos return a JSON nanos formatted string.
+ */
+ protected String toJsonNanos(long epochSecs, int nanos) {
+ return DecimalUtils.toDecimal(epochSecs, nanos);
+ }
+
+ @Override
+ public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+
+ switch (event) {
+ case VALUE_NUMBER_INT: {
+ return convertFromMillis(ctx.getLongValue());
+ }
+ case VALUE_NUMBER_FLOAT: {
+ BigDecimal value = ctx.getDecimalValue();
+ Timestamp timestamp = DecimalUtils.toTimestamp(value);
+ return convertFromTimestamp(timestamp);
+ }
+ default: {
+ String jsonDateTime = ctx.getText();
+ return convertFromTimestamp(dateTimeParser.parse(jsonDateTime));
+ }
+ }
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator generator, String name, T value) throws IOException {
+
+ switch (mode) {
+ case ISO8601: {
+ generator.writeFieldName(name);
+ generator.writeString(toJsonISO8601(value));
+ break;
+ }
+ case NANOS: {
+ generator.writeFieldName(name);
+ generator.writeNumber(toJsonNanos(value));
+ break;
+ }
+ default: {
+ generator.writeNumberField(name, convertToMillis(value));
+ }
+ }
+ }
+
+ public String formatValue(T t) {
+ Timestamp ts = convertToTimestamp(t);
+ return ts.toString();
+ }
+
+ public T parse(String value) {
+ Timestamp ts = Timestamp.valueOf(value);
+ return convertFromTimestamp(ts);
+ }
+
+
+ public boolean isDateTimeCapable() {
+ return true;
+ }
+
+ public T readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ long val = dataInput.readLong();
+ Timestamp ts = new Timestamp(val);
+ return convertFromTimestamp(ts);
+ }
+ }
+
+ public void writeData(DataOutput dataOutput, T value) throws IOException {
+
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ Timestamp ts = convertToTimestamp(value);
+ dataOutput.writeLong(ts.getTime());
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseVarchar.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseVarchar.java
index 750400b95..f3009983e 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseVarchar.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBaseVarchar.java
@@ -1,134 +1,134 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebean.text.TextException;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * Base ScalarType for types which converts to and from a VARCHAR database
- * column.
- */
-public abstract class ScalarTypeBaseVarchar extends ScalarTypeBase {
-
- public ScalarTypeBaseVarchar(Class type) {
- super(type, false, Types.VARCHAR);
- }
-
- public ScalarTypeBaseVarchar(Class type, boolean jdbcNative, int jdbcType) {
- super(type, jdbcNative, jdbcType);
- }
-
- /**
- * Format the target type to a string.
- */
- public abstract String formatValue(T v);
-
- /**
- * Parse from a formatted string value.
- */
- public abstract T parse(String value);
-
- /**
- * Convert from DB string value to the target type.
- */
- public abstract T convertFromDbString(String dbValue);
-
- /**
- * Convert to DB string from the target type.
- */
- public abstract String convertToDbString(T beanValue);
-
- @Override
- public void bind(DataBind b, T value) throws SQLException {
- if (value == null) {
- b.setNull(Types.VARCHAR);
-
- } else {
- b.setString(convertToDbString(value));
- }
- }
-
- @Override
- public T read(DataReader dataReader) throws SQLException {
- String s = dataReader.getString();
- if (s == null) {
- return null;
- } else {
- return convertFromDbString(s);
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public T toBeanType(Object value) {
- if (value == null) {
- return null;
- }
- if (value instanceof String) {
- return parse((String) value);
- }
- return (T) value;
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof String) {
- return parse((String) value);
- }
- return value;
- }
-
- @Override
- public T convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not Supported");
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return false;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public String format(Object v) {
- return formatValue((T) v);
- }
-
- @Override
- public T readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- String val = dataInput.readUTF();
- return convertFromDbString(val);
- }
- }
-
- public void writeData(DataOutput dataOutput, T value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- String s = convertToDbString(value);
- dataOutput.writeUTF(s);
- }
- }
-
- @Override
- public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return parse(ctx.getValueAsString());
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
- ctx.writeStringField(name, format(value));
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebean.text.TextException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * Base ScalarType for types which converts to and from a VARCHAR database
+ * column.
+ */
+public abstract class ScalarTypeBaseVarchar extends ScalarTypeBase {
+
+ public ScalarTypeBaseVarchar(Class type) {
+ super(type, false, Types.VARCHAR);
+ }
+
+ public ScalarTypeBaseVarchar(Class type, boolean jdbcNative, int jdbcType) {
+ super(type, jdbcNative, jdbcType);
+ }
+
+ /**
+ * Format the target type to a string.
+ */
+ public abstract String formatValue(T v);
+
+ /**
+ * Parse from a formatted string value.
+ */
+ public abstract T parse(String value);
+
+ /**
+ * Convert from DB string value to the target type.
+ */
+ public abstract T convertFromDbString(String dbValue);
+
+ /**
+ * Convert to DB string from the target type.
+ */
+ public abstract String convertToDbString(T beanValue);
+
+ @Override
+ public void bind(DataBind b, T value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.VARCHAR);
+
+ } else {
+ b.setString(convertToDbString(value));
+ }
+ }
+
+ @Override
+ public T read(DataReader dataReader) throws SQLException {
+ String s = dataReader.getString();
+ if (s == null) {
+ return null;
+ } else {
+ return convertFromDbString(s);
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public T toBeanType(Object value) {
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof String) {
+ return parse((String) value);
+ }
+ return (T) value;
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof String) {
+ return parse((String) value);
+ }
+ return value;
+ }
+
+ @Override
+ public T convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not Supported");
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public String format(Object v) {
+ return formatValue((T) v);
+ }
+
+ @Override
+ public T readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ String val = dataInput.readUTF();
+ return convertFromDbString(val);
+ }
+ }
+
+ public void writeData(DataOutput dataOutput, T value) throws IOException {
+
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ String s = convertToDbString(value);
+ dataOutput.writeUTF(s);
+ }
+ }
+
+ @Override
+ public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return parse(ctx.getValueAsString());
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
+ ctx.writeStringField(name, format(value));
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBigDecimal.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBigDecimal.java
index 23d4fad29..c45e960db 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBigDecimal.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBigDecimal.java
@@ -1,89 +1,89 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for BigDecimal.
- */
-public class ScalarTypeBigDecimal extends ScalarTypeBase {
-
- public ScalarTypeBigDecimal() {
- super(BigDecimal.class, true, Types.DECIMAL);
- }
-
- public BigDecimal readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- double val = dataInput.readDouble();
- return new BigDecimal(val);
- }
- }
-
- public void writeData(DataOutput dataOutput, BigDecimal b) throws IOException {
-
- if (b == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeDouble(b.doubleValue());
- }
- }
-
- public void bind(DataBind b, BigDecimal value) throws SQLException {
- if (value == null) {
- b.setNull(Types.DECIMAL);
- } else {
- b.setBigDecimal(value);
- }
- }
-
- public BigDecimal read(DataReader dataReader) throws SQLException {
-
- return dataReader.getBigDecimal();
- }
-
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toBigDecimal(value);
- }
-
- public BigDecimal toBeanType(Object value) {
- return BasicTypeConverter.toBigDecimal(value);
- }
-
- public String formatValue(BigDecimal t) {
- return t.toPlainString();
- }
-
- public BigDecimal parse(String value) {
- return new BigDecimal(value);
- }
-
- public BigDecimal convertFromMillis(long systemTimeMillis) {
- return BigDecimal.valueOf(systemTimeMillis);
- }
-
- public boolean isDateTimeCapable() {
- return true;
- }
-
- @Override
- public BigDecimal jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return ctx.getDecimalValue();
- }
-
- public void jsonWrite(JsonGenerator ctx, String name, BigDecimal value) throws IOException {
- ctx.writeNumberField(name, (BigDecimal) value);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for BigDecimal.
+ */
+public class ScalarTypeBigDecimal extends ScalarTypeBase {
+
+ public ScalarTypeBigDecimal() {
+ super(BigDecimal.class, true, Types.DECIMAL);
+ }
+
+ public BigDecimal readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ double val = dataInput.readDouble();
+ return new BigDecimal(val);
+ }
+ }
+
+ public void writeData(DataOutput dataOutput, BigDecimal b) throws IOException {
+
+ if (b == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeDouble(b.doubleValue());
+ }
+ }
+
+ public void bind(DataBind b, BigDecimal value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.DECIMAL);
+ } else {
+ b.setBigDecimal(value);
+ }
+ }
+
+ public BigDecimal read(DataReader dataReader) throws SQLException {
+
+ return dataReader.getBigDecimal();
+ }
+
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toBigDecimal(value);
+ }
+
+ public BigDecimal toBeanType(Object value) {
+ return BasicTypeConverter.toBigDecimal(value);
+ }
+
+ public String formatValue(BigDecimal t) {
+ return t.toPlainString();
+ }
+
+ public BigDecimal parse(String value) {
+ return new BigDecimal(value);
+ }
+
+ public BigDecimal convertFromMillis(long systemTimeMillis) {
+ return BigDecimal.valueOf(systemTimeMillis);
+ }
+
+ public boolean isDateTimeCapable() {
+ return true;
+ }
+
+ @Override
+ public BigDecimal jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return ctx.getDecimalValue();
+ }
+
+ public void jsonWrite(JsonGenerator ctx, String name, BigDecimal value) throws IOException {
+ ctx.writeNumberField(name, (BigDecimal) value);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBoolean.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBoolean.java
index 67780c3bb..4d76e3805 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBoolean.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBoolean.java
@@ -1,300 +1,300 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebean.text.TextException;
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for Boolean and boolean.
- *
- * This may or may not be a native jdbc type depending on the database and jdbc driver.
- *
- */
-public class ScalarTypeBoolean {
-
- public static class Native extends BooleanBase {
-
- /**
- * Native Boolean database type.
- */
- public Native() {
- super(true, Types.BOOLEAN);
- }
-
- public Boolean toBeanType(Object value) {
- return BasicTypeConverter.toBoolean(value);
- }
-
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.convert(value, jdbcType);
- }
-
- public void bind(DataBind b, Boolean value) throws SQLException {
- if (value == null) {
- b.setNull(Types.BOOLEAN);
- } else {
- b.setBoolean(value);
- }
-
- }
-
- public Boolean read(DataReader dataReader) throws SQLException {
- return dataReader.getBoolean();
- }
- }
-
- /**
- * The Class BitBoolean converts a JDBC type BIT to a java boolean
- *
- *
- * Sometimes booleans may be mapped to the JDBC type BIT. To use the BitBoolean specify
- * type.boolean.dbtype="bit" in the ebean configuration
- *
- */
- public static class BitBoolean extends BooleanBase {
-
- /**
- * Native Boolean database type.
- */
- public BitBoolean() {
- super(true, Types.BIT);
- }
-
- public Boolean toBeanType(Object value) {
- return BasicTypeConverter.toBoolean(value);
- }
-
- public Object toJdbcType(Object value) {
- // use JDBC driver to convert boolean to bit
- return BasicTypeConverter.toBoolean(value);
- }
-
- public void bind(DataBind b, Boolean value) throws SQLException {
- if (value == null) {
- b.setNull(Types.BIT);
- } else {
- // use JDBC driver to convert boolean to bit
- b.setBoolean(value);
- }
- }
-
- public Boolean read(DataReader dataReader) throws SQLException {
- return dataReader.getBoolean();
- }
-
- }
-
- /**
- * Converted to/from an Integer in the Database.
- */
- public static class IntBoolean extends BooleanBase {
-
- private final Integer trueValue;
- private final Integer falseValue;
-
- public IntBoolean(Integer trueValue, Integer falseValue) {
- super(false, Types.INTEGER);
- this.trueValue = trueValue;
- this.falseValue = falseValue;
- }
-
- @Override
- public int getLength() {
- return 1;
- }
-
- public void bind(DataBind b, Boolean value) throws SQLException {
- if (value == null) {
- b.setNull(Types.INTEGER);
- } else {
- b.setInt(toInteger(value));
- }
- }
-
- public Boolean read(DataReader dataReader) throws SQLException {
- Integer i = dataReader.getInt();
- if (i == null) {
- return null;
- }
- if (i.equals(trueValue)) {
- return Boolean.TRUE;
- } else {
- return Boolean.FALSE;
- }
- }
-
- public Object toJdbcType(Object value) {
- return toInteger(value);
- }
-
- /**
- * Convert the Boolean value to the db value.
- */
- public Integer toInteger(Object value) {
- if (value == null) {
- return null;
- }
- Boolean b = (Boolean) value;
- if (b.booleanValue()) {
- return trueValue;
- } else {
- return falseValue;
- }
- }
-
- /**
- * Convert the db value to the Boolean value.
- */
- public Boolean toBeanType(Object value) {
- if (value == null) {
- return null;
- }
- if (value instanceof Boolean) {
- return (Boolean) value;
- }
- if (trueValue.equals(value)) {
- return Boolean.TRUE;
- } else {
- return Boolean.FALSE;
- }
- }
-
- }
-
- /**
- * Converted to/from an Integer in the Database.
- */
- public static class StringBoolean extends BooleanBase {
-
- private final String trueValue;
- private final String falseValue;
-
- public StringBoolean(String trueValue, String falseValue) {
- super(false, Types.VARCHAR);
- this.trueValue = trueValue;
- this.falseValue = falseValue;
- }
-
- @Override
- public int getLength() {
- // typically this will return 1
- return Math.max(trueValue.length(), falseValue.length());
- }
-
- public void bind(DataBind b, Boolean value) throws SQLException {
- if (value == null) {
- b.setNull(Types.VARCHAR);
- } else {
- b.setString(toString(value));
- }
- }
-
- public Boolean read(DataReader dataReader) throws SQLException {
- String string = dataReader.getString();
- if (string == null) {
- return null;
- }
-
- if (string.equals(trueValue)) {
- return Boolean.TRUE;
- } else {
- return Boolean.FALSE;
- }
- }
-
- public Object toJdbcType(Object value) {
- return toString(value);
- }
-
- /**
- * Convert the Boolean value to the db value.
- */
- public String toString(Object value) {
- if (value == null) {
- return null;
- }
- Boolean b = (Boolean) value;
- if (b.booleanValue()) {
- return trueValue;
- } else {
- return falseValue;
- }
- }
-
- /**
- * Convert the db value to the Boolean value.
- */
- public Boolean toBeanType(Object value) {
- if (value == null) {
- return null;
- }
- if (value instanceof Boolean) {
- return (Boolean) value;
- }
- if (trueValue.equals(value)) {
- return Boolean.TRUE;
- } else {
- return Boolean.FALSE;
- }
- }
- }
-
- public static abstract class BooleanBase extends ScalarTypeBase {
-
- public BooleanBase(boolean jdbcNative, int jdbcType) {
- super(Boolean.class, jdbcNative, jdbcType);
- }
-
- public String formatValue(Boolean t) {
- return t.toString();
- }
-
- public Boolean parse(String value) {
- return Boolean.valueOf(value);
- }
-
- public Boolean convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not Supported");
- }
-
- public boolean isDateTimeCapable() {
- return false;
- }
-
- public Boolean readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- return dataInput.readBoolean();
- }
- }
-
- public void writeData(DataOutput dataOutput, Boolean val) throws IOException {
-
- if (val == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeBoolean(val);
- }
- }
-
- @Override
- public Boolean jsonRead(JsonParser ctx, JsonToken event) {
- return JsonToken.VALUE_TRUE == event ? Boolean.TRUE : Boolean.FALSE;
- }
-
- public void jsonWrite(JsonGenerator ctx, String name, Boolean value) throws IOException {
- ctx.writeBooleanField(name, (Boolean) value);
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebean.text.TextException;
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for Boolean and boolean.
+ *
+ * This may or may not be a native jdbc type depending on the database and jdbc driver.
+ *
+ */
+public class ScalarTypeBoolean {
+
+ public static class Native extends BooleanBase {
+
+ /**
+ * Native Boolean database type.
+ */
+ public Native() {
+ super(true, Types.BOOLEAN);
+ }
+
+ public Boolean toBeanType(Object value) {
+ return BasicTypeConverter.toBoolean(value);
+ }
+
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.convert(value, jdbcType);
+ }
+
+ public void bind(DataBind b, Boolean value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.BOOLEAN);
+ } else {
+ b.setBoolean(value);
+ }
+
+ }
+
+ public Boolean read(DataReader dataReader) throws SQLException {
+ return dataReader.getBoolean();
+ }
+ }
+
+ /**
+ * The Class BitBoolean converts a JDBC type BIT to a java boolean
+ *
+ *
+ * Sometimes booleans may be mapped to the JDBC type BIT. To use the BitBoolean specify
+ * type.boolean.dbtype="bit" in the ebean configuration
+ *
+ */
+ public static class BitBoolean extends BooleanBase {
+
+ /**
+ * Native Boolean database type.
+ */
+ public BitBoolean() {
+ super(true, Types.BIT);
+ }
+
+ public Boolean toBeanType(Object value) {
+ return BasicTypeConverter.toBoolean(value);
+ }
+
+ public Object toJdbcType(Object value) {
+ // use JDBC driver to convert boolean to bit
+ return BasicTypeConverter.toBoolean(value);
+ }
+
+ public void bind(DataBind b, Boolean value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.BIT);
+ } else {
+ // use JDBC driver to convert boolean to bit
+ b.setBoolean(value);
+ }
+ }
+
+ public Boolean read(DataReader dataReader) throws SQLException {
+ return dataReader.getBoolean();
+ }
+
+ }
+
+ /**
+ * Converted to/from an Integer in the Database.
+ */
+ public static class IntBoolean extends BooleanBase {
+
+ private final Integer trueValue;
+ private final Integer falseValue;
+
+ public IntBoolean(Integer trueValue, Integer falseValue) {
+ super(false, Types.INTEGER);
+ this.trueValue = trueValue;
+ this.falseValue = falseValue;
+ }
+
+ @Override
+ public int getLength() {
+ return 1;
+ }
+
+ public void bind(DataBind b, Boolean value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.INTEGER);
+ } else {
+ b.setInt(toInteger(value));
+ }
+ }
+
+ public Boolean read(DataReader dataReader) throws SQLException {
+ Integer i = dataReader.getInt();
+ if (i == null) {
+ return null;
+ }
+ if (i.equals(trueValue)) {
+ return Boolean.TRUE;
+ } else {
+ return Boolean.FALSE;
+ }
+ }
+
+ public Object toJdbcType(Object value) {
+ return toInteger(value);
+ }
+
+ /**
+ * Convert the Boolean value to the db value.
+ */
+ public Integer toInteger(Object value) {
+ if (value == null) {
+ return null;
+ }
+ Boolean b = (Boolean) value;
+ if (b.booleanValue()) {
+ return trueValue;
+ } else {
+ return falseValue;
+ }
+ }
+
+ /**
+ * Convert the db value to the Boolean value.
+ */
+ public Boolean toBeanType(Object value) {
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof Boolean) {
+ return (Boolean) value;
+ }
+ if (trueValue.equals(value)) {
+ return Boolean.TRUE;
+ } else {
+ return Boolean.FALSE;
+ }
+ }
+
+ }
+
+ /**
+ * Converted to/from an Integer in the Database.
+ */
+ public static class StringBoolean extends BooleanBase {
+
+ private final String trueValue;
+ private final String falseValue;
+
+ public StringBoolean(String trueValue, String falseValue) {
+ super(false, Types.VARCHAR);
+ this.trueValue = trueValue;
+ this.falseValue = falseValue;
+ }
+
+ @Override
+ public int getLength() {
+ // typically this will return 1
+ return Math.max(trueValue.length(), falseValue.length());
+ }
+
+ public void bind(DataBind b, Boolean value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.VARCHAR);
+ } else {
+ b.setString(toString(value));
+ }
+ }
+
+ public Boolean read(DataReader dataReader) throws SQLException {
+ String string = dataReader.getString();
+ if (string == null) {
+ return null;
+ }
+
+ if (string.equals(trueValue)) {
+ return Boolean.TRUE;
+ } else {
+ return Boolean.FALSE;
+ }
+ }
+
+ public Object toJdbcType(Object value) {
+ return toString(value);
+ }
+
+ /**
+ * Convert the Boolean value to the db value.
+ */
+ public String toString(Object value) {
+ if (value == null) {
+ return null;
+ }
+ Boolean b = (Boolean) value;
+ if (b.booleanValue()) {
+ return trueValue;
+ } else {
+ return falseValue;
+ }
+ }
+
+ /**
+ * Convert the db value to the Boolean value.
+ */
+ public Boolean toBeanType(Object value) {
+ if (value == null) {
+ return null;
+ }
+ if (value instanceof Boolean) {
+ return (Boolean) value;
+ }
+ if (trueValue.equals(value)) {
+ return Boolean.TRUE;
+ } else {
+ return Boolean.FALSE;
+ }
+ }
+ }
+
+ public static abstract class BooleanBase extends ScalarTypeBase {
+
+ public BooleanBase(boolean jdbcNative, int jdbcType) {
+ super(Boolean.class, jdbcNative, jdbcType);
+ }
+
+ public String formatValue(Boolean t) {
+ return t.toString();
+ }
+
+ public Boolean parse(String value) {
+ return Boolean.valueOf(value);
+ }
+
+ public Boolean convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not Supported");
+ }
+
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ public Boolean readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ return dataInput.readBoolean();
+ }
+ }
+
+ public void writeData(DataOutput dataOutput, Boolean val) throws IOException {
+
+ if (val == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeBoolean(val);
+ }
+ }
+
+ @Override
+ public Boolean jsonRead(JsonParser ctx, JsonToken event) {
+ return JsonToken.VALUE_TRUE == event ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ public void jsonWrite(JsonGenerator ctx, String name, Boolean value) throws IOException {
+ ctx.writeBooleanField(name, (Boolean) value);
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeByte.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeByte.java
index 1ac6dfcf2..bc6872eaf 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeByte.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeByte.java
@@ -1,88 +1,88 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebean.text.TextException;
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for Byte.
- */
-public class ScalarTypeByte extends ScalarTypeBase {
-
- public ScalarTypeByte() {
- super(Byte.class, true, Types.TINYINT);
- }
-
- public void bind(DataBind b, Byte value) throws SQLException {
- if (value == null) {
- b.setNull(Types.TINYINT);
- } else {
- b.setByte(value);
- }
- }
-
- public Byte read(DataReader dataReader) throws SQLException {
- return dataReader.getByte();
- }
-
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toByte(value);
- }
-
- public Byte toBeanType(Object value) {
- return BasicTypeConverter.toByte(value);
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, Byte value) throws IOException {
- throw new IOException("Not supported");
- }
-
- @Override
- public Byte jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- throw new IOException("Not supported");
- }
-
- public String formatValue(Byte t) {
- return t.toString();
- }
-
- public Byte parse(String value) {
- throw new TextException("Not supported");
- }
-
- public Byte convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not Supported");
- }
-
- public boolean isDateTimeCapable() {
- return false;
- }
-
- public Byte readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- return dataInput.readByte();
- }
- }
-
- public void writeData(DataOutput dataOutput, Byte val) throws IOException {
-
- if (val == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeByte(val);
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebean.text.TextException;
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for Byte.
+ */
+public class ScalarTypeByte extends ScalarTypeBase {
+
+ public ScalarTypeByte() {
+ super(Byte.class, true, Types.TINYINT);
+ }
+
+ public void bind(DataBind b, Byte value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.TINYINT);
+ } else {
+ b.setByte(value);
+ }
+ }
+
+ public Byte read(DataReader dataReader) throws SQLException {
+ return dataReader.getByte();
+ }
+
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toByte(value);
+ }
+
+ public Byte toBeanType(Object value) {
+ return BasicTypeConverter.toByte(value);
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, Byte value) throws IOException {
+ throw new IOException("Not supported");
+ }
+
+ @Override
+ public Byte jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ throw new IOException("Not supported");
+ }
+
+ public String formatValue(Byte t) {
+ return t.toString();
+ }
+
+ public Byte parse(String value) {
+ throw new TextException("Not supported");
+ }
+
+ public Byte convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not Supported");
+ }
+
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ public Byte readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ return dataInput.readByte();
+ }
+ }
+
+ public void writeData(DataOutput dataOutput, Byte val) throws IOException {
+
+ if (val == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeByte(val);
+ }
+ }
+
+}
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 2f03c15aa..0fa8c65a0 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBase.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBase.java
@@ -1,97 +1,97 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-
-import com.avaje.ebean.text.TextException;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * Base type for binary types.
- */
-public abstract class ScalarTypeBytesBase extends ScalarTypeBase {
-
- protected ScalarTypeBytesBase(boolean jdbcNative, int jdbcType) {
- super(byte[].class, jdbcNative, jdbcType);
- }
-
- public Object convertFromBytes(byte[] bytes) {
- return bytes;
- }
-
- public byte[] convertToBytes(Object value) {
- return (byte[]) value;
- }
-
- public void bind(DataBind b, byte[] value) throws SQLException {
- if (value == null) {
- b.setNull(jdbcType);
- } else {
- b.setBytes(value);
- }
- }
-
- public Object toJdbcType(Object value) {
- return value;
- }
-
- public byte[] toBeanType(Object value) {
- return (byte[]) value;
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, byte[] value) throws IOException {
- ctx.writeBinaryField(name, (byte[]) value);
- }
-
- @Override
- public byte[] jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream(500);
- ctx.readBinaryValue(out);
- return out.toByteArray();
- }
-
- public String formatValue(byte[] t) {
- throw new TextException("Not supported");
- }
-
- public byte[] parse(String value) {
- throw new TextException("Not supported");
- }
-
- public byte[] convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not supported");
- }
-
- public boolean isDateTimeCapable() {
- return false;
- }
-
- public byte[] readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- int len = dataInput.readInt();
- byte[] buf = new byte[len];
- dataInput.readFully(buf, 0, buf.length);
- return buf;
- }
- }
-
- public void writeData(DataOutput dataOutput, byte[] v) throws IOException {
- if (v == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- byte[] bytes = convertToBytes(v);
- dataOutput.writeInt(bytes.length);
- dataOutput.write(bytes);
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import com.avaje.ebean.text.TextException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * Base type for binary types.
+ */
+public abstract class ScalarTypeBytesBase extends ScalarTypeBase {
+
+ protected ScalarTypeBytesBase(boolean jdbcNative, int jdbcType) {
+ super(byte[].class, jdbcNative, jdbcType);
+ }
+
+ public Object convertFromBytes(byte[] bytes) {
+ return bytes;
+ }
+
+ public byte[] convertToBytes(Object value) {
+ return (byte[]) value;
+ }
+
+ public void bind(DataBind b, byte[] value) throws SQLException {
+ if (value == null) {
+ b.setNull(jdbcType);
+ } else {
+ b.setBytes(value);
+ }
+ }
+
+ public Object toJdbcType(Object value) {
+ return value;
+ }
+
+ public byte[] toBeanType(Object value) {
+ return (byte[]) value;
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, byte[] value) throws IOException {
+ ctx.writeBinaryField(name, (byte[]) value);
+ }
+
+ @Override
+ public byte[] jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream(500);
+ ctx.readBinaryValue(out);
+ return out.toByteArray();
+ }
+
+ public String formatValue(byte[] t) {
+ throw new TextException("Not supported");
+ }
+
+ public byte[] parse(String value) {
+ throw new TextException("Not supported");
+ }
+
+ public byte[] convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not supported");
+ }
+
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ public byte[] readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ int len = dataInput.readInt();
+ byte[] buf = new byte[len];
+ dataInput.readFully(buf, 0, buf.length);
+ return buf;
+ }
+ }
+
+ public void writeData(DataOutput dataOutput, byte[] v) throws IOException {
+ if (v == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ byte[] bytes = convertToBytes(v);
+ dataOutput.writeInt(bytes.length);
+ dataOutput.write(bytes);
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBinary.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBinary.java
index b83cf3c05..22809599a 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBinary.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBinary.java
@@ -1,19 +1,19 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.SQLException;
-import java.sql.Types;
-
-/**
- * ScalarType for Types.BINARY to byte[].
- */
-public class ScalarTypeBytesBinary extends ScalarTypeBytesBase {
-
- public ScalarTypeBytesBinary() {
- super(true, Types.BINARY);
- }
-
- public byte[] read(DataReader dataReader) throws SQLException {
- return dataReader.getBytes();
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * ScalarType for Types.BINARY to byte[].
+ */
+public class ScalarTypeBytesBinary extends ScalarTypeBytesBase {
+
+ public ScalarTypeBytesBinary() {
+ super(true, Types.BINARY);
+ }
+
+ public byte[] read(DataReader dataReader) throws SQLException {
+ return dataReader.getBytes();
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBlob.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBlob.java
index 11ff9f465..31dc90637 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBlob.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesBlob.java
@@ -1,20 +1,20 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.SQLException;
-import java.sql.Types;
-
-/**
- * ScalarType for BLOB.
- */
-public class ScalarTypeBytesBlob extends ScalarTypeBytesBase {
-
- public ScalarTypeBytesBlob() {
- super(true, Types.BLOB);
- }
-
- public byte[] read(DataReader dataReader) throws SQLException {
-
- return dataReader.getBlobBytes();
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * ScalarType for BLOB.
+ */
+public class ScalarTypeBytesBlob extends ScalarTypeBytesBase {
+
+ public ScalarTypeBytesBlob() {
+ super(true, Types.BLOB);
+ }
+
+ public byte[] read(DataReader dataReader) throws SQLException {
+
+ return dataReader.getBlobBytes();
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java
index 4dfbc2b1f..d739a24f6 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesEncrypted.java
@@ -1,138 +1,138 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * Encrypted ScalarType that wraps a byte[] types.
- *
- * @author rbygrave
- *
- */
-public class ScalarTypeBytesEncrypted implements ScalarType {
-
- private final ScalarTypeBytesBase baseType;
-
- private final DataEncryptSupport dataEncryptSupport;
-
- public ScalarTypeBytesEncrypted(ScalarTypeBytesBase baseType, DataEncryptSupport dataEncryptSupport) {
- this.baseType = baseType;
- this.dataEncryptSupport = dataEncryptSupport;
- }
-
- @Override
- public boolean isMutable() {
- return false;
- }
-
- @Override
- public boolean isDirty(Object value) {
- return false;
- }
-
- public void bind(DataBind b, byte[] value) throws SQLException {
- value = dataEncryptSupport.encrypt(value);
- baseType.bind(b, value);
- }
-
- public int getJdbcType() {
- return baseType.getJdbcType();
- }
-
- public int getLength() {
- return baseType.getLength();
- }
-
- public Class getType() {
- return byte[].class;
- }
-
- public boolean isDateTimeCapable() {
- return baseType.isDateTimeCapable();
- }
-
- public boolean isJdbcNative() {
- return baseType.isJdbcNative();
- }
-
- public void loadIgnore(DataReader dataReader) {
- baseType.loadIgnore(dataReader);
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, byte[] value) throws IOException {
- ctx.writeBinaryField(name, (byte[]) value);
- }
-
- @Override
- public byte[] jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream(500);
- ctx.readBinaryValue(out);
- return out.toByteArray();
- }
-
- public String format(Object v) {
- throw new RuntimeException("Not used");
- }
-
- public String formatValue(byte[] v) {
- throw new RuntimeException("Not used");
- }
-
- public byte[] parse(String value) {
- return baseType.parse(value);
- }
-
- public byte[] convertFromMillis(long systemTimeMillis) {
- return baseType.convertFromMillis(systemTimeMillis);
- }
-
- public byte[] read(DataReader dataReader) throws SQLException {
-
- byte[] data = baseType.read(dataReader);
- data = dataEncryptSupport.decrypt(data);
- return data;
- }
-
- public byte[] toBeanType(Object value) {
- return baseType.toBeanType(value);
- }
-
- public Object toJdbcType(Object value) {
- return baseType.toJdbcType(value);
- }
-
- public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
- baseType.accumulateScalarTypes(propName, list);
- }
-
- public byte[] readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- int len = dataInput.readInt();
- byte[] value = new byte[len];
- dataInput.readFully(value);
- return value;
- }
- }
-
- public void writeData(DataOutput dataOutput, byte[] value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeInt(value.length);
- dataOutput.write(value);
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * Encrypted ScalarType that wraps a byte[] types.
+ *
+ * @author rbygrave
+ *
+ */
+public class ScalarTypeBytesEncrypted implements ScalarType {
+
+ private final ScalarTypeBytesBase baseType;
+
+ private final DataEncryptSupport dataEncryptSupport;
+
+ public ScalarTypeBytesEncrypted(ScalarTypeBytesBase baseType, DataEncryptSupport dataEncryptSupport) {
+ this.baseType = baseType;
+ this.dataEncryptSupport = dataEncryptSupport;
+ }
+
+ @Override
+ public boolean isMutable() {
+ return false;
+ }
+
+ @Override
+ public boolean isDirty(Object value) {
+ return false;
+ }
+
+ public void bind(DataBind b, byte[] value) throws SQLException {
+ value = dataEncryptSupport.encrypt(value);
+ baseType.bind(b, value);
+ }
+
+ public int getJdbcType() {
+ return baseType.getJdbcType();
+ }
+
+ public int getLength() {
+ return baseType.getLength();
+ }
+
+ public Class getType() {
+ return byte[].class;
+ }
+
+ public boolean isDateTimeCapable() {
+ return baseType.isDateTimeCapable();
+ }
+
+ public boolean isJdbcNative() {
+ return baseType.isJdbcNative();
+ }
+
+ public void loadIgnore(DataReader dataReader) {
+ baseType.loadIgnore(dataReader);
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, byte[] value) throws IOException {
+ ctx.writeBinaryField(name, (byte[]) value);
+ }
+
+ @Override
+ public byte[] jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream(500);
+ ctx.readBinaryValue(out);
+ return out.toByteArray();
+ }
+
+ public String format(Object v) {
+ throw new RuntimeException("Not used");
+ }
+
+ public String formatValue(byte[] v) {
+ throw new RuntimeException("Not used");
+ }
+
+ public byte[] parse(String value) {
+ return baseType.parse(value);
+ }
+
+ public byte[] convertFromMillis(long systemTimeMillis) {
+ return baseType.convertFromMillis(systemTimeMillis);
+ }
+
+ public byte[] read(DataReader dataReader) throws SQLException {
+
+ byte[] data = baseType.read(dataReader);
+ data = dataEncryptSupport.decrypt(data);
+ return data;
+ }
+
+ public byte[] toBeanType(Object value) {
+ return baseType.toBeanType(value);
+ }
+
+ public Object toJdbcType(Object value) {
+ return baseType.toJdbcType(value);
+ }
+
+ public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
+ baseType.accumulateScalarTypes(propName, list);
+ }
+
+ public byte[] readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ int len = dataInput.readInt();
+ byte[] value = new byte[len];
+ dataInput.readFully(value);
+ return value;
+ }
+ }
+
+ public void writeData(DataOutput dataOutput, byte[] value) throws IOException {
+
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeInt(value.length);
+ dataOutput.write(value);
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesLongVarbinary.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesLongVarbinary.java
index 3a40e3ee9..6aa95f9fe 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesLongVarbinary.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesLongVarbinary.java
@@ -1,18 +1,18 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.SQLException;
-import java.sql.Types;
-
-/**
- * ScalarType for Longvarbinary.
- */
-public class ScalarTypeBytesLongVarbinary extends ScalarTypeBytesBase {
-
- public ScalarTypeBytesLongVarbinary() {
- super(true, Types.LONGVARBINARY);
- }
-
- public byte[] read(DataReader dataReader) throws SQLException {
- return dataReader.getBinaryBytes();
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * ScalarType for Longvarbinary.
+ */
+public class ScalarTypeBytesLongVarbinary extends ScalarTypeBytesBase {
+
+ public ScalarTypeBytesLongVarbinary() {
+ super(true, Types.LONGVARBINARY);
+ }
+
+ public byte[] read(DataReader dataReader) throws SQLException {
+ return dataReader.getBinaryBytes();
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesVarbinary.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesVarbinary.java
index 7ea8f4a5f..e1ee46889 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesVarbinary.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeBytesVarbinary.java
@@ -1,19 +1,19 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.SQLException;
-import java.sql.Types;
-
-/**
- * ScalarType for Types.VARBINARY to byte[].
- */
-public class ScalarTypeBytesVarbinary extends ScalarTypeBytesBase {
-
- public ScalarTypeBytesVarbinary() {
- super(true, Types.VARBINARY);
- }
-
- public byte[] read(DataReader dataReader) throws SQLException {
- return dataReader.getBytes();
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * ScalarType for Types.VARBINARY to byte[].
+ */
+public class ScalarTypeBytesVarbinary extends ScalarTypeBytesBase {
+
+ public ScalarTypeBytesVarbinary() {
+ super(true, Types.VARBINARY);
+ }
+
+ public byte[] read(DataReader dataReader) throws SQLException {
+ return dataReader.getBytes();
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCalendar.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCalendar.java
index ee790cc87..1df451c41 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCalendar.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCalendar.java
@@ -1,80 +1,80 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.Date;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.util.Calendar;
-
-import com.avaje.ebean.config.JsonConfig;
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-/**
- * ScalarType for java.util.Calendar.
- */
-public class ScalarTypeCalendar extends ScalarTypeBaseDateTime {
-
- public ScalarTypeCalendar(JsonConfig.DateTime mode, int jdbcType) {
- super(mode, Calendar.class, false, jdbcType);
- }
-
- public void bind(DataBind b, Calendar value) throws SQLException {
- if (value == null) {
- b.setNull(Types.TIMESTAMP);
- } else {
-
- if (jdbcType == Types.TIMESTAMP) {
- Timestamp timestamp = new Timestamp(value.getTimeInMillis());
- b.setTimestamp(timestamp);
- } else {
- Date d = new Date(value.getTimeInMillis());
- b.setDate(d);
- }
- }
- }
-
- @Override
- public Calendar convertFromMillis(long systemTimeMillis) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(systemTimeMillis);
- return calendar;
- }
-
- @Override
- public Calendar convertFromTimestamp(Timestamp ts) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTimeInMillis(ts.getTime());
- return calendar;
- }
-
- @Override
- protected String toJsonNanos(Calendar value) {
- return String.valueOf(value.getTime());
- }
-
- @Override
- protected String toJsonISO8601(Calendar value) {
- return dateTimeParser.format(value.getTime());
- }
-
- @Override
- public long convertToMillis(Calendar value) {
- return value.getTimeInMillis();
- }
-
- @Override
- public Timestamp convertToTimestamp(Calendar t) {
- return new Timestamp(t.getTimeInMillis());
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.convert(value, jdbcType);
- }
-
- @Override
- public Calendar toBeanType(Object value) {
- return BasicTypeConverter.toCalendar(value);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.Calendar;
+
+import com.avaje.ebean.config.JsonConfig;
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+/**
+ * ScalarType for java.util.Calendar.
+ */
+public class ScalarTypeCalendar extends ScalarTypeBaseDateTime {
+
+ public ScalarTypeCalendar(JsonConfig.DateTime mode, int jdbcType) {
+ super(mode, Calendar.class, false, jdbcType);
+ }
+
+ public void bind(DataBind b, Calendar value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.TIMESTAMP);
+ } else {
+
+ if (jdbcType == Types.TIMESTAMP) {
+ Timestamp timestamp = new Timestamp(value.getTimeInMillis());
+ b.setTimestamp(timestamp);
+ } else {
+ Date d = new Date(value.getTimeInMillis());
+ b.setDate(d);
+ }
+ }
+ }
+
+ @Override
+ public Calendar convertFromMillis(long systemTimeMillis) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(systemTimeMillis);
+ return calendar;
+ }
+
+ @Override
+ public Calendar convertFromTimestamp(Timestamp ts) {
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTimeInMillis(ts.getTime());
+ return calendar;
+ }
+
+ @Override
+ protected String toJsonNanos(Calendar value) {
+ return String.valueOf(value.getTime());
+ }
+
+ @Override
+ protected String toJsonISO8601(Calendar value) {
+ return dateTimeParser.format(value.getTime());
+ }
+
+ @Override
+ public long convertToMillis(Calendar value) {
+ return value.getTimeInMillis();
+ }
+
+ @Override
+ public Timestamp convertToTimestamp(Calendar t) {
+ return new Timestamp(t.getTimeInMillis());
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.convert(value, jdbcType);
+ }
+
+ @Override
+ public Calendar toBeanType(Object value) {
+ return BasicTypeConverter.toCalendar(value);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeChar.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeChar.java
index 7abe7c09c..567e3bd38 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeChar.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeChar.java
@@ -1,62 +1,62 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-/**
- * ScalarType for char.
- */
-public class ScalarTypeChar extends ScalarTypeBaseVarchar {
-
- public ScalarTypeChar() {
- super(char.class, false, Types.VARCHAR);
- }
-
- @Override
- public Character convertFromDbString(String dbValue) {
- return dbValue.charAt(0);
- }
-
- @Override
- public String convertToDbString(Character beanValue) {
- return beanValue.toString();
- }
-
- public void bind(DataBind b, Character value) throws SQLException {
- if (value == null) {
- b.setNull(Types.VARCHAR);
- } else {
- String s = BasicTypeConverter.toString(value);
- b.setString(s);
- }
- }
-
- public Character read(DataReader dataReader) throws SQLException {
- String string = dataReader.getString();
- if (string == null || string.length() == 0) {
- return null;
- } else {
- return string.charAt(0);
- }
- }
-
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toString(value);
- }
-
- public Character toBeanType(Object value) {
- String s = BasicTypeConverter.toString(value);
- return s.charAt(0);
- }
-
- public String formatValue(Character t) {
- return t.toString();
- }
-
- public Character parse(String value) {
- return value.charAt(0);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+/**
+ * ScalarType for char.
+ */
+public class ScalarTypeChar extends ScalarTypeBaseVarchar {
+
+ public ScalarTypeChar() {
+ super(char.class, false, Types.VARCHAR);
+ }
+
+ @Override
+ public Character convertFromDbString(String dbValue) {
+ return dbValue.charAt(0);
+ }
+
+ @Override
+ public String convertToDbString(Character beanValue) {
+ return beanValue.toString();
+ }
+
+ public void bind(DataBind b, Character value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.VARCHAR);
+ } else {
+ String s = BasicTypeConverter.toString(value);
+ b.setString(s);
+ }
+ }
+
+ public Character read(DataReader dataReader) throws SQLException {
+ String string = dataReader.getString();
+ if (string == null || string.length() == 0) {
+ return null;
+ } else {
+ return string.charAt(0);
+ }
+ }
+
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toString(value);
+ }
+
+ public Character toBeanType(Object value) {
+ String s = BasicTypeConverter.toString(value);
+ return s.charAt(0);
+ }
+
+ public String formatValue(Character t) {
+ return t.toString();
+ }
+
+ public Character parse(String value) {
+ return value.charAt(0);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCharArray.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCharArray.java
index ec947202f..1394e5d86 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCharArray.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCharArray.java
@@ -1,74 +1,74 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for char[].
- */
-public class ScalarTypeCharArray extends ScalarTypeBaseVarchar {
-
- public ScalarTypeCharArray() {
- super(char[].class, false, Types.VARCHAR);
- }
-
- @Override
- public char[] convertFromDbString(String dbValue) {
- return dbValue.toCharArray();
- }
-
- @Override
- public String convertToDbString(char[] beanValue) {
- return new String(beanValue);
- }
-
- public void bind(DataBind b, char[] value) throws SQLException {
- if (value == null) {
- b.setNull(Types.VARCHAR);
- } else {
- String s = BasicTypeConverter.toString(value);
- b.setString(s);
- }
- }
-
- public char[] read(DataReader dataReader) throws SQLException {
- String string = dataReader.getString();
- if (string == null) {
- return null;
- } else {
- return string.toCharArray();
- }
- }
-
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toString(value);
- }
-
- public char[] toBeanType(Object value) {
- String s = BasicTypeConverter.toString(value);
- return s.toCharArray();
- }
-
- public String formatValue(char[] t) {
- return String.valueOf(t);
- }
-
- public char[] parse(String value) {
- return value.toCharArray();
- }
-
- @Override
- public char[] jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return ctx.getValueAsString().toCharArray();
- }
-
- public void jsonWrite(JsonGenerator ctx, String name, char[] value) throws IOException {
- ctx.writeStringField(name, String.valueOf(value));
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for char[].
+ */
+public class ScalarTypeCharArray extends ScalarTypeBaseVarchar {
+
+ public ScalarTypeCharArray() {
+ super(char[].class, false, Types.VARCHAR);
+ }
+
+ @Override
+ public char[] convertFromDbString(String dbValue) {
+ return dbValue.toCharArray();
+ }
+
+ @Override
+ public String convertToDbString(char[] beanValue) {
+ return new String(beanValue);
+ }
+
+ public void bind(DataBind b, char[] value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.VARCHAR);
+ } else {
+ String s = BasicTypeConverter.toString(value);
+ b.setString(s);
+ }
+ }
+
+ public char[] read(DataReader dataReader) throws SQLException {
+ String string = dataReader.getString();
+ if (string == null) {
+ return null;
+ } else {
+ return string.toCharArray();
+ }
+ }
+
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toString(value);
+ }
+
+ public char[] toBeanType(Object value) {
+ String s = BasicTypeConverter.toString(value);
+ return s.toCharArray();
+ }
+
+ public String formatValue(char[] t) {
+ return String.valueOf(t);
+ }
+
+ public char[] parse(String value) {
+ return value.toCharArray();
+ }
+
+ @Override
+ public char[] jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return ctx.getValueAsString().toCharArray();
+ }
+
+ public void jsonWrite(JsonGenerator ctx, String name, char[] value) throws IOException {
+ ctx.writeStringField(name, String.valueOf(value));
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClass.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClass.java
index 1a2a6683b..a1227e719 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClass.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClass.java
@@ -1,45 +1,45 @@
-package com.avaje.ebeaninternal.server.type;
-
-import javax.persistence.PersistenceException;
-
-/**
- * ScalarType for Class that persists it to VARCHAR column.
- *
- * @author emcgreal
- * @author rbygrave
- */
-@SuppressWarnings({ "rawtypes" })
-public class ScalarTypeClass extends ScalarTypeBaseVarchar {
-
- public ScalarTypeClass() {
- super(Class.class);
- }
-
- @Override
- public int getLength() {
- return 255;
- }
-
- @Override
- public Class> convertFromDbString(String dbValue) {
- return parse(dbValue);
- }
-
- @Override
- public String convertToDbString(Class beanValue) {
- return beanValue.getCanonicalName();
- }
-
- public String formatValue(Class v) {
- return v.getCanonicalName();
- }
-
- public Class> parse(String value) {
- try {
- return Class.forName(value);
- } catch (Exception e) {
- throw new PersistenceException("Unable to find Class " + value, e);
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import javax.persistence.PersistenceException;
+
+/**
+ * ScalarType for Class that persists it to VARCHAR column.
+ *
+ * @author emcgreal
+ * @author rbygrave
+ */
+@SuppressWarnings({ "rawtypes" })
+public class ScalarTypeClass extends ScalarTypeBaseVarchar {
+
+ public ScalarTypeClass() {
+ super(Class.class);
+ }
+
+ @Override
+ public int getLength() {
+ return 255;
+ }
+
+ @Override
+ public Class> convertFromDbString(String dbValue) {
+ return parse(dbValue);
+ }
+
+ @Override
+ public String convertToDbString(Class beanValue) {
+ return beanValue.getCanonicalName();
+ }
+
+ public String formatValue(Class v) {
+ return v.getCanonicalName();
+ }
+
+ public Class> parse(String value) {
+ try {
+ return Class.forName(value);
+ } catch (Exception e) {
+ throw new PersistenceException("Unable to find Class " + value, e);
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClob.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClob.java
index c81469c66..d052373d5 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClob.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeClob.java
@@ -1,70 +1,70 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-/**
- * ScalarType for String.
- */
-public class ScalarTypeClob extends ScalarTypeBaseVarchar {
-
- static final int clobBufferSize = 512;
-
- static final int stringInitialSize = 512;
-
- protected ScalarTypeClob(boolean jdbcNative, int jdbcType) {
- super(String.class, jdbcNative, jdbcType);
- }
-
- public ScalarTypeClob() {
- super(String.class, true, Types.CLOB);
- }
-
- @Override
- public String convertFromDbString(String dbValue) {
- return dbValue;
- }
-
- @Override
- public String convertToDbString(String beanValue) {
- return beanValue;
- }
-
- @Override
- public void bind(DataBind b, String value) throws SQLException {
- if (value == null) {
- b.setNull(Types.VARCHAR);
- } else {
- b.setString(value);
- }
- }
-
- @Override
- public String read(DataReader dataReader) throws SQLException {
-
- return dataReader.getStringClob();
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toString(value);
- }
-
- @Override
- public String toBeanType(Object value) {
- return BasicTypeConverter.toString(value);
- }
-
- @Override
- public String formatValue(String t) {
- return t;
- }
-
- @Override
- public String parse(String value) {
- return value;
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+/**
+ * ScalarType for String.
+ */
+public class ScalarTypeClob extends ScalarTypeBaseVarchar {
+
+ static final int clobBufferSize = 512;
+
+ static final int stringInitialSize = 512;
+
+ protected ScalarTypeClob(boolean jdbcNative, int jdbcType) {
+ super(String.class, jdbcNative, jdbcType);
+ }
+
+ public ScalarTypeClob() {
+ super(String.class, true, Types.CLOB);
+ }
+
+ @Override
+ public String convertFromDbString(String dbValue) {
+ return dbValue;
+ }
+
+ @Override
+ public String convertToDbString(String beanValue) {
+ return beanValue;
+ }
+
+ @Override
+ public void bind(DataBind b, String value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.VARCHAR);
+ } else {
+ b.setString(value);
+ }
+ }
+
+ @Override
+ public String read(DataReader dataReader) throws SQLException {
+
+ return dataReader.getStringClob();
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toString(value);
+ }
+
+ @Override
+ public String toBeanType(Object value) {
+ return BasicTypeConverter.toString(value);
+ }
+
+ @Override
+ public String formatValue(String t) {
+ return t;
+ }
+
+ @Override
+ public String parse(String value) {
+ return value;
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCurrency.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCurrency.java
index e70d11d87..076c65c21 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCurrency.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeCurrency.java
@@ -1,39 +1,39 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.util.Currency;
-
-/**
- * ScalarType for java.util.Currency which converts to and from a VARCHAR database column.
- */
-public class ScalarTypeCurrency extends ScalarTypeBaseVarchar {
-
- public ScalarTypeCurrency() {
- super(Currency.class);
- }
-
- @Override
- public int getLength() {
- return 3;
- }
-
- @Override
- public Currency convertFromDbString(String dbValue) {
- return Currency.getInstance(dbValue);
- }
-
- @Override
- public String convertToDbString(Currency beanValue) {
- return ((Currency) beanValue).getCurrencyCode();
- }
-
- @Override
- public String formatValue(Currency v) {
- return v.toString();
- }
-
- @Override
- public Currency parse(String value) {
- return Currency.getInstance(value);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.util.Currency;
+
+/**
+ * ScalarType for java.util.Currency which converts to and from a VARCHAR database column.
+ */
+public class ScalarTypeCurrency extends ScalarTypeBaseVarchar {
+
+ public ScalarTypeCurrency() {
+ super(Currency.class);
+ }
+
+ @Override
+ public int getLength() {
+ return 3;
+ }
+
+ @Override
+ public Currency convertFromDbString(String dbValue) {
+ return Currency.getInstance(dbValue);
+ }
+
+ @Override
+ public String convertToDbString(Currency beanValue) {
+ return ((Currency) beanValue).getCurrencyCode();
+ }
+
+ @Override
+ public String formatValue(Currency v) {
+ return v.toString();
+ }
+
+ @Override
+ public Currency parse(String value) {
+ return Currency.getInstance(value);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDate.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDate.java
index 21b373007..986c273aa 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDate.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDate.java
@@ -1,53 +1,53 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.Date;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-/**
- * ScalarType for java.sql.Date.
- */
-public class ScalarTypeDate extends ScalarTypeBaseDate {
-
- public ScalarTypeDate() {
- super(Date.class, true, Types.DATE);
- }
-
- @Override
- public long convertToMillis(Date value) {
- return value.getTime();
- }
-
- @Override
- public Date convertFromDate(Date date) {
- return date;
- }
-
- @Override
- public Date convertToDate(Date t) {
- return t;
- }
-
- public void bind(DataBind b, java.sql.Date value) throws SQLException {
- if (value == null) {
- b.setNull(Types.DATE);
- } else {
- b.setDate(value);
- }
- }
-
- public java.sql.Date read(DataReader dataReader) throws SQLException {
- return dataReader.getDate();
- }
-
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toDate(value);
- }
-
- public java.sql.Date toBeanType(Object value) {
- return BasicTypeConverter.toDate(value);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.Date;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+/**
+ * ScalarType for java.sql.Date.
+ */
+public class ScalarTypeDate extends ScalarTypeBaseDate {
+
+ public ScalarTypeDate() {
+ super(Date.class, true, Types.DATE);
+ }
+
+ @Override
+ public long convertToMillis(Date value) {
+ return value.getTime();
+ }
+
+ @Override
+ public Date convertFromDate(Date date) {
+ return date;
+ }
+
+ @Override
+ public Date convertToDate(Date t) {
+ return t;
+ }
+
+ public void bind(DataBind b, java.sql.Date value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.DATE);
+ } else {
+ b.setDate(value);
+ }
+ }
+
+ public java.sql.Date read(DataReader dataReader) throws SQLException {
+ return dataReader.getDate();
+ }
+
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toDate(value);
+ }
+
+ public java.sql.Date toBeanType(Object value) {
+ return BasicTypeConverter.toDate(value);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDouble.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDouble.java
index 10b5c97fe..ce8c4f3ad 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDouble.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDouble.java
@@ -1,96 +1,96 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for Double and double.
- */
-public class ScalarTypeDouble extends ScalarTypeBase {
-
- public ScalarTypeDouble() {
- super(Double.class, true, Types.DOUBLE);
- }
-
- @Override
- public void bind(DataBind b, Double value) throws SQLException {
- if (value == null) {
- b.setNull(Types.DOUBLE);
- } else {
- b.setDouble(value.doubleValue());
- }
- }
-
- @Override
- public Double read(DataReader dataReader) throws SQLException {
- return dataReader.getDouble();
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toDouble(value);
- }
-
- @Override
- public Double toBeanType(Object value) {
- return BasicTypeConverter.toDouble(value);
- }
-
- @Override
- public String formatValue(Double t) {
- return t.toString();
- }
-
- @Override
- public Double parse(String value) {
- return Double.valueOf(value);
- }
-
- @Override
- public Double convertFromMillis(long systemTimeMillis) {
- return Double.valueOf(systemTimeMillis);
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return true;
- }
-
- @Override
- public Double readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- return dataInput.readDouble();
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, Double value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeDouble(value);
- }
- }
-
- @Override
- public Double jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return ctx.getDoubleValue();
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, Double value) throws IOException {
- ctx.writeNumberField(name, value);
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for Double and double.
+ */
+public class ScalarTypeDouble extends ScalarTypeBase {
+
+ public ScalarTypeDouble() {
+ super(Double.class, true, Types.DOUBLE);
+ }
+
+ @Override
+ public void bind(DataBind b, Double value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.DOUBLE);
+ } else {
+ b.setDouble(value.doubleValue());
+ }
+ }
+
+ @Override
+ public Double read(DataReader dataReader) throws SQLException {
+ return dataReader.getDouble();
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toDouble(value);
+ }
+
+ @Override
+ public Double toBeanType(Object value) {
+ return BasicTypeConverter.toDouble(value);
+ }
+
+ @Override
+ public String formatValue(Double t) {
+ return t.toString();
+ }
+
+ @Override
+ public Double parse(String value) {
+ return Double.valueOf(value);
+ }
+
+ @Override
+ public Double convertFromMillis(long systemTimeMillis) {
+ return Double.valueOf(systemTimeMillis);
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return true;
+ }
+
+ @Override
+ public Double readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ return dataInput.readDouble();
+ }
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, Double value) throws IOException {
+
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeDouble(value);
+ }
+ }
+
+ @Override
+ public Double jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return ctx.getDoubleValue();
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, Double value) throws IOException {
+ ctx.writeNumberField(name, value);
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDuration.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDuration.java
index 7e5937b45..5cd093ed3 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDuration.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDuration.java
@@ -1,113 +1,113 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebean.text.TextException;
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.time.Duration;
-
-/**
- * ScalarType for java.time.Duration (with seconds precision).
- */
-public class ScalarTypeDuration extends ScalarTypeBase {
-
- public ScalarTypeDuration() {
- super(Duration.class, false, Types.BIGINT);
- }
-
- protected ScalarTypeDuration(int jdbcType) {
- super(Duration.class, false, jdbcType);
- }
-
- public BigDecimal convertToBigDecimal(Duration value) {
- return (value == null) ? null : DecimalUtils.toDecimal(value);
- }
-
- public Duration convertFromBigDecimal(BigDecimal value) {
- return (value == null) ? null : DecimalUtils.toDuration(value);
- }
-
- @Override
- public void bind(DataBind bind, Duration value) throws SQLException {
- if (value == null) {
- bind.setNull(Types.BIGINT);
- } else {
- bind.setLong(value.getSeconds());
- }
- }
-
- @Override
- public Duration read(DataReader dataReader) throws SQLException {
- Long value = dataReader.getLong();
- return (value == null) ? null : Duration.ofSeconds(value);
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof Long) return value;
- return ((Duration)value).getSeconds();
- }
-
- @Override
- public Duration toBeanType(Object value) {
- if (value instanceof Duration) return (Duration) value;
- return Duration.ofSeconds(BasicTypeConverter.toLong(value));
- }
-
- @Override
- public Duration readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- return convertFromBigDecimal(new BigDecimal(dataInput.readUTF()));
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, Duration value) throws IOException {
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeUTF(convertToBigDecimal(value).toString());
- }
- }
-
- @Override
- public String formatValue(Duration v) {
- return v.toString();
- }
-
- @Override
- public Duration parse(String value) {
- return Duration.parse(value);
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return false;
- }
-
- @Override
- public Duration convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not Supported");
- }
-
- @Override
- public Duration jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return Duration.parse(ctx.getValueAsString());
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, Duration value) throws IOException {
- ctx.writeStringField(name, value.toString());
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebean.text.TextException;
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.time.Duration;
+
+/**
+ * ScalarType for java.time.Duration (with seconds precision).
+ */
+public class ScalarTypeDuration extends ScalarTypeBase {
+
+ public ScalarTypeDuration() {
+ super(Duration.class, false, Types.BIGINT);
+ }
+
+ protected ScalarTypeDuration(int jdbcType) {
+ super(Duration.class, false, jdbcType);
+ }
+
+ public BigDecimal convertToBigDecimal(Duration value) {
+ return (value == null) ? null : DecimalUtils.toDecimal(value);
+ }
+
+ public Duration convertFromBigDecimal(BigDecimal value) {
+ return (value == null) ? null : DecimalUtils.toDuration(value);
+ }
+
+ @Override
+ public void bind(DataBind bind, Duration value) throws SQLException {
+ if (value == null) {
+ bind.setNull(Types.BIGINT);
+ } else {
+ bind.setLong(value.getSeconds());
+ }
+ }
+
+ @Override
+ public Duration read(DataReader dataReader) throws SQLException {
+ Long value = dataReader.getLong();
+ return (value == null) ? null : Duration.ofSeconds(value);
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof Long) return value;
+ return ((Duration)value).getSeconds();
+ }
+
+ @Override
+ public Duration toBeanType(Object value) {
+ if (value instanceof Duration) return (Duration) value;
+ return Duration.ofSeconds(BasicTypeConverter.toLong(value));
+ }
+
+ @Override
+ public Duration readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ return convertFromBigDecimal(new BigDecimal(dataInput.readUTF()));
+ }
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, Duration value) throws IOException {
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeUTF(convertToBigDecimal(value).toString());
+ }
+ }
+
+ @Override
+ public String formatValue(Duration v) {
+ return v.toString();
+ }
+
+ @Override
+ public Duration parse(String value) {
+ return Duration.parse(value);
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ @Override
+ public Duration convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not Supported");
+ }
+
+ @Override
+ public Duration jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return Duration.parse(ctx.getValueAsString());
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, Duration value) throws IOException {
+ ctx.writeStringField(name, value.toString());
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDurationWithNanos.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDurationWithNanos.java
index 1ff246375..42f05ffb8 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDurationWithNanos.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeDurationWithNanos.java
@@ -1,55 +1,55 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebean.text.TextException;
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.time.Duration;
-
-/**
- * ScalarType for java.time.Duration (with Nanos precision).
- *
- * Stored in the DB as DECIMAL value.
- *
- */
-public class ScalarTypeDurationWithNanos extends ScalarTypeDuration {
-
- public ScalarTypeDurationWithNanos() {
- super(Types.DECIMAL);
- }
-
- @Override
- public void bind(DataBind bind, Duration value) throws SQLException {
- if (value == null) {
- bind.setNull(Types.DECIMAL);
- } else {
- bind.setBigDecimal(convertToBigDecimal(value));
- }
- }
-
- @Override
- public Duration read(DataReader dataReader) throws SQLException {
- return convertFromBigDecimal(dataReader.getBigDecimal());
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof BigDecimal) return value;
- return convertToBigDecimal((Duration)value);
- }
-
- @Override
- public Duration toBeanType(Object value) {
- if (value instanceof Duration) return (Duration) value;
- return convertFromBigDecimal(BasicTypeConverter.toBigDecimal(value));
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebean.text.TextException;
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.time.Duration;
+
+/**
+ * ScalarType for java.time.Duration (with Nanos precision).
+ *
+ * Stored in the DB as DECIMAL value.
+ *
+ */
+public class ScalarTypeDurationWithNanos extends ScalarTypeDuration {
+
+ public ScalarTypeDurationWithNanos() {
+ super(Types.DECIMAL);
+ }
+
+ @Override
+ public void bind(DataBind bind, Duration value) throws SQLException {
+ if (value == null) {
+ bind.setNull(Types.DECIMAL);
+ } else {
+ bind.setBigDecimal(convertToBigDecimal(value));
+ }
+ }
+
+ @Override
+ public Duration read(DataReader dataReader) throws SQLException {
+ return convertFromBigDecimal(dataReader.getBigDecimal());
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof BigDecimal) return value;
+ return convertToBigDecimal((Duration)value);
+ }
+
+ @Override
+ public Duration toBeanType(Object value) {
+ if (value instanceof Duration) return (Duration) value;
+ return convertFromBigDecimal(BasicTypeConverter.toBigDecimal(value));
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java
index 041fd9471..49153679c 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEncryptedWrapper.java
@@ -1,144 +1,144 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-public class ScalarTypeEncryptedWrapper implements ScalarType {
-
- private final ScalarType wrapped;
-
- private final DataEncryptSupport dataEncryptSupport;
-
- private final ScalarTypeBytesBase byteArrayType;
-
- public ScalarTypeEncryptedWrapper(ScalarType wrapped, ScalarTypeBytesBase byteArrayType, DataEncryptSupport dataEncryptSupport) {
- this.wrapped = wrapped;
- this.byteArrayType = byteArrayType;
- this.dataEncryptSupport = dataEncryptSupport;
- }
-
- @Override
- public boolean isMutable() {
- return wrapped.isMutable();
- }
-
- @Override
- public boolean isDirty(Object value) {
- return wrapped.isDirty(value);
- }
-
- @Override
- public T readData(DataInput dataInput) throws IOException {
- return wrapped.readData(dataInput);
- }
-
- @Override
- public void writeData(DataOutput dataOutput, T v) throws IOException {
- wrapped.writeData(dataOutput, v);
- }
-
- @Override
- public T read(DataReader dataReader) throws SQLException {
-
- byte[] data = dataReader.getBytes();
- String formattedValue = dataEncryptSupport.decryptObject(data);
- if (formattedValue == null) {
- return null;
- }
- return wrapped.parse(formattedValue);
- }
-
- private byte[] encrypt(T value) {
- String formatValue = wrapped.formatValue(value);
- return dataEncryptSupport.encryptObject(formatValue);
- }
-
- @Override
- public void bind(DataBind b, T value) throws SQLException {
-
- byte[] encryptedValue = encrypt(value);
- byteArrayType.bind(b, encryptedValue);
- }
-
- @Override
- public int getJdbcType() {
- return byteArrayType.getJdbcType();
- }
-
- @Override
- public int getLength() {
- return byteArrayType.getLength();
- }
-
- @Override
- public Class getType() {
- return wrapped.getType();
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return wrapped.isDateTimeCapable();
- }
-
- @Override
- public boolean isJdbcNative() {
- return false;
- }
-
- @Override
- public void loadIgnore(DataReader dataReader) {
- wrapped.loadIgnore(dataReader);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public String format(Object v) {
- return formatValue((T) v);
- }
-
- @Override
- public String formatValue(T v) {
- return wrapped.formatValue(v);
- }
-
- @Override
- public T parse(String value) {
- return wrapped.parse(value);
- }
-
- @Override
- public T convertFromMillis(long systemTimeMillis) {
- return wrapped.convertFromMillis(systemTimeMillis);
- }
-
- @Override
- public T toBeanType(Object value) {
- return wrapped.toBeanType(value);
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return wrapped.toJdbcType(value);
- }
-
- @Override
- public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
- wrapped.accumulateScalarTypes(propName, list);
- }
-
- @Override
- public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return wrapped.jsonRead(ctx, event);
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
- wrapped.jsonWrite(ctx, name, value);
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+public class ScalarTypeEncryptedWrapper implements ScalarType {
+
+ private final ScalarType wrapped;
+
+ private final DataEncryptSupport dataEncryptSupport;
+
+ private final ScalarTypeBytesBase byteArrayType;
+
+ public ScalarTypeEncryptedWrapper(ScalarType wrapped, ScalarTypeBytesBase byteArrayType, DataEncryptSupport dataEncryptSupport) {
+ this.wrapped = wrapped;
+ this.byteArrayType = byteArrayType;
+ this.dataEncryptSupport = dataEncryptSupport;
+ }
+
+ @Override
+ public boolean isMutable() {
+ return wrapped.isMutable();
+ }
+
+ @Override
+ public boolean isDirty(Object value) {
+ return wrapped.isDirty(value);
+ }
+
+ @Override
+ public T readData(DataInput dataInput) throws IOException {
+ return wrapped.readData(dataInput);
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, T v) throws IOException {
+ wrapped.writeData(dataOutput, v);
+ }
+
+ @Override
+ public T read(DataReader dataReader) throws SQLException {
+
+ byte[] data = dataReader.getBytes();
+ String formattedValue = dataEncryptSupport.decryptObject(data);
+ if (formattedValue == null) {
+ return null;
+ }
+ return wrapped.parse(formattedValue);
+ }
+
+ private byte[] encrypt(T value) {
+ String formatValue = wrapped.formatValue(value);
+ return dataEncryptSupport.encryptObject(formatValue);
+ }
+
+ @Override
+ public void bind(DataBind b, T value) throws SQLException {
+
+ byte[] encryptedValue = encrypt(value);
+ byteArrayType.bind(b, encryptedValue);
+ }
+
+ @Override
+ public int getJdbcType() {
+ return byteArrayType.getJdbcType();
+ }
+
+ @Override
+ public int getLength() {
+ return byteArrayType.getLength();
+ }
+
+ @Override
+ public Class getType() {
+ return wrapped.getType();
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return wrapped.isDateTimeCapable();
+ }
+
+ @Override
+ public boolean isJdbcNative() {
+ return false;
+ }
+
+ @Override
+ public void loadIgnore(DataReader dataReader) {
+ wrapped.loadIgnore(dataReader);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public String format(Object v) {
+ return formatValue((T) v);
+ }
+
+ @Override
+ public String formatValue(T v) {
+ return wrapped.formatValue(v);
+ }
+
+ @Override
+ public T parse(String value) {
+ return wrapped.parse(value);
+ }
+
+ @Override
+ public T convertFromMillis(long systemTimeMillis) {
+ return wrapped.convertFromMillis(systemTimeMillis);
+ }
+
+ @Override
+ public T toBeanType(Object value) {
+ return wrapped.toBeanType(value);
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ return wrapped.toJdbcType(value);
+ }
+
+ @Override
+ public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
+ wrapped.accumulateScalarTypes(propName, list);
+ }
+
+ @Override
+ public T jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return wrapped.jsonRead(ctx, event);
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, T value) throws IOException {
+ wrapped.jsonWrite(ctx, name, value);
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumStandard.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumStandard.java
index b8e7014b5..4180250bb 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumStandard.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumStandard.java
@@ -1,265 +1,265 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.EnumSet;
-
-import com.avaje.ebean.text.TextException;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * JPA standard based Enum scalar type.
- *
- * Converts between bean Enum types to database string or integer columns.
- *
- *
- * The limitation of this class is that it converts the Enum to either the ordinal or string value
- * of the Enum. If you wish to convert the Enum to some other value then you should look at the
- * Ebean specific @EnumMapping.
- *
- */
-public class ScalarTypeEnumStandard {
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static class StringEnum extends EnumBase implements ScalarTypeEnum {
-
- private final int length;
-
- /**
- * Create a ScalarTypeEnum.
- */
- public StringEnum(Class enumType) {
- super(enumType, false, Types.VARCHAR);
- this.length = maxValueLength(enumType);
- }
-
- /**
- * Return the IN values for DB constraint construction.
- */
- public String getConstraintInValues() {
-
- StringBuilder sb = new StringBuilder();
-
- sb.append("(");
- Object[] ea = enumType.getEnumConstants();
- for (int i = 0; i < ea.length; i++) {
- Enum> e = (Enum>) ea[i];
- if (i > 0) {
- sb.append(",");
- }
- sb.append("'").append(e.name()).append("'");
- }
- sb.append(")");
-
- return sb.toString();
- }
-
- private int maxValueLength(Class> enumType) {
-
- int maxLen = 0;
-
- Object[] ea = enumType.getEnumConstants();
- for (int i = 0; i < ea.length; i++) {
- Enum> e = (Enum>) ea[i];
- maxLen = Math.max(maxLen, e.toString().length());
- }
-
- return maxLen;
- }
-
- public int getLength() {
- return length;
- }
-
- public void bind(DataBind b, Object value) throws SQLException {
- if (value == null) {
- b.setNull(Types.VARCHAR);
- } else {
- b.setString(format(value));
- }
- }
-
- public Object read(DataReader dataReader) throws SQLException {
-
- String string = dataReader.getString();
- if (string == null) {
- return null;
- } else {
- return parse(string);
- }
- }
-
- /**
- * Convert the Boolean value to the db value.
- */
- public Object toJdbcType(Object beanValue) {
- if (beanValue == null) {
- return null;
- }
- return beanValue.toString();
- }
-
- public Object toBeanType(Object dbValue) {
- if (dbValue == null || dbValue instanceof Enum>) {
- return dbValue;
- }
- return Enum.valueOf(enumType, (String) dbValue);
- }
-
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static class OrdinalEnum extends EnumBase implements ScalarTypeEnum {
-
- private final Object[] enumArray;
-
- /**
- * Create a ScalarTypeEnum.
- */
- public OrdinalEnum(Class enumType) {
- super(enumType, false, Types.INTEGER);
- this.enumArray = EnumSet.allOf(enumType).toArray();
- }
-
- /**
- * Return the IN values for DB constraint construction.
- */
- public String getConstraintInValues() {
-
- StringBuilder sb = new StringBuilder();
-
- sb.append("(");
- for (int i = 0; i < enumArray.length; i++) {
- Enum> e = (Enum>) enumArray[i];
- if (i > 0) {
- sb.append(",");
- }
- sb.append(e.ordinal());
- }
- sb.append(")");
-
- return sb.toString();
- }
-
- public void bind(DataBind b, Object value) throws SQLException {
- if (value == null) {
- b.setNull(Types.INTEGER);
- } else {
- b.setInt(((Enum>) value).ordinal());
- }
- }
-
- public Object read(DataReader dataReader) throws SQLException {
-
- Integer ordinal = dataReader.getInt();
- if (ordinal == null) {
- return null;
- } else {
- if (ordinal < 0 || ordinal >= enumArray.length) {
- String m = "Unexpected ordinal [" + ordinal + "] out of range [" + enumArray.length + "]";
- throw new IllegalStateException(m);
- }
- return enumArray[ordinal];
- }
- }
-
- /**
- * Convert the Enum value to the db value.
- */
- public Object toJdbcType(Object beanValue) {
- if (beanValue == null) {
- return null;
- }
- return ((Enum>) beanValue).ordinal();
- }
-
- /**
- * Convert the db value to the Enum value.
- */
- public Object toBeanType(Object dbValue) {
- if (dbValue == null || dbValue instanceof Enum>) {
- return dbValue;
- }
-
- int ordinal = (Integer) dbValue;
- if (ordinal < 0 || ordinal >= enumArray.length) {
- String m = "Unexpected ordinal [" + ordinal + "] out of range [" + enumArray.length + "]";
- throw new IllegalStateException(m);
- }
- return enumArray[ordinal];
- }
-
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public abstract static class EnumBase extends ScalarTypeBase {
-
- protected final Class enumType;
-
- public EnumBase(Class> type, boolean jdbcNative, int jdbcType) {
- super(type, jdbcNative, jdbcType);
- this.enumType = type;
- }
-
- @Override
- public String format(Object t) {
- return ((Enum>) t).name();
- }
-
- @Override
- public String formatValue(Object t) {
- return ((Enum>) t).name();
- }
-
- @Override
- public Object parse(String value) {
- return Enum.valueOf(enumType, value);
- }
-
- @Override
- public Object convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not Supported");
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return false;
- }
-
- @Override
- public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return parse(ctx.getValueAsString());
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
- ctx.writeStringField(name, formatValue(value));
- }
-
- @Override
- public Object readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- String s = dataInput.readUTF();
- return parse(s);
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, Object v) throws IOException {
- if (v == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeUTF(format(v));
- }
- }
-
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.EnumSet;
+
+import com.avaje.ebean.text.TextException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * JPA standard based Enum scalar type.
+ *
+ * Converts between bean Enum types to database string or integer columns.
+ *
+ *
+ * The limitation of this class is that it converts the Enum to either the ordinal or string value
+ * of the Enum. If you wish to convert the Enum to some other value then you should look at the
+ * Ebean specific @EnumMapping.
+ *
+ */
+public class ScalarTypeEnumStandard {
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public static class StringEnum extends EnumBase implements ScalarTypeEnum {
+
+ private final int length;
+
+ /**
+ * Create a ScalarTypeEnum.
+ */
+ public StringEnum(Class enumType) {
+ super(enumType, false, Types.VARCHAR);
+ this.length = maxValueLength(enumType);
+ }
+
+ /**
+ * Return the IN values for DB constraint construction.
+ */
+ public String getConstraintInValues() {
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(");
+ Object[] ea = enumType.getEnumConstants();
+ for (int i = 0; i < ea.length; i++) {
+ Enum> e = (Enum>) ea[i];
+ if (i > 0) {
+ sb.append(",");
+ }
+ sb.append("'").append(e.name()).append("'");
+ }
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ private int maxValueLength(Class> enumType) {
+
+ int maxLen = 0;
+
+ Object[] ea = enumType.getEnumConstants();
+ for (int i = 0; i < ea.length; i++) {
+ Enum> e = (Enum>) ea[i];
+ maxLen = Math.max(maxLen, e.toString().length());
+ }
+
+ return maxLen;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public void bind(DataBind b, Object value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.VARCHAR);
+ } else {
+ b.setString(format(value));
+ }
+ }
+
+ public Object read(DataReader dataReader) throws SQLException {
+
+ String string = dataReader.getString();
+ if (string == null) {
+ return null;
+ } else {
+ return parse(string);
+ }
+ }
+
+ /**
+ * Convert the Boolean value to the db value.
+ */
+ public Object toJdbcType(Object beanValue) {
+ if (beanValue == null) {
+ return null;
+ }
+ return beanValue.toString();
+ }
+
+ public Object toBeanType(Object dbValue) {
+ if (dbValue == null || dbValue instanceof Enum>) {
+ return dbValue;
+ }
+ return Enum.valueOf(enumType, (String) dbValue);
+ }
+
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public static class OrdinalEnum extends EnumBase implements ScalarTypeEnum {
+
+ private final Object[] enumArray;
+
+ /**
+ * Create a ScalarTypeEnum.
+ */
+ public OrdinalEnum(Class enumType) {
+ super(enumType, false, Types.INTEGER);
+ this.enumArray = EnumSet.allOf(enumType).toArray();
+ }
+
+ /**
+ * Return the IN values for DB constraint construction.
+ */
+ public String getConstraintInValues() {
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("(");
+ for (int i = 0; i < enumArray.length; i++) {
+ Enum> e = (Enum>) enumArray[i];
+ if (i > 0) {
+ sb.append(",");
+ }
+ sb.append(e.ordinal());
+ }
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ public void bind(DataBind b, Object value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.INTEGER);
+ } else {
+ b.setInt(((Enum>) value).ordinal());
+ }
+ }
+
+ public Object read(DataReader dataReader) throws SQLException {
+
+ Integer ordinal = dataReader.getInt();
+ if (ordinal == null) {
+ return null;
+ } else {
+ if (ordinal < 0 || ordinal >= enumArray.length) {
+ String m = "Unexpected ordinal [" + ordinal + "] out of range [" + enumArray.length + "]";
+ throw new IllegalStateException(m);
+ }
+ return enumArray[ordinal];
+ }
+ }
+
+ /**
+ * Convert the Enum value to the db value.
+ */
+ public Object toJdbcType(Object beanValue) {
+ if (beanValue == null) {
+ return null;
+ }
+ return ((Enum>) beanValue).ordinal();
+ }
+
+ /**
+ * Convert the db value to the Enum value.
+ */
+ public Object toBeanType(Object dbValue) {
+ if (dbValue == null || dbValue instanceof Enum>) {
+ return dbValue;
+ }
+
+ int ordinal = (Integer) dbValue;
+ if (ordinal < 0 || ordinal >= enumArray.length) {
+ String m = "Unexpected ordinal [" + ordinal + "] out of range [" + enumArray.length + "]";
+ throw new IllegalStateException(m);
+ }
+ return enumArray[ordinal];
+ }
+
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public abstract static class EnumBase extends ScalarTypeBase {
+
+ protected final Class enumType;
+
+ public EnumBase(Class> type, boolean jdbcNative, int jdbcType) {
+ super(type, jdbcNative, jdbcType);
+ this.enumType = type;
+ }
+
+ @Override
+ public String format(Object t) {
+ return ((Enum>) t).name();
+ }
+
+ @Override
+ public String formatValue(Object t) {
+ return ((Enum>) t).name();
+ }
+
+ @Override
+ public Object parse(String value) {
+ return Enum.valueOf(enumType, value);
+ }
+
+ @Override
+ public Object convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not Supported");
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ @Override
+ public Object jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return parse(ctx.getValueAsString());
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, Object value) throws IOException {
+ ctx.writeStringField(name, formatValue(value));
+ }
+
+ @Override
+ public Object readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ String s = dataInput.readUTF();
+ return parse(s);
+ }
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, Object v) throws IOException {
+ if (v == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeUTF(format(v));
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java
index a7f26f86e..cedb8e767 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeEnumWithMapping.java
@@ -1,85 +1,85 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.SQLException;
-import java.util.Iterator;
-
-/**
- * Additional control over mapping to DB values.
- */
-@SuppressWarnings({ "unchecked", "rawtypes" })
-public class ScalarTypeEnumWithMapping extends ScalarTypeEnumStandard.EnumBase implements ScalarType, ScalarTypeEnum {
-
- private final EnumToDbValueMap beanDbMap;
-
- private final int length;
-
- /**
- * Create with an explicit mapping of bean to database values.
- */
- public ScalarTypeEnumWithMapping(EnumToDbValueMap> beanDbMap, Class> enumType, int length) {
- super(enumType, false, beanDbMap.getDbType());
- this.beanDbMap = beanDbMap;
- this.length = length;
- }
-
- /**
- * Return the IN values for DB constraint construction.
- */
- public String getConstraintInValues() {
-
- StringBuilder sb = new StringBuilder();
-
- int i = 0;
-
- sb.append("(");
-
- Iterator> it = beanDbMap.dbValues();
- while (it.hasNext()) {
- Object dbValue = it.next();
- if (i++ > 0) {
- sb.append(",");
- }
- if (!beanDbMap.isIntegerType()) {
- sb.append("'");
- }
- sb.append(dbValue.toString());
- if (!beanDbMap.isIntegerType()) {
- sb.append("'");
- }
- }
-
- sb.append(")");
-
- return sb.toString();
- }
-
- /**
- * Return the DB column length for storing the enum value.
- *
- * This is for enum's mapped to strings.
- *
- */
- public int getLength() {
- return length;
- }
-
- public void bind(DataBind b, Object value) throws SQLException {
- beanDbMap.bind(b, value);
- }
-
- public Object read(DataReader dataReader) throws SQLException {
- return beanDbMap.read(dataReader);
- }
-
- public Object toBeanType(Object dbValue) {
- if (dbValue == null || dbValue instanceof Enum>) {
- return dbValue;
- }
- return beanDbMap.getBeanValue(dbValue);
- }
-
- public Object toJdbcType(Object beanValue) {
- return beanDbMap.getDbValue(beanValue);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.SQLException;
+import java.util.Iterator;
+
+/**
+ * Additional control over mapping to DB values.
+ */
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public class ScalarTypeEnumWithMapping extends ScalarTypeEnumStandard.EnumBase implements ScalarType, ScalarTypeEnum {
+
+ private final EnumToDbValueMap beanDbMap;
+
+ private final int length;
+
+ /**
+ * Create with an explicit mapping of bean to database values.
+ */
+ public ScalarTypeEnumWithMapping(EnumToDbValueMap> beanDbMap, Class> enumType, int length) {
+ super(enumType, false, beanDbMap.getDbType());
+ this.beanDbMap = beanDbMap;
+ this.length = length;
+ }
+
+ /**
+ * Return the IN values for DB constraint construction.
+ */
+ public String getConstraintInValues() {
+
+ StringBuilder sb = new StringBuilder();
+
+ int i = 0;
+
+ sb.append("(");
+
+ Iterator> it = beanDbMap.dbValues();
+ while (it.hasNext()) {
+ Object dbValue = it.next();
+ if (i++ > 0) {
+ sb.append(",");
+ }
+ if (!beanDbMap.isIntegerType()) {
+ sb.append("'");
+ }
+ sb.append(dbValue.toString());
+ if (!beanDbMap.isIntegerType()) {
+ sb.append("'");
+ }
+ }
+
+ sb.append(")");
+
+ return sb.toString();
+ }
+
+ /**
+ * Return the DB column length for storing the enum value.
+ *
+ * This is for enum's mapped to strings.
+ *
+ */
+ public int getLength() {
+ return length;
+ }
+
+ public void bind(DataBind b, Object value) throws SQLException {
+ beanDbMap.bind(b, value);
+ }
+
+ public Object read(DataReader dataReader) throws SQLException {
+ return beanDbMap.read(dataReader);
+ }
+
+ public Object toBeanType(Object dbValue) {
+ if (dbValue == null || dbValue instanceof Enum>) {
+ return dbValue;
+ }
+ return beanDbMap.getBeanValue(dbValue);
+ }
+
+ public Object toJdbcType(Object beanValue) {
+ return beanDbMap.getDbValue(beanValue);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFile.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFile.java
index 074f4ece1..ca6a6a6fe 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFile.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFile.java
@@ -1,193 +1,193 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebean.text.TextException;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.*;
-import java.sql.SQLException;
-import java.sql.Types;
-
-/**
- * ScalarType for streaming between a File and the database.
- */
-public class ScalarTypeFile extends ScalarTypeBase {
-
- private static Logger logger = LoggerFactory.getLogger(ScalarTypeFile.class);
-
- private final String prefix;
-
- private final String suffix;
-
- private final File directory;
-
- private final int bufferSize;
-
- /**
- * Construct with reasonable defaults of Blob and 8096 buffer size.
- */
- public ScalarTypeFile() {
- this(Types.BLOB, "db-", null, null, 8096);
- }
-
- /**
- * Create the ScalarTypeFile.
- */
- public ScalarTypeFile(int jdbcType, String prefix, String suffix, File directory, int bufferSize) {
- super(File.class, false, jdbcType);
- this.prefix = prefix;
- this.suffix = suffix;
- this.directory = directory;
- this.bufferSize = bufferSize;
- }
-
- private InputStream getInputStream(File value) throws IOException {
- FileInputStream fi = new FileInputStream(value);
- return new BufferedInputStream(fi, bufferSize);
- }
-
- private OutputStream getOutputStream(File value) throws IOException {
- FileOutputStream fi = new FileOutputStream(value);
- return new BufferedOutputStream(fi, bufferSize);
- }
-
- @Override
- public File read(DataReader dataReader) throws SQLException {
-
- InputStream is = dataReader.getBinaryStream();
- if (is == null) {
- return null;
- }
-
- try {
- // stream from db into our temp file
- File tempFile = File.createTempFile(prefix, suffix, directory);
- OutputStream os = getOutputStream(tempFile);
- pump(is, os);
-
- return tempFile;
-
- } catch (IOException e) {
- throw new SQLException("Error reading db file inputStream", e);
- }
- }
-
-
- @Override
- public void bind(DataBind b, File value) throws SQLException {
- if (value == null) {
- b.setNull(jdbcType);
- } else {
- try {
- // stream from our file to the db
- InputStream fi = getInputStream(value);
- b.setBlob(fi, value.length());
- } catch (IOException e) {
- throw new SQLException("Error trying to set file inputStream", e);
- }
- }
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return value;
- }
-
- @Override
- public File toBeanType(Object value) {
- return (File) value;
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, File value) throws IOException {
- ctx.writeFieldName(name);
- InputStream is = getInputStream(value);
- ctx.writeBinary(is, (int) value.length());
- }
-
- @Override
- public File jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- File tempFile = File.createTempFile(prefix, suffix, directory);
- OutputStream os = getOutputStream(tempFile);
- ctx.readBinaryValue(os);
- os.flush();
- os.close();
- return tempFile;
- }
-
- @Override
- public String formatValue(File file) {
- throw new TextException("Not supported");
- }
-
- @Override
- public File parse(String value) {
- throw new TextException("Not supported");
- }
-
- @Override
- public File convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not supported");
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return false;
- }
-
- @Override
- public File readData(DataInput dataInput) throws IOException {
- // skip reading large file
- return null;
- }
-
- public void writeData(DataOutput dataOutput, File file) throws IOException {
- // skip writing large file
- }
-
- /**
- * Helper method to pump bytes from input to output.
- */
- public long pump(InputStream is, OutputStream out) throws IOException {
-
- long totalBytes = 0;
- InputStream input = null;
- OutputStream output = null;
-
- try {
- input = new BufferedInputStream(is, bufferSize);
- output = new BufferedOutputStream(out, bufferSize);
-
- byte[] buffer = new byte[bufferSize];
- int length;
- while (((length = input.read(buffer)) > 0)) {
- output.write(buffer, 0, length);
- totalBytes += length;
- }
-
- output.flush();
-
- return totalBytes;
-
- } finally {
- if (output != null) {
- try {
- output.close();
- } catch (IOException e) {
- logger.error("Error when closing outputstream", e);
- }
- }
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {
- logger.error("Error when closing inputstream ", e);
- }
- }
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebean.text.TextException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * ScalarType for streaming between a File and the database.
+ */
+public class ScalarTypeFile extends ScalarTypeBase {
+
+ private static Logger logger = LoggerFactory.getLogger(ScalarTypeFile.class);
+
+ private final String prefix;
+
+ private final String suffix;
+
+ private final File directory;
+
+ private final int bufferSize;
+
+ /**
+ * Construct with reasonable defaults of Blob and 8096 buffer size.
+ */
+ public ScalarTypeFile() {
+ this(Types.BLOB, "db-", null, null, 8096);
+ }
+
+ /**
+ * Create the ScalarTypeFile.
+ */
+ public ScalarTypeFile(int jdbcType, String prefix, String suffix, File directory, int bufferSize) {
+ super(File.class, false, jdbcType);
+ this.prefix = prefix;
+ this.suffix = suffix;
+ this.directory = directory;
+ this.bufferSize = bufferSize;
+ }
+
+ private InputStream getInputStream(File value) throws IOException {
+ FileInputStream fi = new FileInputStream(value);
+ return new BufferedInputStream(fi, bufferSize);
+ }
+
+ private OutputStream getOutputStream(File value) throws IOException {
+ FileOutputStream fi = new FileOutputStream(value);
+ return new BufferedOutputStream(fi, bufferSize);
+ }
+
+ @Override
+ public File read(DataReader dataReader) throws SQLException {
+
+ InputStream is = dataReader.getBinaryStream();
+ if (is == null) {
+ return null;
+ }
+
+ try {
+ // stream from db into our temp file
+ File tempFile = File.createTempFile(prefix, suffix, directory);
+ OutputStream os = getOutputStream(tempFile);
+ pump(is, os);
+
+ return tempFile;
+
+ } catch (IOException e) {
+ throw new SQLException("Error reading db file inputStream", e);
+ }
+ }
+
+
+ @Override
+ public void bind(DataBind b, File value) throws SQLException {
+ if (value == null) {
+ b.setNull(jdbcType);
+ } else {
+ try {
+ // stream from our file to the db
+ InputStream fi = getInputStream(value);
+ b.setBlob(fi, value.length());
+ } catch (IOException e) {
+ throw new SQLException("Error trying to set file inputStream", e);
+ }
+ }
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ return value;
+ }
+
+ @Override
+ public File toBeanType(Object value) {
+ return (File) value;
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, File value) throws IOException {
+ ctx.writeFieldName(name);
+ InputStream is = getInputStream(value);
+ ctx.writeBinary(is, (int) value.length());
+ }
+
+ @Override
+ public File jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ File tempFile = File.createTempFile(prefix, suffix, directory);
+ OutputStream os = getOutputStream(tempFile);
+ ctx.readBinaryValue(os);
+ os.flush();
+ os.close();
+ return tempFile;
+ }
+
+ @Override
+ public String formatValue(File file) {
+ throw new TextException("Not supported");
+ }
+
+ @Override
+ public File parse(String value) {
+ throw new TextException("Not supported");
+ }
+
+ @Override
+ public File convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not supported");
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ @Override
+ public File readData(DataInput dataInput) throws IOException {
+ // skip reading large file
+ return null;
+ }
+
+ public void writeData(DataOutput dataOutput, File file) throws IOException {
+ // skip writing large file
+ }
+
+ /**
+ * Helper method to pump bytes from input to output.
+ */
+ public long pump(InputStream is, OutputStream out) throws IOException {
+
+ long totalBytes = 0;
+ InputStream input = null;
+ OutputStream output = null;
+
+ try {
+ input = new BufferedInputStream(is, bufferSize);
+ output = new BufferedOutputStream(out, bufferSize);
+
+ byte[] buffer = new byte[bufferSize];
+ int length;
+ while (((length = input.read(buffer)) > 0)) {
+ output.write(buffer, 0, length);
+ totalBytes += length;
+ }
+
+ output.flush();
+
+ return totalBytes;
+
+ } finally {
+ if (output != null) {
+ try {
+ output.close();
+ } catch (IOException e) {
+ logger.error("Error when closing outputstream", e);
+ }
+ }
+ if (input != null) {
+ try {
+ input.close();
+ } catch (IOException e) {
+ logger.error("Error when closing inputstream ", e);
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFloat.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFloat.java
index 96807eab4..06f4f3c1a 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFloat.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeFloat.java
@@ -1,97 +1,97 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for Float and float.
- */
-public class ScalarTypeFloat extends ScalarTypeBase {
-
- public ScalarTypeFloat() {
- super(Float.class, true, Types.REAL);
- }
-
- @Override
- public void bind(DataBind b, Float value) throws SQLException {
- if (value == null) {
- b.setNull(Types.REAL);
- } else {
- b.setFloat(value.floatValue());
- }
- }
-
- @Override
- public Float read(DataReader dataReader) throws SQLException {
- return dataReader.getFloat();
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toFloat(value);
- }
-
- @Override
- public Float toBeanType(Object value) {
- return BasicTypeConverter.toFloat(value);
- }
-
- @Override
- public String formatValue(Float t) {
- return t.toString();
- }
-
- @Override
- public Float parse(String value) {
- return Float.valueOf(value);
- }
-
- @Override
- public Float convertFromMillis(long systemTimeMillis) {
- return Float.valueOf(systemTimeMillis);
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return true;
- }
-
- @Override
- public Float readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- float val = dataInput.readFloat();
- return Float.valueOf(val);
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, Float value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeFloat(value);
- }
- }
-
- @Override
- public Float jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return ctx.getFloatValue();
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, Float value) throws IOException {
- ctx.writeNumberField(name, (Float) value);
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for Float and float.
+ */
+public class ScalarTypeFloat extends ScalarTypeBase {
+
+ public ScalarTypeFloat() {
+ super(Float.class, true, Types.REAL);
+ }
+
+ @Override
+ public void bind(DataBind b, Float value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.REAL);
+ } else {
+ b.setFloat(value.floatValue());
+ }
+ }
+
+ @Override
+ public Float read(DataReader dataReader) throws SQLException {
+ return dataReader.getFloat();
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toFloat(value);
+ }
+
+ @Override
+ public Float toBeanType(Object value) {
+ return BasicTypeConverter.toFloat(value);
+ }
+
+ @Override
+ public String formatValue(Float t) {
+ return t.toString();
+ }
+
+ @Override
+ public Float parse(String value) {
+ return Float.valueOf(value);
+ }
+
+ @Override
+ public Float convertFromMillis(long systemTimeMillis) {
+ return Float.valueOf(systemTimeMillis);
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return true;
+ }
+
+ @Override
+ public Float readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ float val = dataInput.readFloat();
+ return Float.valueOf(val);
+ }
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, Float value) throws IOException {
+
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeFloat(value);
+ }
+ }
+
+ @Override
+ public Float jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return ctx.getFloatValue();
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, Float value) throws IOException {
+ ctx.writeNumberField(name, (Float) value);
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInetAddress.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInetAddress.java
index 3b83d3f17..a1ce30a37 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInetAddress.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInetAddress.java
@@ -1,48 +1,48 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.net.InetAddress;
-
-import com.avaje.ebean.text.TextException;
-
-/**
- * ScalarType for java.net.URI which converts to and from a VARCHAR database column.
- */
-public class ScalarTypeInetAddress extends ScalarTypeBaseVarchar {
-
- public ScalarTypeInetAddress() {
- super(InetAddress.class);
- }
-
- @Override
- public int getLength() {
- return 50;
- }
-
- @Override
- public InetAddress convertFromDbString(String dbValue) {
- try {
- return parse(dbValue);
- } catch (IllegalArgumentException e) {
- throw new RuntimeException("Error with InetAddresses [" + dbValue + "] " + e);
- }
- }
-
- @Override
- public String convertToDbString(InetAddress beanValue) {
- return ConvertInetAddresses.toUriString(beanValue);
- }
-
- @Override
- public String formatValue(InetAddress v) {
- return ConvertInetAddresses.toUriString(v);
- }
-
- @Override
- public InetAddress parse(String value) {
- try {
- return ConvertInetAddresses.forUriString(value);
- } catch (IllegalArgumentException e) {
- throw new TextException("Error with InetAddresses [" + value + "] ", e);
- }
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.net.InetAddress;
+
+import com.avaje.ebean.text.TextException;
+
+/**
+ * ScalarType for java.net.URI which converts to and from a VARCHAR database column.
+ */
+public class ScalarTypeInetAddress extends ScalarTypeBaseVarchar {
+
+ public ScalarTypeInetAddress() {
+ super(InetAddress.class);
+ }
+
+ @Override
+ public int getLength() {
+ return 50;
+ }
+
+ @Override
+ public InetAddress convertFromDbString(String dbValue) {
+ try {
+ return parse(dbValue);
+ } catch (IllegalArgumentException e) {
+ throw new RuntimeException("Error with InetAddresses [" + dbValue + "] " + e);
+ }
+ }
+
+ @Override
+ public String convertToDbString(InetAddress beanValue) {
+ return ConvertInetAddresses.toUriString(beanValue);
+ }
+
+ @Override
+ public String formatValue(InetAddress v) {
+ return ConvertInetAddresses.toUriString(v);
+ }
+
+ @Override
+ public InetAddress parse(String value) {
+ try {
+ return ConvertInetAddresses.forUriString(value);
+ } catch (IllegalArgumentException e) {
+ throw new TextException("Error with InetAddresses [" + value + "] ", e);
+ }
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInstant.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInstant.java
index 00997022d..5e309a9c8 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInstant.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInstant.java
@@ -1,59 +1,59 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebean.config.JsonConfig;
-
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.time.Instant;
-
-/**
- * ScalarType for java.sql.Timestamp.
- */
-public class ScalarTypeInstant extends ScalarTypeBaseDateTime {
-
- public ScalarTypeInstant(JsonConfig.DateTime mode) {
- super(mode, Instant.class, true, Types.TIMESTAMP);
- }
-
- @Override
- protected String toJsonNanos(Instant value) {
- return toJsonNanos(value.getEpochSecond(), value.getNano());
- }
-
- @Override
- protected String toJsonISO8601(Instant value) {
- return value.toString();
- }
-
- @Override
- public long convertToMillis(Instant value) {
- return value.toEpochMilli();
- }
-
- @Override
- public Instant convertFromMillis(long systemTimeMillis) {
- return Instant.ofEpochMilli(systemTimeMillis);
- }
-
- @Override
- public Instant convertFromTimestamp(Timestamp ts) {
- return ts.toInstant();
- }
-
- @Override
- public Timestamp convertToTimestamp(Instant t) {
- return Timestamp.from(t);
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof Timestamp) return value;
- return convertToTimestamp((Instant) value);
- }
-
- @Override
- public Instant toBeanType(Object value) {
- if (value instanceof Instant) return (Instant) value;
- return convertFromTimestamp((Timestamp) value);
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebean.config.JsonConfig;
+
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.Instant;
+
+/**
+ * ScalarType for java.sql.Timestamp.
+ */
+public class ScalarTypeInstant extends ScalarTypeBaseDateTime {
+
+ public ScalarTypeInstant(JsonConfig.DateTime mode) {
+ super(mode, Instant.class, true, Types.TIMESTAMP);
+ }
+
+ @Override
+ protected String toJsonNanos(Instant value) {
+ return toJsonNanos(value.getEpochSecond(), value.getNano());
+ }
+
+ @Override
+ protected String toJsonISO8601(Instant value) {
+ return value.toString();
+ }
+
+ @Override
+ public long convertToMillis(Instant value) {
+ return value.toEpochMilli();
+ }
+
+ @Override
+ public Instant convertFromMillis(long systemTimeMillis) {
+ return Instant.ofEpochMilli(systemTimeMillis);
+ }
+
+ @Override
+ public Instant convertFromTimestamp(Timestamp ts) {
+ return ts.toInstant();
+ }
+
+ @Override
+ public Timestamp convertToTimestamp(Instant t) {
+ return Timestamp.from(t);
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof Timestamp) return value;
+ return convertToTimestamp((Instant) value);
+ }
+
+ @Override
+ public Instant toBeanType(Object value) {
+ if (value instanceof Instant) return (Instant) value;
+ return convertFromTimestamp((Timestamp) value);
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInteger.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInteger.java
index 3199fb609..40d851867 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInteger.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeInteger.java
@@ -1,96 +1,96 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebean.text.TextException;
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for Integer and int.
- */
-public class ScalarTypeInteger extends ScalarTypeBase {
-
- public ScalarTypeInteger() {
- super(Integer.class, true, Types.INTEGER);
- }
-
- @Override
- public void bind(DataBind b, Integer value) throws SQLException {
- if (value == null) {
- b.setNull(Types.INTEGER);
- } else {
- b.setInt(value.intValue());
- }
- }
-
- @Override
- public Integer read(DataReader dataReader) throws SQLException {
- return dataReader.getInt();
- }
-
- @Override
- public Integer readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- return Integer.valueOf(dataInput.readInt());
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, Integer value) throws IOException {
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeInt(value);
- }
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toInteger(value);
- }
-
- @Override
- public Integer toBeanType(Object value) {
- return BasicTypeConverter.toInteger(value);
- }
-
- @Override
- public String formatValue(Integer v) {
- return v.toString();
- }
-
- @Override
- public Integer parse(String value) {
- return Integer.valueOf(value);
- }
-
- @Override
- public Integer convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not Supported");
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return false;
- }
-
- @Override
- public Integer jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return ctx.getIntValue();
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, Integer value) throws IOException {
- ctx.writeNumberField(name, value);
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebean.text.TextException;
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for Integer and int.
+ */
+public class ScalarTypeInteger extends ScalarTypeBase {
+
+ public ScalarTypeInteger() {
+ super(Integer.class, true, Types.INTEGER);
+ }
+
+ @Override
+ public void bind(DataBind b, Integer value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.INTEGER);
+ } else {
+ b.setInt(value.intValue());
+ }
+ }
+
+ @Override
+ public Integer read(DataReader dataReader) throws SQLException {
+ return dataReader.getInt();
+ }
+
+ @Override
+ public Integer readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ return Integer.valueOf(dataInput.readInt());
+ }
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, Integer value) throws IOException {
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeInt(value);
+ }
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ return BasicTypeConverter.toInteger(value);
+ }
+
+ @Override
+ public Integer toBeanType(Object value) {
+ return BasicTypeConverter.toInteger(value);
+ }
+
+ @Override
+ public String formatValue(Integer v) {
+ return v.toString();
+ }
+
+ @Override
+ public Integer parse(String value) {
+ return Integer.valueOf(value);
+ }
+
+ @Override
+ public Integer convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not Supported");
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ @Override
+ public Integer jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return ctx.getIntValue();
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, Integer value) throws IOException {
+ ctx.writeNumberField(name, value);
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateMidnight.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateMidnight.java
index 244b8c127..5a0c66c77 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateMidnight.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateMidnight.java
@@ -1,52 +1,52 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.Date;
-import java.sql.Types;
-
-import org.joda.time.DateMidnight;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-/**
- * ScalarType for Joda DateMidnight. This maps to a JDBC Date.
- */
-public class ScalarTypeJodaDateMidnight extends ScalarTypeBaseDate {
-
- /**
- * Instantiates a new scalar type joda date midnight.
- */
- public ScalarTypeJodaDateMidnight() {
- super(DateMidnight.class, false, Types.DATE);
- }
-
- @Override
- public long convertToMillis(DateMidnight value) {
- return value.getMillis();
- }
-
- @Override
- public DateMidnight convertFromDate(Date ts) {
- return new DateMidnight(ts.getTime());
- }
-
- @Override
- public Date convertToDate(DateMidnight t) {
- return new Date(t.getMillis());
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof DateMidnight) {
- return new Date(((DateMidnight) value).getMillis());
- }
- return BasicTypeConverter.toDate(value);
- }
-
- @Override
- public DateMidnight toBeanType(Object value) {
- if (value instanceof java.util.Date) {
- return new DateMidnight(((java.util.Date) value).getTime());
- }
- return (DateMidnight) value;
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.Date;
+import java.sql.Types;
+
+import org.joda.time.DateMidnight;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+/**
+ * ScalarType for Joda DateMidnight. This maps to a JDBC Date.
+ */
+public class ScalarTypeJodaDateMidnight extends ScalarTypeBaseDate {
+
+ /**
+ * Instantiates a new scalar type joda date midnight.
+ */
+ public ScalarTypeJodaDateMidnight() {
+ super(DateMidnight.class, false, Types.DATE);
+ }
+
+ @Override
+ public long convertToMillis(DateMidnight value) {
+ return value.getMillis();
+ }
+
+ @Override
+ public DateMidnight convertFromDate(Date ts) {
+ return new DateMidnight(ts.getTime());
+ }
+
+ @Override
+ public Date convertToDate(DateMidnight t) {
+ return new Date(t.getMillis());
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof DateMidnight) {
+ return new Date(((DateMidnight) value).getMillis());
+ }
+ return BasicTypeConverter.toDate(value);
+ }
+
+ @Override
+ public DateMidnight toBeanType(Object value) {
+ if (value instanceof java.util.Date) {
+ return new DateMidnight(((java.util.Date) value).getTime());
+ }
+ return (DateMidnight) value;
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateTime.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateTime.java
index 9f0d5de86..797ce69f9 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateTime.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaDateTime.java
@@ -1,67 +1,67 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.Timestamp;
-import java.sql.Types;
-
-import com.avaje.ebean.config.JsonConfig;
-import org.joda.time.DateTime;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import org.joda.time.LocalDateTime;
-
-/**
- * ScalarType for Joda DateTime. This maps to a JDBC Timestamp.
- */
-public class ScalarTypeJodaDateTime extends ScalarTypeBaseDateTime {
-
- public ScalarTypeJodaDateTime(JsonConfig.DateTime mode) {
- super(mode, DateTime.class, false, Types.TIMESTAMP);
- }
-
- @Override
- public long convertToMillis(DateTime value) {
- return value.getMillis();
- }
-
- @Override
- protected String toJsonNanos(DateTime value) {
- return String.valueOf(value.toDateTime().getMillis());
- }
-
- @Override
- protected String toJsonISO8601(DateTime value) {
- return value.toString();
- }
-
- @Override
- public DateTime convertFromMillis(long systemTimeMillis) {
- return new DateTime(systemTimeMillis);
- }
-
- @Override
- public DateTime convertFromTimestamp(Timestamp ts) {
- return new DateTime(ts.getTime());
- }
-
- @Override
- public Timestamp convertToTimestamp(DateTime t) {
- return new Timestamp(t.getMillis());
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof DateTime) {
- return new Timestamp(((DateTime) value).getMillis());
- }
- return BasicTypeConverter.toTimestamp(value);
- }
-
- @Override
- public DateTime toBeanType(Object value) {
- if (value instanceof java.util.Date) {
- return new DateTime(((java.util.Date) value).getTime());
- }
- return (DateTime) value;
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.Timestamp;
+import java.sql.Types;
+
+import com.avaje.ebean.config.JsonConfig;
+import org.joda.time.DateTime;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import org.joda.time.LocalDateTime;
+
+/**
+ * ScalarType for Joda DateTime. This maps to a JDBC Timestamp.
+ */
+public class ScalarTypeJodaDateTime extends ScalarTypeBaseDateTime {
+
+ public ScalarTypeJodaDateTime(JsonConfig.DateTime mode) {
+ super(mode, DateTime.class, false, Types.TIMESTAMP);
+ }
+
+ @Override
+ public long convertToMillis(DateTime value) {
+ return value.getMillis();
+ }
+
+ @Override
+ protected String toJsonNanos(DateTime value) {
+ return String.valueOf(value.toDateTime().getMillis());
+ }
+
+ @Override
+ protected String toJsonISO8601(DateTime value) {
+ return value.toString();
+ }
+
+ @Override
+ public DateTime convertFromMillis(long systemTimeMillis) {
+ return new DateTime(systemTimeMillis);
+ }
+
+ @Override
+ public DateTime convertFromTimestamp(Timestamp ts) {
+ return new DateTime(ts.getTime());
+ }
+
+ @Override
+ public Timestamp convertToTimestamp(DateTime t) {
+ return new Timestamp(t.getMillis());
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof DateTime) {
+ return new Timestamp(((DateTime) value).getMillis());
+ }
+ return BasicTypeConverter.toTimestamp(value);
+ }
+
+ @Override
+ public DateTime toBeanType(Object value) {
+ if (value instanceof java.util.Date) {
+ return new DateTime(((java.util.Date) value).getTime());
+ }
+ return (DateTime) value;
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java
index f06639ec4..30f39d4b9 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java
@@ -1,55 +1,55 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.Date;
-import java.sql.Types;
-
-import org.joda.time.LocalDate;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-/**
- * ScalarType for Joda LocalDate. This maps to a JDBC Date.
- */
-public class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate {
-
- public ScalarTypeJodaLocalDate() {
- super(LocalDate.class, false, Types.DATE);
- }
-
- @Override
- public long convertToMillis(LocalDate value) {
- return value.toDateMidnight().getMillis();
- }
-
- @Override
- public LocalDate convertFromDate(Date ts) {
- return new LocalDate(((java.util.Date) ts).getTime());
- }
-
- @Override
- public Date convertToDate(LocalDate t) {
- return new java.sql.Date(t.toDateMidnight().getMillis());
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof LocalDate) {
- return new java.sql.Date(((LocalDate) value).toDateMidnight().getMillis());
- }
- return BasicTypeConverter.toDate(value);
- }
-
- @Override
- public LocalDate toBeanType(Object value) {
- if (value instanceof java.util.Date) {
- return new LocalDate(((java.util.Date) value).getTime());
- }
- return (LocalDate) value;
- }
-
- @Override
- public LocalDate convertFromMillis(long systemTimeMillis) {
- return new LocalDate(systemTimeMillis);
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.Date;
+import java.sql.Types;
+
+import org.joda.time.LocalDate;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+/**
+ * ScalarType for Joda LocalDate. This maps to a JDBC Date.
+ */
+public class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate {
+
+ public ScalarTypeJodaLocalDate() {
+ super(LocalDate.class, false, Types.DATE);
+ }
+
+ @Override
+ public long convertToMillis(LocalDate value) {
+ return value.toDateMidnight().getMillis();
+ }
+
+ @Override
+ public LocalDate convertFromDate(Date ts) {
+ return new LocalDate(((java.util.Date) ts).getTime());
+ }
+
+ @Override
+ public Date convertToDate(LocalDate t) {
+ return new java.sql.Date(t.toDateMidnight().getMillis());
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof LocalDate) {
+ return new java.sql.Date(((LocalDate) value).toDateMidnight().getMillis());
+ }
+ return BasicTypeConverter.toDate(value);
+ }
+
+ @Override
+ public LocalDate toBeanType(Object value) {
+ if (value instanceof java.util.Date) {
+ return new LocalDate(((java.util.Date) value).getTime());
+ }
+ return (LocalDate) value;
+ }
+
+ @Override
+ public LocalDate convertFromMillis(long systemTimeMillis) {
+ return new LocalDate(systemTimeMillis);
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDateTime.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDateTime.java
index e0bc36ce3..cda901d66 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDateTime.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDateTime.java
@@ -1,67 +1,67 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.sql.Timestamp;
-import java.sql.Types;
-
-import com.avaje.ebean.config.JsonConfig;
-import org.joda.time.LocalDateTime;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-/**
- * ScalarType for Joda LocalDateTime. This maps to a JDBC Timestamp.
- */
-public class ScalarTypeJodaLocalDateTime extends ScalarTypeBaseDateTime {
-
- public ScalarTypeJodaLocalDateTime(JsonConfig.DateTime mode) {
- super(mode, LocalDateTime.class, false, Types.TIMESTAMP);
- }
-
- @Override
- protected String toJsonNanos(LocalDateTime value) {
- return String.valueOf(value.toDateTime().getMillis());
- }
-
- @Override
- protected String toJsonISO8601(LocalDateTime value) {
- return value.toString();
- }
-
- @Override
- public long convertToMillis(LocalDateTime value) {
- return value.toDateTime().getMillis();
- }
-
-
- @Override
- public LocalDateTime convertFromMillis(long systemTimeMillis) {
- return new LocalDateTime(systemTimeMillis);
- }
-
- @Override
- public LocalDateTime convertFromTimestamp(Timestamp ts) {
- return new LocalDateTime(ts.getTime());
- }
-
- @Override
- public Timestamp convertToTimestamp(LocalDateTime t) {
- return new Timestamp(t.toDateTime().getMillis());
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof LocalDateTime) {
- return new Timestamp(((LocalDateTime) value).toDateTime().getMillis());
- }
- return BasicTypeConverter.toTimestamp(value);
- }
-
- @Override
- public LocalDateTime toBeanType(Object value) {
- if (value instanceof java.util.Date) {
- return new LocalDateTime(((java.util.Date) value).getTime());
- }
- return (LocalDateTime) value;
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.sql.Timestamp;
+import java.sql.Types;
+
+import com.avaje.ebean.config.JsonConfig;
+import org.joda.time.LocalDateTime;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+/**
+ * ScalarType for Joda LocalDateTime. This maps to a JDBC Timestamp.
+ */
+public class ScalarTypeJodaLocalDateTime extends ScalarTypeBaseDateTime {
+
+ public ScalarTypeJodaLocalDateTime(JsonConfig.DateTime mode) {
+ super(mode, LocalDateTime.class, false, Types.TIMESTAMP);
+ }
+
+ @Override
+ protected String toJsonNanos(LocalDateTime value) {
+ return String.valueOf(value.toDateTime().getMillis());
+ }
+
+ @Override
+ protected String toJsonISO8601(LocalDateTime value) {
+ return value.toString();
+ }
+
+ @Override
+ public long convertToMillis(LocalDateTime value) {
+ return value.toDateTime().getMillis();
+ }
+
+
+ @Override
+ public LocalDateTime convertFromMillis(long systemTimeMillis) {
+ return new LocalDateTime(systemTimeMillis);
+ }
+
+ @Override
+ public LocalDateTime convertFromTimestamp(Timestamp ts) {
+ return new LocalDateTime(ts.getTime());
+ }
+
+ @Override
+ public Timestamp convertToTimestamp(LocalDateTime t) {
+ return new Timestamp(t.toDateTime().getMillis());
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof LocalDateTime) {
+ return new Timestamp(((LocalDateTime) value).toDateTime().getMillis());
+ }
+ return BasicTypeConverter.toTimestamp(value);
+ }
+
+ @Override
+ public LocalDateTime toBeanType(Object value) {
+ if (value instanceof java.util.Date) {
+ return new LocalDateTime(((java.util.Date) value).getTime());
+ }
+ return (LocalDateTime) value;
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalTime.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalTime.java
index 3b5e6c97b..c3cd766c6 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalTime.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalTime.java
@@ -1,120 +1,120 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Types;
-
-import org.joda.time.DateTimeZone;
-import org.joda.time.LocalTime;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for Joda LocalTime. This maps to a JDBC Time.
- */
-public class ScalarTypeJodaLocalTime extends ScalarTypeBase {
-
- public ScalarTypeJodaLocalTime() {
- super(LocalTime.class, false, Types.TIME);
- }
-
- @Override
- public void bind(DataBind b, LocalTime value) throws SQLException {
- if (value == null) {
- b.setNull(Types.TIME);
- } else {
- Time sqlTime = new Time(value.getMillisOfDay());
- b.setTime(sqlTime);
- }
- }
-
- @Override
- public LocalTime read(DataReader dataReader) throws SQLException {
-
- Time sqlTime = dataReader.getTime();
- if (sqlTime == null) {
- return null;
- } else {
- return new LocalTime(sqlTime, DateTimeZone.UTC);
- }
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof LocalTime) {
- return new Time(((LocalTime) value).getMillisOfDay());
- }
- return BasicTypeConverter.toTime(value);
- }
-
- @Override
- public LocalTime toBeanType(Object value) {
- if (value instanceof java.util.Date) {
- return new LocalTime(value, DateTimeZone.UTC);
- }
- return (LocalTime) value;
- }
-
- @Override
- public String formatValue(LocalTime v) {
- return v.toString();
- }
-
- @Override
- public LocalTime parse(String value) {
- return new LocalTime(value);
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, LocalTime value) throws IOException {
- ctx.writeStringField(name, value.toString());
- }
-
- @Override
- public LocalTime jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- if (JsonToken.VALUE_NUMBER_INT == event) {
- long millis = ctx.getLongValue();
- return convertFromMillis(millis);
- } else {
- String string = ctx.getValueAsString();
- throw new RuntimeException("convert " + string);
- }
- }
-
- @Override
- public LocalTime convertFromMillis(long systemTimeMillis) {
- return new LocalTime(systemTimeMillis);
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return true;
- }
-
- @Override
- public LocalTime readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- String val = dataInput.readUTF();
- return parse(val);
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, LocalTime value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeUTF(format(value));
- }
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Types;
+
+import org.joda.time.DateTimeZone;
+import org.joda.time.LocalTime;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for Joda LocalTime. This maps to a JDBC Time.
+ */
+public class ScalarTypeJodaLocalTime extends ScalarTypeBase {
+
+ public ScalarTypeJodaLocalTime() {
+ super(LocalTime.class, false, Types.TIME);
+ }
+
+ @Override
+ public void bind(DataBind b, LocalTime value) throws SQLException {
+ if (value == null) {
+ b.setNull(Types.TIME);
+ } else {
+ Time sqlTime = new Time(value.getMillisOfDay());
+ b.setTime(sqlTime);
+ }
+ }
+
+ @Override
+ public LocalTime read(DataReader dataReader) throws SQLException {
+
+ Time sqlTime = dataReader.getTime();
+ if (sqlTime == null) {
+ return null;
+ } else {
+ return new LocalTime(sqlTime, DateTimeZone.UTC);
+ }
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof LocalTime) {
+ return new Time(((LocalTime) value).getMillisOfDay());
+ }
+ return BasicTypeConverter.toTime(value);
+ }
+
+ @Override
+ public LocalTime toBeanType(Object value) {
+ if (value instanceof java.util.Date) {
+ return new LocalTime(value, DateTimeZone.UTC);
+ }
+ return (LocalTime) value;
+ }
+
+ @Override
+ public String formatValue(LocalTime v) {
+ return v.toString();
+ }
+
+ @Override
+ public LocalTime parse(String value) {
+ return new LocalTime(value);
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, LocalTime value) throws IOException {
+ ctx.writeStringField(name, value.toString());
+ }
+
+ @Override
+ public LocalTime jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ if (JsonToken.VALUE_NUMBER_INT == event) {
+ long millis = ctx.getLongValue();
+ return convertFromMillis(millis);
+ } else {
+ String string = ctx.getValueAsString();
+ throw new RuntimeException("convert " + string);
+ }
+ }
+
+ @Override
+ public LocalTime convertFromMillis(long systemTimeMillis) {
+ return new LocalTime(systemTimeMillis);
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return true;
+ }
+
+ @Override
+ public LocalTime readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ String val = dataInput.readUTF();
+ return parse(val);
+ }
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, LocalTime value) throws IOException {
+
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeUTF(format(value));
+ }
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDate.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDate.java
index 5ffef6b3f..76f7fc33a 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDate.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDate.java
@@ -1,59 +1,59 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-import java.sql.Date;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.time.LocalDate;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-
-/**
- * ScalarType for java.time.LocalDate. This maps to a JDBC Date.
- */
-public class ScalarTypeLocalDate extends ScalarTypeBaseDate {
-
- public ScalarTypeLocalDate() {
- super(LocalDate.class, false, Types.DATE);
- }
-
- @Override
- public long convertToMillis(LocalDate value) {
- ZonedDateTime zonedDateTime = value.atStartOfDay(ZoneId.systemDefault());
- return zonedDateTime.toInstant().toEpochMilli();
- }
-
- @Override
- public LocalDate convertFromDate(Date ts) {
- return ts.toLocalDate();
- }
-
- @Override
- public Date convertToDate(LocalDate t) {
- return Date.valueOf(t);
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof LocalDate) {
- return Date.valueOf((LocalDate) value);
- }
- return BasicTypeConverter.toDate(value);
- }
-
- @Override
- public LocalDate toBeanType(Object value) {
- if (value instanceof java.sql.Date) {
- return ((java.sql.Date) value).toLocalDate();
- }
- return (LocalDate) value;
- }
-
- @Override
- public LocalDate convertFromMillis(long systemTimeMillis) {
- return new Timestamp(systemTimeMillis).toLocalDateTime().toLocalDate();
- }
-
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+
+/**
+ * ScalarType for java.time.LocalDate. This maps to a JDBC Date.
+ */
+public class ScalarTypeLocalDate extends ScalarTypeBaseDate {
+
+ public ScalarTypeLocalDate() {
+ super(LocalDate.class, false, Types.DATE);
+ }
+
+ @Override
+ public long convertToMillis(LocalDate value) {
+ ZonedDateTime zonedDateTime = value.atStartOfDay(ZoneId.systemDefault());
+ return zonedDateTime.toInstant().toEpochMilli();
+ }
+
+ @Override
+ public LocalDate convertFromDate(Date ts) {
+ return ts.toLocalDate();
+ }
+
+ @Override
+ public Date convertToDate(LocalDate t) {
+ return Date.valueOf(t);
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof LocalDate) {
+ return Date.valueOf((LocalDate) value);
+ }
+ return BasicTypeConverter.toDate(value);
+ }
+
+ @Override
+ public LocalDate toBeanType(Object value) {
+ if (value instanceof java.sql.Date) {
+ return ((java.sql.Date) value).toLocalDate();
+ }
+ return (LocalDate) value;
+ }
+
+ @Override
+ public LocalDate convertFromMillis(long systemTimeMillis) {
+ return new Timestamp(systemTimeMillis).toLocalDateTime().toLocalDate();
+ }
+
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDateTime.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDateTime.java
index b0452f95e..e745480ad 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDateTime.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalDateTime.java
@@ -1,64 +1,64 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebean.config.JsonConfig;
-
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-
-/**
- * ScalarType for java.sql.Timestamp.
- */
-public class ScalarTypeLocalDateTime extends ScalarTypeBaseDateTime {
-
- public ScalarTypeLocalDateTime(JsonConfig.DateTime mode) {
- super(mode, LocalDateTime.class, true, Types.TIMESTAMP);
- }
-
- @Override
- public LocalDateTime convertFromMillis(long systemTimeMillis) {
- return new Timestamp(systemTimeMillis).toLocalDateTime();
- }
-
- @Override
- public long convertToMillis(LocalDateTime value) {
- return value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
- }
-
- @Override
- protected String toJsonNanos(LocalDateTime value) {
- return String.valueOf(convertToMillis(value));
- }
-
- @Override
- protected String toJsonISO8601(LocalDateTime value) {
- return value.atZone(ZoneId.systemDefault()).toInstant().toString();
- }
-
- @Override
- public LocalDateTime convertFromTimestamp(Timestamp ts) {
- return ts.toLocalDateTime();
- }
-
- @Override
- public Timestamp convertToTimestamp(LocalDateTime t) {
-
- ZonedDateTime zonedDateTime = t.atZone(ZoneId.systemDefault());
- return Timestamp.from(zonedDateTime.toInstant());
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof Timestamp) return value;
- return convertToTimestamp((LocalDateTime)value);
- }
-
- @Override
- public LocalDateTime toBeanType(Object value) {
- if (value instanceof LocalDateTime) return (LocalDateTime)value;
- return convertFromTimestamp((Timestamp)value);
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebean.config.JsonConfig;
+
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+
+/**
+ * ScalarType for java.sql.Timestamp.
+ */
+public class ScalarTypeLocalDateTime extends ScalarTypeBaseDateTime {
+
+ public ScalarTypeLocalDateTime(JsonConfig.DateTime mode) {
+ super(mode, LocalDateTime.class, true, Types.TIMESTAMP);
+ }
+
+ @Override
+ public LocalDateTime convertFromMillis(long systemTimeMillis) {
+ return new Timestamp(systemTimeMillis).toLocalDateTime();
+ }
+
+ @Override
+ public long convertToMillis(LocalDateTime value) {
+ return value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+ }
+
+ @Override
+ protected String toJsonNanos(LocalDateTime value) {
+ return String.valueOf(convertToMillis(value));
+ }
+
+ @Override
+ protected String toJsonISO8601(LocalDateTime value) {
+ return value.atZone(ZoneId.systemDefault()).toInstant().toString();
+ }
+
+ @Override
+ public LocalDateTime convertFromTimestamp(Timestamp ts) {
+ return ts.toLocalDateTime();
+ }
+
+ @Override
+ public Timestamp convertToTimestamp(LocalDateTime t) {
+
+ ZonedDateTime zonedDateTime = t.atZone(ZoneId.systemDefault());
+ return Timestamp.from(zonedDateTime.toInstant());
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof Timestamp) return value;
+ return convertToTimestamp((LocalDateTime)value);
+ }
+
+ @Override
+ public LocalDateTime toBeanType(Object value) {
+ if (value instanceof LocalDateTime) return (LocalDateTime)value;
+ return convertFromTimestamp((Timestamp)value);
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTime.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTime.java
index 40a45f0a3..32971086e 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTime.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTime.java
@@ -1,105 +1,105 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebean.text.TextException;
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Types;
-import java.time.LocalTime;
-
-/**
- * ScalarType for java.time.LocalTime stored as JDBC Time.
- */
-public class ScalarTypeLocalTime extends ScalarTypeBase {
-
- public ScalarTypeLocalTime() {
- super(LocalTime.class, false, Types.TIME);
- }
-
- protected ScalarTypeLocalTime(int jdbcTtype) {
- super(LocalTime.class, false, jdbcTtype);
- }
-
- @Override
- public void bind(DataBind bind, LocalTime value) throws SQLException {
- if (value == null) {
- bind.setNull(Types.TIME);
- } else {
- bind.setTime(Time.valueOf(value));
- }
- }
-
- @Override
- public LocalTime read(DataReader dataReader) throws SQLException {
- Time time = dataReader.getTime();
- return (time == null) ? null : time.toLocalTime();
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof Time) return value;
- return Time.valueOf((LocalTime)value);
- }
-
- @Override
- public LocalTime toBeanType(Object value) {
- if (value instanceof LocalTime) return (LocalTime) value;
- return BasicTypeConverter.toTime(value).toLocalTime();
- }
-
- @Override
- public LocalTime readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- return LocalTime.ofNanoOfDay(dataInput.readLong());
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, LocalTime value) throws IOException {
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeLong(value.toNanoOfDay());
- }
- }
-
- @Override
- public String formatValue(LocalTime v) {
- return v.toString();
- }
-
- @Override
- public LocalTime parse(String value) {
- return LocalTime.parse(value);
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return false;
- }
-
- @Override
- public LocalTime convertFromMillis(long systemTimeMillis) {
- throw new TextException("Not Supported");
- }
-
- @Override
- public LocalTime jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return LocalTime.parse(ctx.getValueAsString());
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, LocalTime value) throws IOException {
- ctx.writeStringField(name, value.toString());
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebean.text.TextException;
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Types;
+import java.time.LocalTime;
+
+/**
+ * ScalarType for java.time.LocalTime stored as JDBC Time.
+ */
+public class ScalarTypeLocalTime extends ScalarTypeBase {
+
+ public ScalarTypeLocalTime() {
+ super(LocalTime.class, false, Types.TIME);
+ }
+
+ protected ScalarTypeLocalTime(int jdbcTtype) {
+ super(LocalTime.class, false, jdbcTtype);
+ }
+
+ @Override
+ public void bind(DataBind bind, LocalTime value) throws SQLException {
+ if (value == null) {
+ bind.setNull(Types.TIME);
+ } else {
+ bind.setTime(Time.valueOf(value));
+ }
+ }
+
+ @Override
+ public LocalTime read(DataReader dataReader) throws SQLException {
+ Time time = dataReader.getTime();
+ return (time == null) ? null : time.toLocalTime();
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof Time) return value;
+ return Time.valueOf((LocalTime)value);
+ }
+
+ @Override
+ public LocalTime toBeanType(Object value) {
+ if (value instanceof LocalTime) return (LocalTime) value;
+ return BasicTypeConverter.toTime(value).toLocalTime();
+ }
+
+ @Override
+ public LocalTime readData(DataInput dataInput) throws IOException {
+ if (!dataInput.readBoolean()) {
+ return null;
+ } else {
+ return LocalTime.ofNanoOfDay(dataInput.readLong());
+ }
+ }
+
+ @Override
+ public void writeData(DataOutput dataOutput, LocalTime value) throws IOException {
+ if (value == null) {
+ dataOutput.writeBoolean(false);
+ } else {
+ dataOutput.writeBoolean(true);
+ dataOutput.writeLong(value.toNanoOfDay());
+ }
+ }
+
+ @Override
+ public String formatValue(LocalTime v) {
+ return v.toString();
+ }
+
+ @Override
+ public LocalTime parse(String value) {
+ return LocalTime.parse(value);
+ }
+
+ @Override
+ public boolean isDateTimeCapable() {
+ return false;
+ }
+
+ @Override
+ public LocalTime convertFromMillis(long systemTimeMillis) {
+ throw new TextException("Not Supported");
+ }
+
+ @Override
+ public LocalTime jsonRead(JsonParser ctx, JsonToken event) throws IOException {
+ return LocalTime.parse(ctx.getValueAsString());
+ }
+
+ @Override
+ public void jsonWrite(JsonGenerator ctx, String name, LocalTime value) throws IOException {
+ ctx.writeStringField(name, value.toString());
+ }
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTimeWithNanos.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTimeWithNanos.java
index d72f36222..deab02e3e 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTimeWithNanos.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocalTimeWithNanos.java
@@ -1,45 +1,45 @@
-package com.avaje.ebeaninternal.server.type;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-
-import java.sql.SQLException;
-import java.sql.Types;
-import java.time.LocalTime;
-
-/**
- * ScalarType for java.time.LocalTime stored with Nanos as DB BIGINT type.
- */
-public class ScalarTypeLocalTimeWithNanos extends ScalarTypeLocalTime {
-
- public ScalarTypeLocalTimeWithNanos() {
- super(Types.BIGINT);
- }
-
- @Override
- public void bind(DataBind bind, LocalTime value) throws SQLException {
- if (value == null) {
- bind.setNull(Types.BIGINT);
- } else {
- bind.setLong(value.toNanoOfDay());
- }
- }
-
- @Override
- public LocalTime read(DataReader dataReader) throws SQLException {
- Long value = dataReader.getLong();
- return (value == null) ? null : LocalTime.ofNanoOfDay(value);
- }
-
- @Override
- public Object toJdbcType(Object value) {
- if (value instanceof Long) return value;
- return ((LocalTime)value).toNanoOfDay();
- }
-
- @Override
- public LocalTime toBeanType(Object value) {
- if (value instanceof LocalTime) return (LocalTime) value;
- return LocalTime.ofNanoOfDay(BasicTypeConverter.toLong(value));
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import java.time.LocalTime;
+
+/**
+ * ScalarType for java.time.LocalTime stored with Nanos as DB BIGINT type.
+ */
+public class ScalarTypeLocalTimeWithNanos extends ScalarTypeLocalTime {
+
+ public ScalarTypeLocalTimeWithNanos() {
+ super(Types.BIGINT);
+ }
+
+ @Override
+ public void bind(DataBind bind, LocalTime value) throws SQLException {
+ if (value == null) {
+ bind.setNull(Types.BIGINT);
+ } else {
+ bind.setLong(value.toNanoOfDay());
+ }
+ }
+
+ @Override
+ public LocalTime read(DataReader dataReader) throws SQLException {
+ Long value = dataReader.getLong();
+ return (value == null) ? null : LocalTime.ofNanoOfDay(value);
+ }
+
+ @Override
+ public Object toJdbcType(Object value) {
+ if (value instanceof Long) return value;
+ return ((LocalTime)value).toNanoOfDay();
+ }
+
+ @Override
+ public LocalTime toBeanType(Object value) {
+ if (value instanceof LocalTime) return (LocalTime) value;
+ return LocalTime.ofNanoOfDay(BasicTypeConverter.toLong(value));
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocale.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocale.java
index 26c04c70d..62ec137ca 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocale.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLocale.java
@@ -1,65 +1,65 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.util.Locale;
-
-/**
- * ScalarType for java.util.Currency which converts to and from a VARCHAR database column.
- */
-public class ScalarTypeLocale extends ScalarTypeBaseVarchar {
-
- public ScalarTypeLocale() {
- super(Locale.class);
- }
-
- @Override
- public int getLength() {
- return 20;
- }
-
- @Override
- public Locale convertFromDbString(String dbValue) {
- return parse(dbValue);
- }
-
- @Override
- public String convertToDbString(Locale beanValue) {
- return ((Locale) beanValue).toString();
- }
-
- @Override
- public String formatValue(Locale t) {
- return t.toString();
- }
-
- @Override
- public Locale parse(String value) {
-
- int pos1 = -1;
- int pos2 = -1;
-
- for (int i = 0; i < value.length(); i++) {
- char c = value.charAt(i);
- if (c == '_') {
- if (pos1 > -1) {
- pos2 = i;
- break;
- } else {
- pos1 = i;
- }
- }
- }
- if (pos1 == -1) {
- return new Locale(value);
- }
- String language = value.substring(0, pos1);
- if (pos2 == -1) {
- String country = value.substring(pos1 + 1);
- return new Locale(language, country);
- } else {
- String country = value.substring(pos1 + 1, pos2);
- String variant = value.substring(pos2 + 1);
- return new Locale(language, country, variant);
- }
- }
-
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.util.Locale;
+
+/**
+ * ScalarType for java.util.Currency which converts to and from a VARCHAR database column.
+ */
+public class ScalarTypeLocale extends ScalarTypeBaseVarchar {
+
+ public ScalarTypeLocale() {
+ super(Locale.class);
+ }
+
+ @Override
+ public int getLength() {
+ return 20;
+ }
+
+ @Override
+ public Locale convertFromDbString(String dbValue) {
+ return parse(dbValue);
+ }
+
+ @Override
+ public String convertToDbString(Locale beanValue) {
+ return ((Locale) beanValue).toString();
+ }
+
+ @Override
+ public String formatValue(Locale t) {
+ return t.toString();
+ }
+
+ @Override
+ public Locale parse(String value) {
+
+ int pos1 = -1;
+ int pos2 = -1;
+
+ for (int i = 0; i < value.length(); i++) {
+ char c = value.charAt(i);
+ if (c == '_') {
+ if (pos1 > -1) {
+ pos2 = i;
+ break;
+ } else {
+ pos1 = i;
+ }
+ }
+ }
+ if (pos1 == -1) {
+ return new Locale(value);
+ }
+ String language = value.substring(0, pos1);
+ if (pos2 == -1) {
+ String country = value.substring(pos1 + 1);
+ return new Locale(language, country);
+ } else {
+ String country = value.substring(pos1 + 1, pos2);
+ String variant = value.substring(pos2 + 1);
+ return new Locale(language, country, variant);
+ }
+ }
+
+}
diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLong.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLong.java
index 1bf541144..f14190777 100644
--- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLong.java
+++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeLong.java
@@ -1,96 +1,96 @@
-package com.avaje.ebeaninternal.server.type;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.sql.Types;
-
-import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
-import com.fasterxml.jackson.core.JsonGenerator;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-/**
- * ScalarType for Long and long.
- */
-public class ScalarTypeLong extends ScalarTypeBase {
-
- public ScalarTypeLong() {
- super(Long.class, true, Types.BIGINT);
- }
-
- @Override
- public void bind(DataBind b, Long value) throws SQLException {
- if (value == null) {
- b.setNull(Types.BIGINT);
- } else {
- b.setLong(value.longValue());
- }
- }
-
- @Override
- public Long read(DataReader dataReader) throws SQLException {
- return dataReader.getLong();
- }
-
- @Override
- public Object toJdbcType(Object value) {
- return BasicTypeConverter.toLong(value);
- }
-
- @Override
- public Long toBeanType(Object value) {
- return BasicTypeConverter.toLong(value);
- }
-
- @Override
- public String formatValue(Long t) {
- return t.toString();
- }
-
- @Override
- public Long parse(String value) {
- return Long.valueOf(value);
- }
-
- @Override
- public Long convertFromMillis(long systemTimeMillis) {
- return systemTimeMillis;
- }
-
- @Override
- public boolean isDateTimeCapable() {
- return true;
- }
-
- @Override
- public Long readData(DataInput dataInput) throws IOException {
- if (!dataInput.readBoolean()) {
- return null;
- } else {
- return dataInput.readLong();
- }
- }
-
- @Override
- public void writeData(DataOutput dataOutput, Long value) throws IOException {
-
- if (value == null) {
- dataOutput.writeBoolean(false);
- } else {
- dataOutput.writeBoolean(true);
- dataOutput.writeLong(value);
- }
- }
-
- @Override
- public Long jsonRead(JsonParser ctx, JsonToken event) throws IOException {
- return ctx.getLongValue();
- }
-
- @Override
- public void jsonWrite(JsonGenerator ctx, String name, Long value) throws IOException {
- ctx.writeNumberField(name, (Long) value);
- }
-}
+package com.avaje.ebeaninternal.server.type;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+
+/**
+ * ScalarType for Long and long.
+ */
+public class ScalarTypeLong extends ScalarTypeBase