mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - change newline char
This commit is contained in:
@@ -1,84 +1,84 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Used to map Bean values to DB values.
|
||||
* <p>
|
||||
* Useful for building Enum converters where you want to map the DB values an
|
||||
* Enum gets converter to.
|
||||
* </p>
|
||||
*
|
||||
* @param <B>
|
||||
* The Bean value type
|
||||
* @param <D>
|
||||
* The DB value type
|
||||
*/
|
||||
public class BeanToDbMap<B, D> {
|
||||
|
||||
final HashMap<B, D> keyMap;
|
||||
|
||||
final HashMap<D, B> valueMap;
|
||||
|
||||
final boolean allowNulls;
|
||||
|
||||
/**
|
||||
* Construct with allowNulls defaulting to false.
|
||||
*/
|
||||
public BeanToDbMap() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with allowNulls setting.
|
||||
* <p>
|
||||
* If allowNulls is false then an IllegalArgumentException is thrown by
|
||||
* either the getDBValue or getBeanValue methods if not matching Bean or DB
|
||||
* value is found.
|
||||
* </p>
|
||||
*/
|
||||
public BeanToDbMap(boolean allowNulls) {
|
||||
this.allowNulls = allowNulls;
|
||||
keyMap = new HashMap<B, D>();
|
||||
valueMap = new HashMap<D, B>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bean value and DB value pair.
|
||||
*/
|
||||
public BeanToDbMap<B, D> add(B beanValue, D dbValue) {
|
||||
keyMap.put(beanValue, dbValue);
|
||||
valueMap.put(dbValue, beanValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB value given the bean value.
|
||||
*/
|
||||
public D getDbValue(B beanValue) {
|
||||
if (beanValue == null){
|
||||
return null;
|
||||
}
|
||||
D dbValue = keyMap.get(beanValue);
|
||||
if (dbValue == null && !allowNulls) {
|
||||
String msg = "DB value for " + beanValue + " not found in "+valueMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return dbValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Bean value given the DB value.
|
||||
*/
|
||||
public B getBeanValue(D dbValue) {
|
||||
if (dbValue == null){
|
||||
return null;
|
||||
}
|
||||
B beanValue = valueMap.get(dbValue);
|
||||
if (beanValue == null && !allowNulls) {
|
||||
String msg = "Bean value for " + dbValue + " not found in "+valueMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return beanValue;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Used to map Bean values to DB values.
|
||||
* <p>
|
||||
* Useful for building Enum converters where you want to map the DB values an
|
||||
* Enum gets converter to.
|
||||
* </p>
|
||||
*
|
||||
* @param <B>
|
||||
* The Bean value type
|
||||
* @param <D>
|
||||
* The DB value type
|
||||
*/
|
||||
public class BeanToDbMap<B, D> {
|
||||
|
||||
final HashMap<B, D> keyMap;
|
||||
|
||||
final HashMap<D, B> valueMap;
|
||||
|
||||
final boolean allowNulls;
|
||||
|
||||
/**
|
||||
* Construct with allowNulls defaulting to false.
|
||||
*/
|
||||
public BeanToDbMap() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with allowNulls setting.
|
||||
* <p>
|
||||
* If allowNulls is false then an IllegalArgumentException is thrown by
|
||||
* either the getDBValue or getBeanValue methods if not matching Bean or DB
|
||||
* value is found.
|
||||
* </p>
|
||||
*/
|
||||
public BeanToDbMap(boolean allowNulls) {
|
||||
this.allowNulls = allowNulls;
|
||||
keyMap = new HashMap<B, D>();
|
||||
valueMap = new HashMap<D, B>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bean value and DB value pair.
|
||||
*/
|
||||
public BeanToDbMap<B, D> add(B beanValue, D dbValue) {
|
||||
keyMap.put(beanValue, dbValue);
|
||||
valueMap.put(dbValue, beanValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB value given the bean value.
|
||||
*/
|
||||
public D getDbValue(B beanValue) {
|
||||
if (beanValue == null){
|
||||
return null;
|
||||
}
|
||||
D dbValue = keyMap.get(beanValue);
|
||||
if (dbValue == null && !allowNulls) {
|
||||
String msg = "DB value for " + beanValue + " not found in "+valueMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return dbValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Bean value given the DB value.
|
||||
*/
|
||||
public B getBeanValue(D dbValue) {
|
||||
if (dbValue == null){
|
||||
return null;
|
||||
}
|
||||
B beanValue = valueMap.get(dbValue);
|
||||
if (beanValue == null && !allowNulls) {
|
||||
String msg = "Bean value for " + dbValue + " not found in "+valueMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return beanValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
/**
|
||||
* Wraps a CompoundTypeProperty with it's type and parent for nested compound
|
||||
* types.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class CtCompoundProperty {
|
||||
|
||||
private final String relativeName;
|
||||
|
||||
private final CtCompoundProperty parent;
|
||||
|
||||
private final CtCompoundType<?> compoundType;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
private final CompoundTypeProperty property;
|
||||
|
||||
public CtCompoundProperty(String relativeName, CtCompoundProperty parent, CtCompoundType<?> ctType,
|
||||
CompoundTypeProperty<?, ?> property) {
|
||||
|
||||
this.relativeName = relativeName;
|
||||
this.parent = parent;
|
||||
this.compoundType = ctType;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
/**
|
||||
* The property name relative to the root of the compound type.
|
||||
*/
|
||||
public String getRelativeName() {
|
||||
return relativeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The property name local to its type.
|
||||
*/
|
||||
public String getPropertyName() {
|
||||
return property.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return relativeName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getValue(Object valueObject) {
|
||||
if (valueObject == null) {
|
||||
return null;
|
||||
}
|
||||
if (parent != null) {
|
||||
valueObject = parent.getValue(valueObject);
|
||||
}
|
||||
return property.getValue(valueObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a scalar value that is used to build the immutable compound value
|
||||
* object.
|
||||
* <p>
|
||||
* When all the scalar values have been collected then the compound value
|
||||
* object is built and this can be recursive for nested compound types.
|
||||
* </p>
|
||||
*/
|
||||
public Object setValue(Object bean, Object value) {
|
||||
|
||||
// compoundType and propertyName should be correct depth
|
||||
Object compoundValue = ImmutableCompoundTypeBuilder.set(compoundType, property.getName(), value);
|
||||
|
||||
if (compoundValue != null && parent != null) {
|
||||
// Continue up the tree
|
||||
return parent.setValue(bean, compoundValue);
|
||||
|
||||
} else {
|
||||
return compoundValue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
/**
|
||||
* Wraps a CompoundTypeProperty with it's type and parent for nested compound
|
||||
* types.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class CtCompoundProperty {
|
||||
|
||||
private final String relativeName;
|
||||
|
||||
private final CtCompoundProperty parent;
|
||||
|
||||
private final CtCompoundType<?> compoundType;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
private final CompoundTypeProperty property;
|
||||
|
||||
public CtCompoundProperty(String relativeName, CtCompoundProperty parent, CtCompoundType<?> ctType,
|
||||
CompoundTypeProperty<?, ?> property) {
|
||||
|
||||
this.relativeName = relativeName;
|
||||
this.parent = parent;
|
||||
this.compoundType = ctType;
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
/**
|
||||
* The property name relative to the root of the compound type.
|
||||
*/
|
||||
public String getRelativeName() {
|
||||
return relativeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The property name local to its type.
|
||||
*/
|
||||
public String getPropertyName() {
|
||||
return property.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return relativeName;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getValue(Object valueObject) {
|
||||
if (valueObject == null) {
|
||||
return null;
|
||||
}
|
||||
if (parent != null) {
|
||||
valueObject = parent.getValue(valueObject);
|
||||
}
|
||||
return property.getValue(valueObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a scalar value that is used to build the immutable compound value
|
||||
* object.
|
||||
* <p>
|
||||
* When all the scalar values have been collected then the compound value
|
||||
* object is built and this can be recursive for nested compound types.
|
||||
* </p>
|
||||
*/
|
||||
public Object setValue(Object bean, Object value) {
|
||||
|
||||
// compoundType and propertyName should be correct depth
|
||||
Object compoundValue = ImmutableCompoundTypeBuilder.set(compoundType, property.getName(), value);
|
||||
|
||||
if (compoundValue != null && parent != null) {
|
||||
// Continue up the tree
|
||||
return parent.setValue(bean, compoundValue);
|
||||
|
||||
} else {
|
||||
return compoundValue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+145
-145
@@ -1,145 +1,145 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.text.StringFormatter;
|
||||
import com.avaje.ebean.text.StringParser;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
/**
|
||||
* Adapter for CtCompoundProperty to ElPropertyValue.
|
||||
* <p>
|
||||
* This is used for non-scalar properties of a Compound Value Object. These only
|
||||
* occur in nested compound types.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class CtCompoundPropertyElAdapter implements ElPropertyValue {
|
||||
|
||||
private final CtCompoundProperty prop;
|
||||
|
||||
private int deployOrder;
|
||||
|
||||
public CtCompoundPropertyElAdapter(CtCompoundProperty prop) {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
public void setDeployOrder(int deployOrder) {
|
||||
this.deployOrder = deployOrder;
|
||||
}
|
||||
|
||||
public Object elConvertType(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object elGetReference(EntityBean bean) {
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object elGetValue(EntityBean bean) {
|
||||
return prop.getValue(bean);
|
||||
}
|
||||
|
||||
public void elSetReference(EntityBean bean) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public void elSetValue(EntityBean bean, Object value, boolean populate) {
|
||||
prop.setValue(bean, value);
|
||||
}
|
||||
|
||||
public int getDeployOrder() {
|
||||
return deployOrder;
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public Object[] getAssocOneIdValues(EntityBean bean) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public String getAssocIdInValueExpr(int size) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public BeanProperty getBeanProperty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public StringFormatter getStringFormatter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public StringParser getStringParser() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isDbEncrypted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLocalEncrypted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAssocId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAssocProperty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getJdbcType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object parseDateTime(long systemTimeMillis) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsFormulaWithJoin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsMany() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsManySince(String sinceProperty) {
|
||||
return containsMany();
|
||||
}
|
||||
|
||||
public String getDbColumn() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getElPlaceholder(boolean encrypted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getElPrefix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return prop.getPropertyName();
|
||||
}
|
||||
|
||||
public String getElName() {
|
||||
return prop.getPropertyName();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.bean.EntityBean;
|
||||
import com.avaje.ebean.text.StringFormatter;
|
||||
import com.avaje.ebean.text.StringParser;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
/**
|
||||
* Adapter for CtCompoundProperty to ElPropertyValue.
|
||||
* <p>
|
||||
* This is used for non-scalar properties of a Compound Value Object. These only
|
||||
* occur in nested compound types.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class CtCompoundPropertyElAdapter implements ElPropertyValue {
|
||||
|
||||
private final CtCompoundProperty prop;
|
||||
|
||||
private int deployOrder;
|
||||
|
||||
public CtCompoundPropertyElAdapter(CtCompoundProperty prop) {
|
||||
this.prop = prop;
|
||||
}
|
||||
|
||||
public void setDeployOrder(int deployOrder) {
|
||||
this.deployOrder = deployOrder;
|
||||
}
|
||||
|
||||
public Object elConvertType(Object value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object elGetReference(EntityBean bean) {
|
||||
return bean;
|
||||
}
|
||||
|
||||
public Object elGetValue(EntityBean bean) {
|
||||
return prop.getValue(bean);
|
||||
}
|
||||
|
||||
public void elSetReference(EntityBean bean) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public void elSetValue(EntityBean bean, Object value, boolean populate) {
|
||||
prop.setValue(bean, value);
|
||||
}
|
||||
|
||||
public int getDeployOrder() {
|
||||
return deployOrder;
|
||||
}
|
||||
|
||||
public String getAssocOneIdExpr(String prefix, String operator) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public Object[] getAssocOneIdValues(EntityBean bean) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public String getAssocIdInExpr(String prefix) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public String getAssocIdInValueExpr(int size) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
public BeanProperty getBeanProperty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public StringFormatter getStringFormatter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public StringParser getStringParser() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isDbEncrypted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLocalEncrypted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAssocId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAssocProperty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getJdbcType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Object parseDateTime(long systemTimeMillis) {
|
||||
throw new RuntimeException("Not Supported or Expected");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsFormulaWithJoin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsMany() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsManySince(String sinceProperty) {
|
||||
return containsMany();
|
||||
}
|
||||
|
||||
public String getDbColumn() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getElPlaceholder(boolean encrypted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getElPrefix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return prop.getPropertyName();
|
||||
}
|
||||
|
||||
public String getElName() {
|
||||
return prop.getPropertyName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,229 +1,229 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.avaje.ebean.config.CompoundType;
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
|
||||
/**
|
||||
* The internal representation of a Compound Type (Immutable Compound Value Object).
|
||||
*
|
||||
* @param <V>
|
||||
* The Type of the "Immutable Compound Value Object".
|
||||
*/
|
||||
public final class CtCompoundType<V> implements ScalarDataReader<V> {
|
||||
|
||||
private final Class<V> cvoClass;
|
||||
|
||||
private final CompoundType<V> cvoType;
|
||||
|
||||
private final Map<String,CompoundTypeProperty<V, ?>> propertyMap;
|
||||
|
||||
private final ScalarDataReader<Object>[] propReaders;
|
||||
|
||||
private final CompoundTypeProperty<V, ?>[] properties;
|
||||
|
||||
public CtCompoundType(Class<V> cvoClass, CompoundType<V> cvoType, ScalarDataReader<Object>[] propReaders) {
|
||||
|
||||
this.cvoClass = cvoClass;
|
||||
this.cvoType = cvoType;
|
||||
this.properties = cvoType.getProperties();
|
||||
this.propReaders = propReaders;
|
||||
|
||||
this.propertyMap = new LinkedHashMap<String, CompoundTypeProperty<V,?>>();
|
||||
for (CompoundTypeProperty<V,?> cp: properties) {
|
||||
propertyMap.put(cp.getName(), cp);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return cvoClass.toString();
|
||||
}
|
||||
|
||||
public Class<V> getCompoundTypeClass() {
|
||||
return cvoClass;
|
||||
}
|
||||
|
||||
public V create(Object[] propertyValues) {
|
||||
return cvoType.create(propertyValues);
|
||||
}
|
||||
|
||||
|
||||
public V create(Map<String, Object> valueMap) {
|
||||
|
||||
if (valueMap.size() != properties.length) {
|
||||
// not enough elements in the map
|
||||
return null;
|
||||
}
|
||||
|
||||
// we expect the map to contain a value for
|
||||
// each property and that the values are the
|
||||
// correct type
|
||||
Object[] propertyValues = new Object[properties.length];
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
propertyValues[i] = valueMap.get(properties[i].getName());
|
||||
if (propertyValues[i] == null) {
|
||||
String m = "Null value for " + properties[i].getName() + " in map " + valueMap;
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
}
|
||||
|
||||
return create(propertyValues);
|
||||
}
|
||||
|
||||
public CompoundTypeProperty<V, ?>[] getProperties() {
|
||||
|
||||
return cvoType.getProperties();
|
||||
}
|
||||
|
||||
public Object[] getPropertyValues(V valueObject) {
|
||||
|
||||
Object[] values = new Object[properties.length];
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
values[i] = properties[i].getValue(valueObject);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public V read(DataReader source) throws SQLException {
|
||||
|
||||
boolean nullValue = false;
|
||||
Object[] values = new Object[propReaders.length];
|
||||
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
Object o = propReaders[i].read(source);
|
||||
values[i] = o;
|
||||
if (o == null){
|
||||
nullValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullValue){
|
||||
return null;
|
||||
}
|
||||
|
||||
return create(values);
|
||||
}
|
||||
|
||||
public void loadIgnore(DataReader dataReader) {
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
propReaders[i].loadIgnore(dataReader);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(DataBind b, V value) throws SQLException {
|
||||
|
||||
CompoundTypeProperty<V, ?>[] props = cvoType.getProperties();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object o = props[i].getValue(value);
|
||||
propReaders[i].bind(b, o);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively accumulate all the scalar types (in depth first order).
|
||||
* <p>
|
||||
* This creates a flat list of scalars even when compound types are embedded
|
||||
* inside compound types.
|
||||
* </p>
|
||||
*/
|
||||
public void accumulateScalarTypes(String parent, CtCompoundTypeScalarList list) {
|
||||
|
||||
CompoundTypeProperty<V, ?>[] props = cvoType.getProperties();
|
||||
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
String propName = getFullPropName(parent, props[i].getName());
|
||||
|
||||
list.addCompoundProperty(propName, this, props[i]);
|
||||
|
||||
propReaders[i].accumulateScalarTypes(propName, list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the full property name (for compound types embedded in other
|
||||
* compound types).
|
||||
*
|
||||
* @param parent
|
||||
* the parent property name
|
||||
* @param propName
|
||||
* the local property name
|
||||
*/
|
||||
private String getFullPropName(String parent, String propName) {
|
||||
if (parent == null) {
|
||||
return propName;
|
||||
} else {
|
||||
return parent + "." + propName;
|
||||
}
|
||||
}
|
||||
|
||||
public Object jsonConvert(Map<String, Object> map) {
|
||||
return readJsonElementObject(map);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object readJsonElementObject(Map<String,Object> jsonObject){
|
||||
|
||||
boolean nullValue = false;
|
||||
Object[] values = new Object[propReaders.length];
|
||||
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
String propName = properties[i].getName();
|
||||
Object jsonElement = jsonObject.get(propName);
|
||||
|
||||
if (propReaders[i] instanceof CtCompoundType<?>) {
|
||||
values[i] = ((CtCompoundType<?>)propReaders[i]).readJsonElementObject((Map<String,Object>)jsonElement);
|
||||
} else {
|
||||
//((ScalarType<?>)propReaders[i]).jsonFromString(jsonElement.toPrimitiveString(), ctx.getValueAdapter());
|
||||
values[i] = ((ScalarType<?>)propReaders[i]).parse(jsonElement.toString());;
|
||||
}
|
||||
if (values[i] == null){
|
||||
nullValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullValue){
|
||||
return null;
|
||||
}
|
||||
|
||||
return create(values);
|
||||
}
|
||||
|
||||
|
||||
public void jsonWrite(WriteJson ctx, Object valueObject, String propertyName) throws IOException {
|
||||
|
||||
ctx.beginAssocOne(propertyName, valueObject);
|
||||
jsonWriteProps(ctx, valueObject, propertyName);
|
||||
ctx.endAssocOne();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void jsonWriteProps(WriteJson ctx, Object valueObject, String propertyName) throws IOException {
|
||||
|
||||
if (propertyName != null) {
|
||||
ctx.gen().writeFieldName(propertyName);
|
||||
}
|
||||
ctx.gen().writeStartObject();
|
||||
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
String propName = properties[i].getName();
|
||||
Object value = properties[i].getValue((V) valueObject);
|
||||
if (propReaders[i] instanceof CtCompoundType<?>) {
|
||||
((CtCompoundType) propReaders[i]).jsonWrite(ctx, value, propName);
|
||||
|
||||
} else {
|
||||
((ScalarType) propReaders[i]).jsonWrite(ctx.gen(), propName, value);
|
||||
//ctx.appendNameValue(propName, (ScalarType) propReaders[i], value);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.gen().writeEndObject();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.avaje.ebean.config.CompoundType;
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
|
||||
/**
|
||||
* The internal representation of a Compound Type (Immutable Compound Value Object).
|
||||
*
|
||||
* @param <V>
|
||||
* The Type of the "Immutable Compound Value Object".
|
||||
*/
|
||||
public final class CtCompoundType<V> implements ScalarDataReader<V> {
|
||||
|
||||
private final Class<V> cvoClass;
|
||||
|
||||
private final CompoundType<V> cvoType;
|
||||
|
||||
private final Map<String,CompoundTypeProperty<V, ?>> propertyMap;
|
||||
|
||||
private final ScalarDataReader<Object>[] propReaders;
|
||||
|
||||
private final CompoundTypeProperty<V, ?>[] properties;
|
||||
|
||||
public CtCompoundType(Class<V> cvoClass, CompoundType<V> cvoType, ScalarDataReader<Object>[] propReaders) {
|
||||
|
||||
this.cvoClass = cvoClass;
|
||||
this.cvoType = cvoType;
|
||||
this.properties = cvoType.getProperties();
|
||||
this.propReaders = propReaders;
|
||||
|
||||
this.propertyMap = new LinkedHashMap<String, CompoundTypeProperty<V,?>>();
|
||||
for (CompoundTypeProperty<V,?> cp: properties) {
|
||||
propertyMap.put(cp.getName(), cp);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return cvoClass.toString();
|
||||
}
|
||||
|
||||
public Class<V> getCompoundTypeClass() {
|
||||
return cvoClass;
|
||||
}
|
||||
|
||||
public V create(Object[] propertyValues) {
|
||||
return cvoType.create(propertyValues);
|
||||
}
|
||||
|
||||
|
||||
public V create(Map<String, Object> valueMap) {
|
||||
|
||||
if (valueMap.size() != properties.length) {
|
||||
// not enough elements in the map
|
||||
return null;
|
||||
}
|
||||
|
||||
// we expect the map to contain a value for
|
||||
// each property and that the values are the
|
||||
// correct type
|
||||
Object[] propertyValues = new Object[properties.length];
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
propertyValues[i] = valueMap.get(properties[i].getName());
|
||||
if (propertyValues[i] == null) {
|
||||
String m = "Null value for " + properties[i].getName() + " in map " + valueMap;
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
}
|
||||
|
||||
return create(propertyValues);
|
||||
}
|
||||
|
||||
public CompoundTypeProperty<V, ?>[] getProperties() {
|
||||
|
||||
return cvoType.getProperties();
|
||||
}
|
||||
|
||||
public Object[] getPropertyValues(V valueObject) {
|
||||
|
||||
Object[] values = new Object[properties.length];
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
values[i] = properties[i].getValue(valueObject);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public V read(DataReader source) throws SQLException {
|
||||
|
||||
boolean nullValue = false;
|
||||
Object[] values = new Object[propReaders.length];
|
||||
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
Object o = propReaders[i].read(source);
|
||||
values[i] = o;
|
||||
if (o == null){
|
||||
nullValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullValue){
|
||||
return null;
|
||||
}
|
||||
|
||||
return create(values);
|
||||
}
|
||||
|
||||
public void loadIgnore(DataReader dataReader) {
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
propReaders[i].loadIgnore(dataReader);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(DataBind b, V value) throws SQLException {
|
||||
|
||||
CompoundTypeProperty<V, ?>[] props = cvoType.getProperties();
|
||||
|
||||
for (int i = 0; i < props.length; i++) {
|
||||
Object o = props[i].getValue(value);
|
||||
propReaders[i].bind(b, o);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively accumulate all the scalar types (in depth first order).
|
||||
* <p>
|
||||
* This creates a flat list of scalars even when compound types are embedded
|
||||
* inside compound types.
|
||||
* </p>
|
||||
*/
|
||||
public void accumulateScalarTypes(String parent, CtCompoundTypeScalarList list) {
|
||||
|
||||
CompoundTypeProperty<V, ?>[] props = cvoType.getProperties();
|
||||
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
String propName = getFullPropName(parent, props[i].getName());
|
||||
|
||||
list.addCompoundProperty(propName, this, props[i]);
|
||||
|
||||
propReaders[i].accumulateScalarTypes(propName, list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the full property name (for compound types embedded in other
|
||||
* compound types).
|
||||
*
|
||||
* @param parent
|
||||
* the parent property name
|
||||
* @param propName
|
||||
* the local property name
|
||||
*/
|
||||
private String getFullPropName(String parent, String propName) {
|
||||
if (parent == null) {
|
||||
return propName;
|
||||
} else {
|
||||
return parent + "." + propName;
|
||||
}
|
||||
}
|
||||
|
||||
public Object jsonConvert(Map<String, Object> map) {
|
||||
return readJsonElementObject(map);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object readJsonElementObject(Map<String,Object> jsonObject){
|
||||
|
||||
boolean nullValue = false;
|
||||
Object[] values = new Object[propReaders.length];
|
||||
|
||||
for (int i = 0; i < propReaders.length; i++) {
|
||||
String propName = properties[i].getName();
|
||||
Object jsonElement = jsonObject.get(propName);
|
||||
|
||||
if (propReaders[i] instanceof CtCompoundType<?>) {
|
||||
values[i] = ((CtCompoundType<?>)propReaders[i]).readJsonElementObject((Map<String,Object>)jsonElement);
|
||||
} else {
|
||||
//((ScalarType<?>)propReaders[i]).jsonFromString(jsonElement.toPrimitiveString(), ctx.getValueAdapter());
|
||||
values[i] = ((ScalarType<?>)propReaders[i]).parse(jsonElement.toString());;
|
||||
}
|
||||
if (values[i] == null){
|
||||
nullValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (nullValue){
|
||||
return null;
|
||||
}
|
||||
|
||||
return create(values);
|
||||
}
|
||||
|
||||
|
||||
public void jsonWrite(WriteJson ctx, Object valueObject, String propertyName) throws IOException {
|
||||
|
||||
ctx.beginAssocOne(propertyName, valueObject);
|
||||
jsonWriteProps(ctx, valueObject, propertyName);
|
||||
ctx.endAssocOne();
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void jsonWriteProps(WriteJson ctx, Object valueObject, String propertyName) throws IOException {
|
||||
|
||||
if (propertyName != null) {
|
||||
ctx.gen().writeFieldName(propertyName);
|
||||
}
|
||||
ctx.gen().writeStartObject();
|
||||
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
String propName = properties[i].getName();
|
||||
Object value = properties[i].getValue((V) valueObject);
|
||||
if (propReaders[i] instanceof CtCompoundType<?>) {
|
||||
((CtCompoundType) propReaders[i]).jsonWrite(ctx, value, propName);
|
||||
|
||||
} else {
|
||||
((ScalarType) propReaders[i]).jsonWrite(ctx.gen(), propName, value);
|
||||
//ctx.appendNameValue(propName, (ScalarType) propReaders[i], value);
|
||||
}
|
||||
}
|
||||
|
||||
ctx.gen().writeEndObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
|
||||
/**
|
||||
* Used to build a flat list of all the scalar types nested in a compound type.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public final class CtCompoundTypeScalarList {
|
||||
|
||||
private final LinkedHashMap<String,ScalarType<?>> scalarProps = new LinkedHashMap<String,ScalarType<?>>();
|
||||
|
||||
private final LinkedHashMap<String,CtCompoundProperty> compoundProperties = new LinkedHashMap<String, CtCompoundProperty>();
|
||||
|
||||
/**
|
||||
* Return the list of non-scalar properties. These occur when compound types are nested.
|
||||
*/
|
||||
public List<CtCompoundProperty> getNonScalarProperties() {
|
||||
|
||||
List<CtCompoundProperty> nonScalarProps = new ArrayList<CtCompoundProperty>();
|
||||
|
||||
for (String propKey: compoundProperties.keySet()) {
|
||||
if (!scalarProps.containsKey(propKey)){
|
||||
nonScalarProps.add(compoundProperties.get(propKey));
|
||||
}
|
||||
}
|
||||
|
||||
return nonScalarProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a property with it's associated compound type and relative name.
|
||||
*/
|
||||
public void addCompoundProperty(String propName, CtCompoundType<?> t, CompoundTypeProperty<?,?> prop) {
|
||||
|
||||
CtCompoundProperty parent = null;
|
||||
String[] split = SplitName.split(propName);
|
||||
if (split[0] != null){
|
||||
parent = compoundProperties.get(split[0]);
|
||||
}
|
||||
|
||||
CtCompoundProperty p = new CtCompoundProperty(propName, parent, t, prop);
|
||||
compoundProperties.put(propName, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a scalarType used in the compound type with its given property name.
|
||||
*/
|
||||
public void addScalarType(String propName, ScalarType<?> scalar){
|
||||
scalarProps.put(propName, scalar);
|
||||
}
|
||||
|
||||
public CtCompoundProperty getCompoundType(String propName) {
|
||||
return compoundProperties.get(propName);
|
||||
}
|
||||
|
||||
public Set<Entry<String, ScalarType<?>>> entries() {
|
||||
return scalarProps.entrySet();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
|
||||
/**
|
||||
* Used to build a flat list of all the scalar types nested in a compound type.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public final class CtCompoundTypeScalarList {
|
||||
|
||||
private final LinkedHashMap<String,ScalarType<?>> scalarProps = new LinkedHashMap<String,ScalarType<?>>();
|
||||
|
||||
private final LinkedHashMap<String,CtCompoundProperty> compoundProperties = new LinkedHashMap<String, CtCompoundProperty>();
|
||||
|
||||
/**
|
||||
* Return the list of non-scalar properties. These occur when compound types are nested.
|
||||
*/
|
||||
public List<CtCompoundProperty> getNonScalarProperties() {
|
||||
|
||||
List<CtCompoundProperty> nonScalarProps = new ArrayList<CtCompoundProperty>();
|
||||
|
||||
for (String propKey: compoundProperties.keySet()) {
|
||||
if (!scalarProps.containsKey(propKey)){
|
||||
nonScalarProps.add(compoundProperties.get(propKey));
|
||||
}
|
||||
}
|
||||
|
||||
return nonScalarProps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a property with it's associated compound type and relative name.
|
||||
*/
|
||||
public void addCompoundProperty(String propName, CtCompoundType<?> t, CompoundTypeProperty<?,?> prop) {
|
||||
|
||||
CtCompoundProperty parent = null;
|
||||
String[] split = SplitName.split(propName);
|
||||
if (split[0] != null){
|
||||
parent = compoundProperties.get(split[0]);
|
||||
}
|
||||
|
||||
CtCompoundProperty p = new CtCompoundProperty(propName, parent, t, prop);
|
||||
compoundProperties.put(propName, p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a scalarType used in the compound type with its given property name.
|
||||
*/
|
||||
public void addScalarType(String propName, ScalarType<?> scalar){
|
||||
scalarProps.put(propName, scalar);
|
||||
}
|
||||
|
||||
public CtCompoundProperty getCompoundType(String propName) {
|
||||
return compoundProperties.get(propName);
|
||||
}
|
||||
|
||||
public Set<Entry<String, ScalarType<?>>> entries() {
|
||||
return scalarProps.entrySet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class DataBind {
|
||||
|
||||
private final PreparedStatement pstmt;
|
||||
|
||||
private int pos;
|
||||
|
||||
public DataBind(PreparedStatement pstmt) {
|
||||
this.pstmt = pstmt;
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
public int currentPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void resetPos() {
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
public void setObject(Object value) throws SQLException {
|
||||
pstmt.setObject(++pos, value);
|
||||
}
|
||||
|
||||
public void setObject(Object value, int sqlType) throws SQLException {
|
||||
pstmt.setObject(++pos, value, sqlType);
|
||||
}
|
||||
|
||||
public void setNull(int jdbcType) throws SQLException {
|
||||
pstmt.setNull(++pos, jdbcType);
|
||||
}
|
||||
|
||||
public int nextPos() {
|
||||
return ++pos;
|
||||
}
|
||||
|
||||
public int decrementPos() {
|
||||
return ++pos;
|
||||
}
|
||||
|
||||
public int executeUpdate() throws SQLException {
|
||||
return pstmt.executeUpdate();
|
||||
}
|
||||
|
||||
public PreparedStatement getPstmt() {
|
||||
return pstmt;
|
||||
}
|
||||
|
||||
public void setString(String s) throws SQLException {
|
||||
pstmt.setString(++pos, s);
|
||||
}
|
||||
|
||||
public void setInt(int i) throws SQLException {
|
||||
pstmt.setInt(++pos, i);
|
||||
}
|
||||
|
||||
public void setLong(long i) throws SQLException {
|
||||
pstmt.setLong(++pos, i);
|
||||
}
|
||||
|
||||
public void setShort(short i) throws SQLException {
|
||||
pstmt.setShort(++pos, i);
|
||||
}
|
||||
|
||||
public void setFloat(float i) throws SQLException {
|
||||
pstmt.setFloat(++pos, i);
|
||||
}
|
||||
|
||||
public void setDouble(double i) throws SQLException {
|
||||
pstmt.setDouble(++pos, i);
|
||||
}
|
||||
|
||||
public void setBigDecimal(BigDecimal v) throws SQLException {
|
||||
pstmt.setBigDecimal(++pos, v);
|
||||
}
|
||||
|
||||
public void setDate(java.sql.Date v) throws SQLException {
|
||||
pstmt.setDate(++pos, v);
|
||||
}
|
||||
|
||||
public void setTimestamp(Timestamp v) throws SQLException {
|
||||
pstmt.setTimestamp(++pos, v);
|
||||
}
|
||||
|
||||
public void setTime(Time v) throws SQLException {
|
||||
pstmt.setTime(++pos, v);
|
||||
}
|
||||
|
||||
public void setBoolean(boolean v) throws SQLException {
|
||||
pstmt.setBoolean(++pos, v);
|
||||
}
|
||||
|
||||
public void setBytes(byte[] v) throws SQLException {
|
||||
pstmt.setBytes(++pos, v);
|
||||
}
|
||||
|
||||
public void setByte(byte v) throws SQLException {
|
||||
pstmt.setByte(++pos, v);
|
||||
}
|
||||
|
||||
public void setChar(char v) throws SQLException {
|
||||
pstmt.setString(++pos, String.valueOf(v));
|
||||
}
|
||||
|
||||
public void setBlob(InputStream inputStream, long length) throws SQLException {
|
||||
pstmt.setBlob(++pos, inputStream, length);
|
||||
}
|
||||
|
||||
public void setBlob(InputStream inputStream) throws SQLException {
|
||||
pstmt.setBlob(++pos, inputStream);
|
||||
}
|
||||
|
||||
public void setBlob(byte[] bytes) throws SQLException {
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
|
||||
pstmt.setBinaryStream(++pos, is, bytes.length);
|
||||
}
|
||||
|
||||
public void setClob(String content) throws SQLException {
|
||||
Reader reader = new StringReader(content);
|
||||
pstmt.setCharacterStream(++pos, reader, content.length());
|
||||
}
|
||||
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class DataBind {
|
||||
|
||||
private final PreparedStatement pstmt;
|
||||
|
||||
private int pos;
|
||||
|
||||
public DataBind(PreparedStatement pstmt) {
|
||||
this.pstmt = pstmt;
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
public int currentPos() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public void resetPos() {
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
public void setObject(Object value) throws SQLException {
|
||||
pstmt.setObject(++pos, value);
|
||||
}
|
||||
|
||||
public void setObject(Object value, int sqlType) throws SQLException {
|
||||
pstmt.setObject(++pos, value, sqlType);
|
||||
}
|
||||
|
||||
public void setNull(int jdbcType) throws SQLException {
|
||||
pstmt.setNull(++pos, jdbcType);
|
||||
}
|
||||
|
||||
public int nextPos() {
|
||||
return ++pos;
|
||||
}
|
||||
|
||||
public int decrementPos() {
|
||||
return ++pos;
|
||||
}
|
||||
|
||||
public int executeUpdate() throws SQLException {
|
||||
return pstmt.executeUpdate();
|
||||
}
|
||||
|
||||
public PreparedStatement getPstmt() {
|
||||
return pstmt;
|
||||
}
|
||||
|
||||
public void setString(String s) throws SQLException {
|
||||
pstmt.setString(++pos, s);
|
||||
}
|
||||
|
||||
public void setInt(int i) throws SQLException {
|
||||
pstmt.setInt(++pos, i);
|
||||
}
|
||||
|
||||
public void setLong(long i) throws SQLException {
|
||||
pstmt.setLong(++pos, i);
|
||||
}
|
||||
|
||||
public void setShort(short i) throws SQLException {
|
||||
pstmt.setShort(++pos, i);
|
||||
}
|
||||
|
||||
public void setFloat(float i) throws SQLException {
|
||||
pstmt.setFloat(++pos, i);
|
||||
}
|
||||
|
||||
public void setDouble(double i) throws SQLException {
|
||||
pstmt.setDouble(++pos, i);
|
||||
}
|
||||
|
||||
public void setBigDecimal(BigDecimal v) throws SQLException {
|
||||
pstmt.setBigDecimal(++pos, v);
|
||||
}
|
||||
|
||||
public void setDate(java.sql.Date v) throws SQLException {
|
||||
pstmt.setDate(++pos, v);
|
||||
}
|
||||
|
||||
public void setTimestamp(Timestamp v) throws SQLException {
|
||||
pstmt.setTimestamp(++pos, v);
|
||||
}
|
||||
|
||||
public void setTime(Time v) throws SQLException {
|
||||
pstmt.setTime(++pos, v);
|
||||
}
|
||||
|
||||
public void setBoolean(boolean v) throws SQLException {
|
||||
pstmt.setBoolean(++pos, v);
|
||||
}
|
||||
|
||||
public void setBytes(byte[] v) throws SQLException {
|
||||
pstmt.setBytes(++pos, v);
|
||||
}
|
||||
|
||||
public void setByte(byte v) throws SQLException {
|
||||
pstmt.setByte(++pos, v);
|
||||
}
|
||||
|
||||
public void setChar(char v) throws SQLException {
|
||||
pstmt.setString(++pos, String.valueOf(v));
|
||||
}
|
||||
|
||||
public void setBlob(InputStream inputStream, long length) throws SQLException {
|
||||
pstmt.setBlob(++pos, inputStream, length);
|
||||
}
|
||||
|
||||
public void setBlob(InputStream inputStream) throws SQLException {
|
||||
pstmt.setBlob(++pos, inputStream);
|
||||
}
|
||||
|
||||
public void setBlob(byte[] bytes) throws SQLException {
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
|
||||
pstmt.setBinaryStream(++pos, is, bytes.length);
|
||||
}
|
||||
|
||||
public void setClob(String content) throws SQLException {
|
||||
Reader reader = new StringReader(content);
|
||||
pstmt.setCharacterStream(++pos, reader, content.length());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +1,43 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.EncryptKeyManager;
|
||||
import com.avaje.ebean.config.Encryptor;
|
||||
|
||||
public class DataEncryptSupport {
|
||||
|
||||
private final EncryptKeyManager encryptKeyManager;
|
||||
private final Encryptor encryptor;
|
||||
private final String table;
|
||||
private final String column;
|
||||
|
||||
public DataEncryptSupport(EncryptKeyManager encryptKeyManager, Encryptor encryptor, String table, String column) {
|
||||
this.encryptKeyManager = encryptKeyManager;
|
||||
this.encryptor = encryptor;
|
||||
this.table = table;
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public byte[] encrypt(byte[] data){
|
||||
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.encrypt(data, key);
|
||||
}
|
||||
|
||||
public byte[] decrypt(byte[] data){
|
||||
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.decrypt(data, key);
|
||||
}
|
||||
|
||||
public String decryptObject(byte[] data) {
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.decryptString(data, key);
|
||||
}
|
||||
|
||||
public <T> byte[] encryptObject(String formattedValue) {
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.encryptString(formattedValue, key);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.EncryptKeyManager;
|
||||
import com.avaje.ebean.config.Encryptor;
|
||||
|
||||
public class DataEncryptSupport {
|
||||
|
||||
private final EncryptKeyManager encryptKeyManager;
|
||||
private final Encryptor encryptor;
|
||||
private final String table;
|
||||
private final String column;
|
||||
|
||||
public DataEncryptSupport(EncryptKeyManager encryptKeyManager, Encryptor encryptor, String table, String column) {
|
||||
this.encryptKeyManager = encryptKeyManager;
|
||||
this.encryptor = encryptor;
|
||||
this.table = table;
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
public byte[] encrypt(byte[] data){
|
||||
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.encrypt(data, key);
|
||||
}
|
||||
|
||||
public byte[] decrypt(byte[] data){
|
||||
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.decrypt(data, key);
|
||||
}
|
||||
|
||||
public String decryptObject(byte[] data) {
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.decryptString(data, key);
|
||||
}
|
||||
|
||||
public <T> byte[] encryptObject(String formattedValue) {
|
||||
EncryptKey key = encryptKeyManager.getEncryptKey(table, column);
|
||||
return encryptor.encryptString(formattedValue, key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Array;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface DataReader {
|
||||
|
||||
public void close() throws SQLException;
|
||||
|
||||
public boolean next() throws SQLException;
|
||||
|
||||
public void resetColumnPosition();
|
||||
|
||||
public void incrementPos(int increment);
|
||||
|
||||
public byte[] getBinaryBytes() throws SQLException;
|
||||
|
||||
public byte[] getBlobBytes() throws SQLException;
|
||||
|
||||
public String getStringFromStream() throws SQLException;
|
||||
|
||||
public String getStringClob() throws SQLException;
|
||||
|
||||
public String getString() throws SQLException;
|
||||
|
||||
public Boolean getBoolean() throws SQLException;
|
||||
|
||||
public Byte getByte() throws SQLException;
|
||||
|
||||
public Short getShort() throws SQLException;
|
||||
|
||||
public Integer getInt() throws SQLException;
|
||||
|
||||
public Long getLong() throws SQLException;
|
||||
|
||||
public Float getFloat() throws SQLException;
|
||||
|
||||
public Double getDouble() throws SQLException;
|
||||
|
||||
public byte[] getBytes() throws SQLException;
|
||||
|
||||
public java.sql.Date getDate() throws SQLException;
|
||||
|
||||
public java.sql.Time getTime() throws SQLException;
|
||||
|
||||
public java.sql.Timestamp getTimestamp() throws SQLException;
|
||||
|
||||
public BigDecimal getBigDecimal() throws SQLException;
|
||||
|
||||
public Array getArray() throws SQLException;
|
||||
|
||||
public Object getObject() throws SQLException;
|
||||
|
||||
public InputStream getBinaryStream() throws SQLException;
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Array;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface DataReader {
|
||||
|
||||
public void close() throws SQLException;
|
||||
|
||||
public boolean next() throws SQLException;
|
||||
|
||||
public void resetColumnPosition();
|
||||
|
||||
public void incrementPos(int increment);
|
||||
|
||||
public byte[] getBinaryBytes() throws SQLException;
|
||||
|
||||
public byte[] getBlobBytes() throws SQLException;
|
||||
|
||||
public String getStringFromStream() throws SQLException;
|
||||
|
||||
public String getStringClob() throws SQLException;
|
||||
|
||||
public String getString() throws SQLException;
|
||||
|
||||
public Boolean getBoolean() throws SQLException;
|
||||
|
||||
public Byte getByte() throws SQLException;
|
||||
|
||||
public Short getShort() throws SQLException;
|
||||
|
||||
public Integer getInt() throws SQLException;
|
||||
|
||||
public Long getLong() throws SQLException;
|
||||
|
||||
public Float getFloat() throws SQLException;
|
||||
|
||||
public Double getDouble() throws SQLException;
|
||||
|
||||
public byte[] getBytes() throws SQLException;
|
||||
|
||||
public java.sql.Date getDate() throws SQLException;
|
||||
|
||||
public java.sql.Time getTime() throws SQLException;
|
||||
|
||||
public java.sql.Timestamp getTimestamp() throws SQLException;
|
||||
|
||||
public BigDecimal getBigDecimal() throws SQLException;
|
||||
|
||||
public Array getArray() throws SQLException;
|
||||
|
||||
public Object getObject() throws SQLException;
|
||||
|
||||
public InputStream getBinaryStream() throws SQLException;
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class DateTimeJsonParser {
|
||||
|
||||
private final SimpleDateFormat dateTimeProto;
|
||||
|
||||
public DateTimeJsonParser() {
|
||||
this("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
}
|
||||
|
||||
public DateTimeJsonParser(String dateTimeFormat) {
|
||||
this.dateTimeProto = new SimpleDateFormat(dateTimeFormat);
|
||||
this.dateTimeProto.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
|
||||
private SimpleDateFormat dtFormat() {
|
||||
return (SimpleDateFormat) dateTimeProto.clone();
|
||||
}
|
||||
|
||||
public Timestamp parse(String jsonDateTime) {
|
||||
try {
|
||||
java.util.Date d = dtFormat().parse(jsonDateTime);
|
||||
return new Timestamp(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException("Error parsing Datetime[" + jsonDateTime + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
public String format(Date value) {
|
||||
return dtFormat().format(value);
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class DateTimeJsonParser {
|
||||
|
||||
private final SimpleDateFormat dateTimeProto;
|
||||
|
||||
public DateTimeJsonParser() {
|
||||
this("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
}
|
||||
|
||||
public DateTimeJsonParser(String dateTimeFormat) {
|
||||
this.dateTimeProto = new SimpleDateFormat(dateTimeFormat);
|
||||
this.dateTimeProto.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
}
|
||||
|
||||
private SimpleDateFormat dtFormat() {
|
||||
return (SimpleDateFormat) dateTimeProto.clone();
|
||||
}
|
||||
|
||||
public Timestamp parse(String jsonDateTime) {
|
||||
try {
|
||||
java.util.Date d = dtFormat().parse(jsonDateTime);
|
||||
return new Timestamp(d.getTime());
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException("Error parsing Datetime[" + jsonDateTime + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
public String format(Date value) {
|
||||
return dtFormat().format(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,143 +1,143 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* Helper to create some default ScalarType objects for Booleans,
|
||||
* java.util.Date, java.util.Calendar etc.
|
||||
*/
|
||||
public class DefaultTypeFactory {
|
||||
|
||||
private final ServerConfig serverConfig;
|
||||
|
||||
public DefaultTypeFactory(ServerConfig serverConfig) {
|
||||
this.serverConfig = serverConfig;
|
||||
}
|
||||
|
||||
private ScalarType<Boolean> createBoolean(String trueValue, String falseValue) {
|
||||
|
||||
try {
|
||||
// first try Integer based boolean
|
||||
Integer intTrue = BasicTypeConverter.toInteger(trueValue);
|
||||
Integer intFalse = BasicTypeConverter.toInteger(falseValue);
|
||||
|
||||
return new ScalarTypeBoolean.IntBoolean(intTrue, intFalse);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
// treat as Varchar/String based boolean
|
||||
return new ScalarTypeBoolean.StringBoolean(trueValue, falseValue);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the ScalarType for mapping Booleans. For some databases this is a
|
||||
* native data type and for others Booleans will be converted to Y/N or 0/1
|
||||
* etc.
|
||||
*/
|
||||
public ScalarType<Boolean> createBoolean() {
|
||||
|
||||
if (serverConfig == null) {
|
||||
return new ScalarTypeBoolean.Native();
|
||||
}
|
||||
String trueValue = serverConfig.getDatabaseBooleanTrue();
|
||||
String falseValue = serverConfig.getDatabaseBooleanFalse();
|
||||
|
||||
if (falseValue != null && trueValue != null) {
|
||||
// explicit integer or string based booleans
|
||||
return createBoolean(trueValue, falseValue);
|
||||
}
|
||||
|
||||
// determine based on database platform configuration
|
||||
int booleanDbType = serverConfig.getDatabasePlatform().getBooleanDbType();
|
||||
|
||||
// Some dbs use BIT e.g. MySQL
|
||||
if (booleanDbType == Types.BIT) {
|
||||
return new ScalarTypeBoolean.BitBoolean();
|
||||
}
|
||||
|
||||
if (booleanDbType == Types.INTEGER) {
|
||||
return new ScalarTypeBoolean.IntBoolean(1, 0);
|
||||
}
|
||||
if (booleanDbType == Types.VARCHAR) {
|
||||
return new ScalarTypeBoolean.StringBoolean("T", "F");
|
||||
}
|
||||
|
||||
if (booleanDbType == Types.BOOLEAN) {
|
||||
return new ScalarTypeBoolean.Native();
|
||||
}
|
||||
|
||||
// assume the JDBC driver can convert the type
|
||||
return new ScalarTypeBoolean.Native();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the default ScalarType for java.util.Date.
|
||||
*/
|
||||
public ScalarType<java.util.Date> createUtilDate(JsonConfig.DateTime mode) {
|
||||
// by default map anonymous java.util.Date to java.sql.Timestamp.
|
||||
// String mapType =
|
||||
// properties.getProperty("type.mapping.java.util.Date","timestamp");
|
||||
int utilDateType = getTemporalMapType("timestamp");
|
||||
|
||||
return createUtilDate(mode, utilDateType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ScalarType for java.util.Date explicitly specifying the type to
|
||||
* map to.
|
||||
*/
|
||||
public ScalarType<java.util.Date> createUtilDate(JsonConfig.DateTime mode, int utilDateType) {
|
||||
|
||||
switch (utilDateType) {
|
||||
case Types.DATE:
|
||||
return new ScalarTypeUtilDate.DateType();
|
||||
|
||||
case Types.TIMESTAMP:
|
||||
return new ScalarTypeUtilDate.TimestampType(mode);
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Invalid type " + utilDateType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the default ScalarType for java.util.Calendar.
|
||||
*/
|
||||
public ScalarType<Calendar> createCalendar(JsonConfig.DateTime mode) {
|
||||
|
||||
int jdbcType = getTemporalMapType("timestamp");
|
||||
return createCalendar(mode, jdbcType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ScalarType for java.util.Calendar explicitly specifying the type
|
||||
* to map to.
|
||||
*/
|
||||
public ScalarType<Calendar> createCalendar(JsonConfig.DateTime mode, int jdbcType) {
|
||||
|
||||
return new ScalarTypeCalendar(mode, jdbcType);
|
||||
}
|
||||
|
||||
private int getTemporalMapType(String mapType) {
|
||||
if (mapType.equalsIgnoreCase("date")) {
|
||||
return java.sql.Types.DATE;
|
||||
}
|
||||
return java.sql.Types.TIMESTAMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ScalarType for java.math.BigInteger.
|
||||
*/
|
||||
public ScalarType<BigInteger> createMathBigInteger() {
|
||||
|
||||
return new ScalarTypeMathBigInteger();
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebean.config.ServerConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* Helper to create some default ScalarType objects for Booleans,
|
||||
* java.util.Date, java.util.Calendar etc.
|
||||
*/
|
||||
public class DefaultTypeFactory {
|
||||
|
||||
private final ServerConfig serverConfig;
|
||||
|
||||
public DefaultTypeFactory(ServerConfig serverConfig) {
|
||||
this.serverConfig = serverConfig;
|
||||
}
|
||||
|
||||
private ScalarType<Boolean> createBoolean(String trueValue, String falseValue) {
|
||||
|
||||
try {
|
||||
// first try Integer based boolean
|
||||
Integer intTrue = BasicTypeConverter.toInteger(trueValue);
|
||||
Integer intFalse = BasicTypeConverter.toInteger(falseValue);
|
||||
|
||||
return new ScalarTypeBoolean.IntBoolean(intTrue, intFalse);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
// treat as Varchar/String based boolean
|
||||
return new ScalarTypeBoolean.StringBoolean(trueValue, falseValue);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the ScalarType for mapping Booleans. For some databases this is a
|
||||
* native data type and for others Booleans will be converted to Y/N or 0/1
|
||||
* etc.
|
||||
*/
|
||||
public ScalarType<Boolean> createBoolean() {
|
||||
|
||||
if (serverConfig == null) {
|
||||
return new ScalarTypeBoolean.Native();
|
||||
}
|
||||
String trueValue = serverConfig.getDatabaseBooleanTrue();
|
||||
String falseValue = serverConfig.getDatabaseBooleanFalse();
|
||||
|
||||
if (falseValue != null && trueValue != null) {
|
||||
// explicit integer or string based booleans
|
||||
return createBoolean(trueValue, falseValue);
|
||||
}
|
||||
|
||||
// determine based on database platform configuration
|
||||
int booleanDbType = serverConfig.getDatabasePlatform().getBooleanDbType();
|
||||
|
||||
// Some dbs use BIT e.g. MySQL
|
||||
if (booleanDbType == Types.BIT) {
|
||||
return new ScalarTypeBoolean.BitBoolean();
|
||||
}
|
||||
|
||||
if (booleanDbType == Types.INTEGER) {
|
||||
return new ScalarTypeBoolean.IntBoolean(1, 0);
|
||||
}
|
||||
if (booleanDbType == Types.VARCHAR) {
|
||||
return new ScalarTypeBoolean.StringBoolean("T", "F");
|
||||
}
|
||||
|
||||
if (booleanDbType == Types.BOOLEAN) {
|
||||
return new ScalarTypeBoolean.Native();
|
||||
}
|
||||
|
||||
// assume the JDBC driver can convert the type
|
||||
return new ScalarTypeBoolean.Native();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the default ScalarType for java.util.Date.
|
||||
*/
|
||||
public ScalarType<java.util.Date> createUtilDate(JsonConfig.DateTime mode) {
|
||||
// by default map anonymous java.util.Date to java.sql.Timestamp.
|
||||
// String mapType =
|
||||
// properties.getProperty("type.mapping.java.util.Date","timestamp");
|
||||
int utilDateType = getTemporalMapType("timestamp");
|
||||
|
||||
return createUtilDate(mode, utilDateType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ScalarType for java.util.Date explicitly specifying the type to
|
||||
* map to.
|
||||
*/
|
||||
public ScalarType<java.util.Date> createUtilDate(JsonConfig.DateTime mode, int utilDateType) {
|
||||
|
||||
switch (utilDateType) {
|
||||
case Types.DATE:
|
||||
return new ScalarTypeUtilDate.DateType();
|
||||
|
||||
case Types.TIMESTAMP:
|
||||
return new ScalarTypeUtilDate.TimestampType(mode);
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Invalid type " + utilDateType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the default ScalarType for java.util.Calendar.
|
||||
*/
|
||||
public ScalarType<Calendar> createCalendar(JsonConfig.DateTime mode) {
|
||||
|
||||
int jdbcType = getTemporalMapType("timestamp");
|
||||
return createCalendar(mode, jdbcType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ScalarType for java.util.Calendar explicitly specifying the type
|
||||
* to map to.
|
||||
*/
|
||||
public ScalarType<Calendar> createCalendar(JsonConfig.DateTime mode, int jdbcType) {
|
||||
|
||||
return new ScalarTypeCalendar(mode, jdbcType);
|
||||
}
|
||||
|
||||
private int getTemporalMapType(String mapType) {
|
||||
if (mapType.equalsIgnoreCase("date")) {
|
||||
return java.sql.Types.DATE;
|
||||
}
|
||||
return java.sql.Types.TIMESTAMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ScalarType for java.math.BigInteger.
|
||||
*/
|
||||
public ScalarType<BigInteger> createMathBigInteger() {
|
||||
|
||||
return new ScalarTypeMathBigInteger();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* Used to map Bean values to DB values.
|
||||
* <p>
|
||||
* Useful for building Enum converters where you want to map the DB values an
|
||||
* Enum gets converter to.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class EnumToDbValueMap<T> {
|
||||
|
||||
public static EnumToDbValueMap<?> create(boolean integerType) {
|
||||
return integerType ? new EnumToDbIntegerMap() : new EnumToDbStringMap();
|
||||
}
|
||||
|
||||
final LinkedHashMap<Object, T> keyMap;
|
||||
|
||||
final LinkedHashMap<T, Object> valueMap;
|
||||
|
||||
final boolean allowNulls;
|
||||
|
||||
final boolean isIntegerType;
|
||||
|
||||
/**
|
||||
* Construct with allowNulls defaulting to false.
|
||||
*/
|
||||
public EnumToDbValueMap() {
|
||||
this(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with allowNulls setting.
|
||||
* <p>
|
||||
* If allowNulls is false then an IllegalArgumentException is thrown by
|
||||
* either the getDBValue or getBeanValue methods if not matching Bean or DB
|
||||
* value is found.
|
||||
* </p>
|
||||
*/
|
||||
public EnumToDbValueMap(boolean allowNulls, boolean isIntegerType) {
|
||||
this.allowNulls = allowNulls;
|
||||
this.isIntegerType = isIntegerType;
|
||||
keyMap = new LinkedHashMap<Object, T>();
|
||||
valueMap = new LinkedHashMap<T, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this is mapping to integers, false
|
||||
* if mapping to Strings.
|
||||
*/
|
||||
public boolean isIntegerType() {
|
||||
return isIntegerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB values.
|
||||
*/
|
||||
public Iterator<T> dbValues() {
|
||||
return valueMap.keySet().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bean 'key' value.
|
||||
*/
|
||||
public Iterator<Object> beanValues() {
|
||||
return valueMap.values().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind using the correct database type.
|
||||
*/
|
||||
public abstract void bind(DataBind b, Object value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Read using the correct database type.
|
||||
*/
|
||||
public abstract Object read(DataReader dataReader) throws SQLException;
|
||||
|
||||
/**
|
||||
* Return the database type.
|
||||
*/
|
||||
public abstract int getDbType();
|
||||
|
||||
/**
|
||||
* Add name value pair where the dbValue is the raw string and may need to
|
||||
* be converted (to an Integer for example).
|
||||
*/
|
||||
public abstract EnumToDbValueMap<T> add(Object beanValue, String dbValue);
|
||||
|
||||
/**
|
||||
* Add a bean value and DB value pair.
|
||||
* <p>
|
||||
* The dbValue will be converted to an Integer if isIntegerType is true;
|
||||
* </p>
|
||||
*/
|
||||
protected void addInternal(Object beanValue, T dbValue) {
|
||||
|
||||
keyMap.put(beanValue, dbValue);
|
||||
valueMap.put(dbValue, beanValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB value given the bean value.
|
||||
*/
|
||||
public T getDbValue(Object beanValue) {
|
||||
if (beanValue == null) {
|
||||
return null;
|
||||
}
|
||||
T dbValue = keyMap.get(beanValue);
|
||||
if (dbValue == null && !allowNulls) {
|
||||
String msg = "DB value for " + beanValue + " not found in " + keyMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return dbValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Bean value given the DB value.
|
||||
*/
|
||||
public Object getBeanValue(T dbValue) {
|
||||
if (dbValue == null) {
|
||||
return null;
|
||||
}
|
||||
Object beanValue = valueMap.get(dbValue);
|
||||
if (beanValue == null && !allowNulls) {
|
||||
String msg = "Bean value for " + dbValue + " not found in " + valueMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return beanValue;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* Used to map Bean values to DB values.
|
||||
* <p>
|
||||
* Useful for building Enum converters where you want to map the DB values an
|
||||
* Enum gets converter to.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class EnumToDbValueMap<T> {
|
||||
|
||||
public static EnumToDbValueMap<?> create(boolean integerType) {
|
||||
return integerType ? new EnumToDbIntegerMap() : new EnumToDbStringMap();
|
||||
}
|
||||
|
||||
final LinkedHashMap<Object, T> keyMap;
|
||||
|
||||
final LinkedHashMap<T, Object> valueMap;
|
||||
|
||||
final boolean allowNulls;
|
||||
|
||||
final boolean isIntegerType;
|
||||
|
||||
/**
|
||||
* Construct with allowNulls defaulting to false.
|
||||
*/
|
||||
public EnumToDbValueMap() {
|
||||
this(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct with allowNulls setting.
|
||||
* <p>
|
||||
* If allowNulls is false then an IllegalArgumentException is thrown by
|
||||
* either the getDBValue or getBeanValue methods if not matching Bean or DB
|
||||
* value is found.
|
||||
* </p>
|
||||
*/
|
||||
public EnumToDbValueMap(boolean allowNulls, boolean isIntegerType) {
|
||||
this.allowNulls = allowNulls;
|
||||
this.isIntegerType = isIntegerType;
|
||||
keyMap = new LinkedHashMap<Object, T>();
|
||||
valueMap = new LinkedHashMap<T, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this is mapping to integers, false
|
||||
* if mapping to Strings.
|
||||
*/
|
||||
public boolean isIntegerType() {
|
||||
return isIntegerType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB values.
|
||||
*/
|
||||
public Iterator<T> dbValues() {
|
||||
return valueMap.keySet().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bean 'key' value.
|
||||
*/
|
||||
public Iterator<Object> beanValues() {
|
||||
return valueMap.values().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind using the correct database type.
|
||||
*/
|
||||
public abstract void bind(DataBind b, Object value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Read using the correct database type.
|
||||
*/
|
||||
public abstract Object read(DataReader dataReader) throws SQLException;
|
||||
|
||||
/**
|
||||
* Return the database type.
|
||||
*/
|
||||
public abstract int getDbType();
|
||||
|
||||
/**
|
||||
* Add name value pair where the dbValue is the raw string and may need to
|
||||
* be converted (to an Integer for example).
|
||||
*/
|
||||
public abstract EnumToDbValueMap<T> add(Object beanValue, String dbValue);
|
||||
|
||||
/**
|
||||
* Add a bean value and DB value pair.
|
||||
* <p>
|
||||
* The dbValue will be converted to an Integer if isIntegerType is true;
|
||||
* </p>
|
||||
*/
|
||||
protected void addInternal(Object beanValue, T dbValue) {
|
||||
|
||||
keyMap.put(beanValue, dbValue);
|
||||
valueMap.put(dbValue, beanValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB value given the bean value.
|
||||
*/
|
||||
public T getDbValue(Object beanValue) {
|
||||
if (beanValue == null) {
|
||||
return null;
|
||||
}
|
||||
T dbValue = keyMap.get(beanValue);
|
||||
if (dbValue == null && !allowNulls) {
|
||||
String msg = "DB value for " + beanValue + " not found in " + keyMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return dbValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Bean value given the DB value.
|
||||
*/
|
||||
public Object getBeanValue(T dbValue) {
|
||||
if (dbValue == null) {
|
||||
return null;
|
||||
}
|
||||
Object beanValue = valueMap.get(dbValue);
|
||||
if (beanValue == null && !allowNulls) {
|
||||
String msg = "Bean value for " + dbValue + " not found in " + valueMap;
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
return beanValue;
|
||||
}
|
||||
}
|
||||
|
||||
+98
-98
@@ -1,98 +1,98 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to build Immutable Compound Value objects.
|
||||
* <p>
|
||||
* The individual values are collected for a given type and when they have all
|
||||
* been collected then the immutable compound value object is created and
|
||||
* returned.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*
|
||||
*/
|
||||
public final class ImmutableCompoundTypeBuilder {
|
||||
|
||||
private static ThreadLocal<ImmutableCompoundTypeBuilder> local = new ThreadLocal<ImmutableCompoundTypeBuilder>() {
|
||||
protected synchronized ImmutableCompoundTypeBuilder initialValue() {
|
||||
return new ImmutableCompoundTypeBuilder();
|
||||
}
|
||||
};
|
||||
|
||||
private Map<Class<?>, Entry> entryMap = new HashMap<Class<?>, Entry>();
|
||||
|
||||
/**
|
||||
* Clear the cache of partial compound objects.
|
||||
*/
|
||||
public static void clear() {
|
||||
local.get().entryMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for the property of a compound type.
|
||||
* <p>
|
||||
* If this is the last value required for the compound type then the
|
||||
* compound type is created and returned, otherwise null is returned (and we
|
||||
* need more values set).
|
||||
* </p>
|
||||
*/
|
||||
public static Object set(CtCompoundType<?> ct, String propName, Object value) {
|
||||
return local.get().setValue(ct, propName, value);
|
||||
}
|
||||
|
||||
private Object setValue(CtCompoundType<?> ct, String propName, Object value) {
|
||||
|
||||
Entry e = getEntry(ct);
|
||||
Object compoundValue = e.set(propName, value);
|
||||
if (compoundValue != null) {
|
||||
removeEntry(ct);
|
||||
}
|
||||
return compoundValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once we have built a compound value we remove the entry.
|
||||
*/
|
||||
private void removeEntry(CtCompoundType<?> ct) {
|
||||
entryMap.remove(ct.getCompoundTypeClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entry which contains the values collected so far for this type.
|
||||
*/
|
||||
private Entry getEntry(CtCompoundType<?> ct) {
|
||||
Entry e = entryMap.get(ct.getCompoundTypeClass());
|
||||
if (e == null) {
|
||||
e = new Entry(ct);
|
||||
entryMap.put(ct.getCompoundTypeClass(), e);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the values collected so far for a given compound type.
|
||||
*/
|
||||
private static class Entry {
|
||||
|
||||
private final CtCompoundType<?> ct;
|
||||
|
||||
private final Map<String, Object> valueMap;
|
||||
|
||||
private Entry(CtCompoundType<?> ct) {
|
||||
this.ct = ct;
|
||||
this.valueMap = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
private Object set(String propName, Object value) {
|
||||
// collect the values...
|
||||
valueMap.put(propName, value);
|
||||
|
||||
// when got all the values this returns the
|
||||
// compound value, otherwise null
|
||||
return ct.create(valueMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Used to build Immutable Compound Value objects.
|
||||
* <p>
|
||||
* The individual values are collected for a given type and when they have all
|
||||
* been collected then the immutable compound value object is created and
|
||||
* returned.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*
|
||||
*/
|
||||
public final class ImmutableCompoundTypeBuilder {
|
||||
|
||||
private static ThreadLocal<ImmutableCompoundTypeBuilder> local = new ThreadLocal<ImmutableCompoundTypeBuilder>() {
|
||||
protected synchronized ImmutableCompoundTypeBuilder initialValue() {
|
||||
return new ImmutableCompoundTypeBuilder();
|
||||
}
|
||||
};
|
||||
|
||||
private Map<Class<?>, Entry> entryMap = new HashMap<Class<?>, Entry>();
|
||||
|
||||
/**
|
||||
* Clear the cache of partial compound objects.
|
||||
*/
|
||||
public static void clear() {
|
||||
local.get().entryMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value for the property of a compound type.
|
||||
* <p>
|
||||
* If this is the last value required for the compound type then the
|
||||
* compound type is created and returned, otherwise null is returned (and we
|
||||
* need more values set).
|
||||
* </p>
|
||||
*/
|
||||
public static Object set(CtCompoundType<?> ct, String propName, Object value) {
|
||||
return local.get().setValue(ct, propName, value);
|
||||
}
|
||||
|
||||
private Object setValue(CtCompoundType<?> ct, String propName, Object value) {
|
||||
|
||||
Entry e = getEntry(ct);
|
||||
Object compoundValue = e.set(propName, value);
|
||||
if (compoundValue != null) {
|
||||
removeEntry(ct);
|
||||
}
|
||||
return compoundValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Once we have built a compound value we remove the entry.
|
||||
*/
|
||||
private void removeEntry(CtCompoundType<?> ct) {
|
||||
entryMap.remove(ct.getCompoundTypeClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entry which contains the values collected so far for this type.
|
||||
*/
|
||||
private Entry getEntry(CtCompoundType<?> ct) {
|
||||
Entry e = entryMap.get(ct.getCompoundTypeClass());
|
||||
if (e == null) {
|
||||
e = new Entry(ct);
|
||||
entryMap.put(ct.getCompoundTypeClass(), e);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the values collected so far for a given compound type.
|
||||
*/
|
||||
private static class Entry {
|
||||
|
||||
private final CtCompoundType<?> ct;
|
||||
|
||||
private final Map<String, Object> valueMap;
|
||||
|
||||
private Entry(CtCompoundType<?> ct) {
|
||||
this.ct = ct;
|
||||
this.valueMap = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
private Object set(String propName, Object value) {
|
||||
// collect the values...
|
||||
valueMap.put(propName, value);
|
||||
|
||||
// when got all the values this returns the
|
||||
// compound value, otherwise null
|
||||
return ct.create(valueMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
public class LongToTimestampConverter implements ScalarTypeConverter<Long, Timestamp>{
|
||||
|
||||
public Long getNullValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Timestamp unwrapValue(Long beanType) {
|
||||
|
||||
return new Timestamp(beanType.longValue());
|
||||
}
|
||||
|
||||
public Long wrapValue(Timestamp scalarType) {
|
||||
|
||||
return scalarType.getTime();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
public class LongToTimestampConverter implements ScalarTypeConverter<Long, Timestamp>{
|
||||
|
||||
public Long getNullValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Timestamp unwrapValue(Long beanType) {
|
||||
|
||||
return new Timestamp(beanType.longValue());
|
||||
}
|
||||
|
||||
public Long wrapValue(Timestamp scalarType) {
|
||||
|
||||
return scalarType.getTime();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,121 +1,121 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Wraps a collection for the purposes of detecting modifications.
|
||||
*/
|
||||
public class ModifyAwareCollection<E> implements Collection<E> {
|
||||
|
||||
protected final ModifyAwareOwner owner;
|
||||
|
||||
protected final Collection<E> c;
|
||||
|
||||
/**
|
||||
* Create with an Owner and the underlying collection this wraps.
|
||||
* <p>
|
||||
* The owner is notified of the additions and removals.
|
||||
* </p>
|
||||
*/
|
||||
public ModifyAwareCollection(ModifyAwareOwner owner, Collection<E> c) {
|
||||
this.owner = owner;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return c.toString();
|
||||
}
|
||||
|
||||
public boolean add(E o) {
|
||||
if (c.add(o)) {
|
||||
owner.markAsModified();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(Collection<? extends E> collection) {
|
||||
boolean changed = false;
|
||||
Iterator<? extends E> it = collection.iterator();
|
||||
while (it.hasNext()) {
|
||||
E o = it.next();
|
||||
if (c.add(o)) {
|
||||
owner.markAsModified();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (!c.isEmpty()) {
|
||||
owner.markAsModified();
|
||||
}
|
||||
c.clear();
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
return c.contains(o);
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<?> collection) {
|
||||
return c.containsAll(collection);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return c.isEmpty();
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
return new ModifyAwareIterator<E>(owner, c.iterator());
|
||||
}
|
||||
|
||||
public boolean remove(Object o) {
|
||||
if (c.remove(o)) {
|
||||
owner.markAsModified();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection<?> collection) {
|
||||
boolean changed = false;
|
||||
Iterator<?> it = collection.iterator();
|
||||
while (it.hasNext()) {
|
||||
Object o = (Object) it.next();
|
||||
if (c.remove(o)) {
|
||||
owner.markAsModified();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection<?> collection) {
|
||||
boolean changed = false;
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
Object o = (Object) it.next();
|
||||
if (!collection.contains(o)) {
|
||||
it.remove();
|
||||
owner.markAsModified();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return c.size();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return c.toArray();
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return c.toArray(a);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Wraps a collection for the purposes of detecting modifications.
|
||||
*/
|
||||
public class ModifyAwareCollection<E> implements Collection<E> {
|
||||
|
||||
protected final ModifyAwareOwner owner;
|
||||
|
||||
protected final Collection<E> c;
|
||||
|
||||
/**
|
||||
* Create with an Owner and the underlying collection this wraps.
|
||||
* <p>
|
||||
* The owner is notified of the additions and removals.
|
||||
* </p>
|
||||
*/
|
||||
public ModifyAwareCollection(ModifyAwareOwner owner, Collection<E> c) {
|
||||
this.owner = owner;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return c.toString();
|
||||
}
|
||||
|
||||
public boolean add(E o) {
|
||||
if (c.add(o)) {
|
||||
owner.markAsModified();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addAll(Collection<? extends E> collection) {
|
||||
boolean changed = false;
|
||||
Iterator<? extends E> it = collection.iterator();
|
||||
while (it.hasNext()) {
|
||||
E o = it.next();
|
||||
if (c.add(o)) {
|
||||
owner.markAsModified();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
if (!c.isEmpty()) {
|
||||
owner.markAsModified();
|
||||
}
|
||||
c.clear();
|
||||
}
|
||||
|
||||
public boolean contains(Object o) {
|
||||
return c.contains(o);
|
||||
}
|
||||
|
||||
public boolean containsAll(Collection<?> collection) {
|
||||
return c.containsAll(collection);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return c.isEmpty();
|
||||
}
|
||||
|
||||
public Iterator<E> iterator() {
|
||||
return new ModifyAwareIterator<E>(owner, c.iterator());
|
||||
}
|
||||
|
||||
public boolean remove(Object o) {
|
||||
if (c.remove(o)) {
|
||||
owner.markAsModified();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeAll(Collection<?> collection) {
|
||||
boolean changed = false;
|
||||
Iterator<?> it = collection.iterator();
|
||||
while (it.hasNext()) {
|
||||
Object o = (Object) it.next();
|
||||
if (c.remove(o)) {
|
||||
owner.markAsModified();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean retainAll(Collection<?> collection) {
|
||||
boolean changed = false;
|
||||
Iterator<?> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
Object o = (Object) it.next();
|
||||
if (!collection.contains(o)) {
|
||||
it.remove();
|
||||
owner.markAsModified();
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return c.size();
|
||||
}
|
||||
|
||||
public Object[] toArray() {
|
||||
return c.toArray();
|
||||
}
|
||||
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return c.toArray(a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Wraps an iterator for the purposes of detecting modifications.
|
||||
*/
|
||||
public class ModifyAwareIterator<E> implements Iterator<E> {
|
||||
|
||||
private final ModifyAwareOwner owner;
|
||||
|
||||
private final Iterator<E> it;
|
||||
|
||||
/**
|
||||
* Create with an Owner and the underlying Iterator this wraps.
|
||||
* <p>
|
||||
* The owner is notified of the removals.
|
||||
* </p>
|
||||
*/
|
||||
public ModifyAwareIterator(ModifyAwareOwner owner, Iterator<E> it) {
|
||||
this.owner = owner;
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
public E next() {
|
||||
return it.next();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
owner.markAsModified();
|
||||
it.remove();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Wraps an iterator for the purposes of detecting modifications.
|
||||
*/
|
||||
public class ModifyAwareIterator<E> implements Iterator<E> {
|
||||
|
||||
private final ModifyAwareOwner owner;
|
||||
|
||||
private final Iterator<E> it;
|
||||
|
||||
/**
|
||||
* Create with an Owner and the underlying Iterator this wraps.
|
||||
* <p>
|
||||
* The owner is notified of the removals.
|
||||
* </p>
|
||||
*/
|
||||
public ModifyAwareIterator(ModifyAwareOwner owner, Iterator<E> it) {
|
||||
this.owner = owner;
|
||||
this.it = it;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return it.hasNext();
|
||||
}
|
||||
|
||||
public E next() {
|
||||
return it.next();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
owner.markAsModified();
|
||||
it.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wraps a Set for the purposes of detecting modifications.
|
||||
*/
|
||||
public class ModifyAwareSet<E> extends ModifyAwareCollection<E> implements Set<E> {
|
||||
|
||||
/**
|
||||
* Create with an Owner that is notified of modifications.
|
||||
*/
|
||||
public ModifyAwareSet(ModifyAwareOwner owner, Set<E> s) {
|
||||
super(owner, s);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wraps a Set for the purposes of detecting modifications.
|
||||
*/
|
||||
public class ModifyAwareSet<E> extends ModifyAwareCollection<E> implements Set<E> {
|
||||
|
||||
/**
|
||||
* Create with an Owner that is notified of modifications.
|
||||
*/
|
||||
public ModifyAwareSet(ModifyAwareOwner owner, Set<E> s) {
|
||||
super(owner, s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,243 +1,243 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Array;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Date;
|
||||
import java.sql.Ref;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.Message;
|
||||
|
||||
public class RsetDataReader implements DataReader {
|
||||
|
||||
private static final int bufferSize = 512;
|
||||
|
||||
static final int clobBufferSize = 512;
|
||||
|
||||
static final int stringInitialSize = 512;
|
||||
|
||||
private final ResultSet rset;
|
||||
|
||||
protected int pos;
|
||||
|
||||
public RsetDataReader(ResultSet rset) {
|
||||
this.rset = rset;
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
rset.close();
|
||||
}
|
||||
|
||||
public boolean next() throws SQLException {
|
||||
return rset.next();
|
||||
}
|
||||
|
||||
public void resetColumnPosition() {
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
public void incrementPos(int increment){
|
||||
pos += increment;
|
||||
}
|
||||
|
||||
protected int pos() {
|
||||
return ++pos;
|
||||
}
|
||||
|
||||
public Array getArray() throws SQLException {
|
||||
return rset.getArray(pos());
|
||||
}
|
||||
|
||||
|
||||
public InputStream getAsciiStream() throws SQLException {
|
||||
return rset.getAsciiStream(pos());
|
||||
}
|
||||
|
||||
public Object getObject() throws SQLException {
|
||||
return rset.getObject(pos());
|
||||
}
|
||||
|
||||
public BigDecimal getBigDecimal() throws SQLException {
|
||||
return rset.getBigDecimal(pos());
|
||||
}
|
||||
|
||||
|
||||
public InputStream getBinaryStream() throws SQLException {
|
||||
return rset.getBinaryStream(pos());
|
||||
}
|
||||
|
||||
public Boolean getBoolean() throws SQLException {
|
||||
boolean v = rset.getBoolean(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Boolean.valueOf(v);
|
||||
}
|
||||
|
||||
public Byte getByte() throws SQLException {
|
||||
byte v = rset.getByte(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Byte.valueOf(v);
|
||||
}
|
||||
|
||||
public byte[] getBytes() throws SQLException {
|
||||
return rset.getBytes(pos());
|
||||
}
|
||||
|
||||
public Date getDate() throws SQLException {
|
||||
return rset.getDate(pos());
|
||||
}
|
||||
|
||||
public Double getDouble() throws SQLException {
|
||||
double v = rset.getDouble(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Double.valueOf(v);
|
||||
}
|
||||
|
||||
public Float getFloat() throws SQLException {
|
||||
float v = rset.getFloat(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Float.valueOf(v);
|
||||
}
|
||||
|
||||
public Integer getInt() throws SQLException {
|
||||
int v = rset.getInt(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Integer.valueOf(v);
|
||||
}
|
||||
|
||||
|
||||
public Long getLong() throws SQLException {
|
||||
long v = rset.getLong(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Long.valueOf(v);
|
||||
}
|
||||
|
||||
|
||||
public Ref getRef() throws SQLException {
|
||||
return rset.getRef(pos());
|
||||
}
|
||||
|
||||
|
||||
public Short getShort() throws SQLException {
|
||||
short s = rset.getShort(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Short.valueOf(s);
|
||||
}
|
||||
|
||||
|
||||
public String getString() throws SQLException {
|
||||
return rset.getString(pos());
|
||||
}
|
||||
|
||||
|
||||
public Time getTime() throws SQLException {
|
||||
return rset.getTime(pos());
|
||||
}
|
||||
|
||||
|
||||
public Timestamp getTimestamp() throws SQLException {
|
||||
return rset.getTimestamp(pos());
|
||||
}
|
||||
|
||||
public String getStringFromStream() throws SQLException {
|
||||
Reader reader = rset.getCharacterStream(pos());
|
||||
if (reader == null) {
|
||||
return null;
|
||||
}
|
||||
return readStringLob(reader);
|
||||
}
|
||||
|
||||
public String getStringClob() throws SQLException {
|
||||
|
||||
Clob clob = rset.getClob(pos());
|
||||
if (clob == null) {
|
||||
return null;
|
||||
}
|
||||
Reader reader = clob.getCharacterStream();
|
||||
if (reader == null) {
|
||||
return null;
|
||||
}
|
||||
return readStringLob(reader);
|
||||
}
|
||||
|
||||
protected String readStringLob(Reader reader) throws SQLException {
|
||||
|
||||
char[] buffer = new char[clobBufferSize];
|
||||
int readLength = 0;
|
||||
StringBuilder out = new StringBuilder(stringInitialSize);
|
||||
try {
|
||||
while ((readLength = reader.read(buffer)) != -1) {
|
||||
out.append(buffer, 0, readLength);
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new SQLException(Message.msg("persist.clob.io", e.getMessage()));
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public byte[] getBinaryBytes() throws SQLException {
|
||||
InputStream in = rset.getBinaryStream(pos());
|
||||
return getBinaryLob(in);
|
||||
}
|
||||
|
||||
public byte[] getBlobBytes() throws SQLException {
|
||||
Blob blob = rset.getBlob(pos());
|
||||
if (blob == null) {
|
||||
return null;
|
||||
}
|
||||
InputStream in = blob.getBinaryStream();
|
||||
return getBinaryLob(in);
|
||||
}
|
||||
|
||||
protected byte[] getBinaryLob(InputStream in) throws SQLException {
|
||||
|
||||
try {
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buf = new byte[bufferSize];
|
||||
int len;
|
||||
while ((len = in.read(buf, 0, buf.length)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
byte[] data = out.toByteArray();
|
||||
|
||||
if (data.length == 0) {
|
||||
data = null;
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
return data;
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new SQLException(e.getClass().getName() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Array;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Date;
|
||||
import java.sql.Ref;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Time;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.Message;
|
||||
|
||||
public class RsetDataReader implements DataReader {
|
||||
|
||||
private static final int bufferSize = 512;
|
||||
|
||||
static final int clobBufferSize = 512;
|
||||
|
||||
static final int stringInitialSize = 512;
|
||||
|
||||
private final ResultSet rset;
|
||||
|
||||
protected int pos;
|
||||
|
||||
public RsetDataReader(ResultSet rset) {
|
||||
this.rset = rset;
|
||||
}
|
||||
|
||||
public void close() throws SQLException {
|
||||
rset.close();
|
||||
}
|
||||
|
||||
public boolean next() throws SQLException {
|
||||
return rset.next();
|
||||
}
|
||||
|
||||
public void resetColumnPosition() {
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
public void incrementPos(int increment){
|
||||
pos += increment;
|
||||
}
|
||||
|
||||
protected int pos() {
|
||||
return ++pos;
|
||||
}
|
||||
|
||||
public Array getArray() throws SQLException {
|
||||
return rset.getArray(pos());
|
||||
}
|
||||
|
||||
|
||||
public InputStream getAsciiStream() throws SQLException {
|
||||
return rset.getAsciiStream(pos());
|
||||
}
|
||||
|
||||
public Object getObject() throws SQLException {
|
||||
return rset.getObject(pos());
|
||||
}
|
||||
|
||||
public BigDecimal getBigDecimal() throws SQLException {
|
||||
return rset.getBigDecimal(pos());
|
||||
}
|
||||
|
||||
|
||||
public InputStream getBinaryStream() throws SQLException {
|
||||
return rset.getBinaryStream(pos());
|
||||
}
|
||||
|
||||
public Boolean getBoolean() throws SQLException {
|
||||
boolean v = rset.getBoolean(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Boolean.valueOf(v);
|
||||
}
|
||||
|
||||
public Byte getByte() throws SQLException {
|
||||
byte v = rset.getByte(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Byte.valueOf(v);
|
||||
}
|
||||
|
||||
public byte[] getBytes() throws SQLException {
|
||||
return rset.getBytes(pos());
|
||||
}
|
||||
|
||||
public Date getDate() throws SQLException {
|
||||
return rset.getDate(pos());
|
||||
}
|
||||
|
||||
public Double getDouble() throws SQLException {
|
||||
double v = rset.getDouble(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Double.valueOf(v);
|
||||
}
|
||||
|
||||
public Float getFloat() throws SQLException {
|
||||
float v = rset.getFloat(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Float.valueOf(v);
|
||||
}
|
||||
|
||||
public Integer getInt() throws SQLException {
|
||||
int v = rset.getInt(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Integer.valueOf(v);
|
||||
}
|
||||
|
||||
|
||||
public Long getLong() throws SQLException {
|
||||
long v = rset.getLong(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Long.valueOf(v);
|
||||
}
|
||||
|
||||
|
||||
public Ref getRef() throws SQLException {
|
||||
return rset.getRef(pos());
|
||||
}
|
||||
|
||||
|
||||
public Short getShort() throws SQLException {
|
||||
short s = rset.getShort(pos());
|
||||
if (rset.wasNull()){
|
||||
return null;
|
||||
}
|
||||
return Short.valueOf(s);
|
||||
}
|
||||
|
||||
|
||||
public String getString() throws SQLException {
|
||||
return rset.getString(pos());
|
||||
}
|
||||
|
||||
|
||||
public Time getTime() throws SQLException {
|
||||
return rset.getTime(pos());
|
||||
}
|
||||
|
||||
|
||||
public Timestamp getTimestamp() throws SQLException {
|
||||
return rset.getTimestamp(pos());
|
||||
}
|
||||
|
||||
public String getStringFromStream() throws SQLException {
|
||||
Reader reader = rset.getCharacterStream(pos());
|
||||
if (reader == null) {
|
||||
return null;
|
||||
}
|
||||
return readStringLob(reader);
|
||||
}
|
||||
|
||||
public String getStringClob() throws SQLException {
|
||||
|
||||
Clob clob = rset.getClob(pos());
|
||||
if (clob == null) {
|
||||
return null;
|
||||
}
|
||||
Reader reader = clob.getCharacterStream();
|
||||
if (reader == null) {
|
||||
return null;
|
||||
}
|
||||
return readStringLob(reader);
|
||||
}
|
||||
|
||||
protected String readStringLob(Reader reader) throws SQLException {
|
||||
|
||||
char[] buffer = new char[clobBufferSize];
|
||||
int readLength = 0;
|
||||
StringBuilder out = new StringBuilder(stringInitialSize);
|
||||
try {
|
||||
while ((readLength = reader.read(buffer)) != -1) {
|
||||
out.append(buffer, 0, readLength);
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new SQLException(Message.msg("persist.clob.io", e.getMessage()));
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public byte[] getBinaryBytes() throws SQLException {
|
||||
InputStream in = rset.getBinaryStream(pos());
|
||||
return getBinaryLob(in);
|
||||
}
|
||||
|
||||
public byte[] getBlobBytes() throws SQLException {
|
||||
Blob blob = rset.getBlob(pos());
|
||||
if (blob == null) {
|
||||
return null;
|
||||
}
|
||||
InputStream in = blob.getBinaryStream();
|
||||
return getBinaryLob(in);
|
||||
}
|
||||
|
||||
protected byte[] getBinaryLob(InputStream in) throws SQLException {
|
||||
|
||||
try {
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buf = new byte[bufferSize];
|
||||
int len;
|
||||
while ((len = in.read(buf, 0, buf.length)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
byte[] data = out.toByteArray();
|
||||
|
||||
if (data.length == 0) {
|
||||
data = null;
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
return data;
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new SQLException(e.getClass().getName() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class RsetDataReaderIndexed extends RsetDataReader {
|
||||
|
||||
private final int[] rsetIndexPositions;
|
||||
|
||||
public RsetDataReaderIndexed(ResultSet rset, int[] rsetIndexPositions, boolean rowNumberIncluded) {
|
||||
super(rset);
|
||||
if (!rowNumberIncluded){
|
||||
this.rsetIndexPositions = rsetIndexPositions;
|
||||
} else {
|
||||
this.rsetIndexPositions = new int[rsetIndexPositions.length+1];
|
||||
for (int i = 0; i < rsetIndexPositions.length; i++) {
|
||||
// increment all the column indexes by 1
|
||||
this.rsetIndexPositions[i+1] = rsetIndexPositions[i]+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int pos() {
|
||||
int i = pos++;
|
||||
return rsetIndexPositions[i];
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class RsetDataReaderIndexed extends RsetDataReader {
|
||||
|
||||
private final int[] rsetIndexPositions;
|
||||
|
||||
public RsetDataReaderIndexed(ResultSet rset, int[] rsetIndexPositions, boolean rowNumberIncluded) {
|
||||
super(rset);
|
||||
if (!rowNumberIncluded){
|
||||
this.rsetIndexPositions = rsetIndexPositions;
|
||||
} else {
|
||||
this.rsetIndexPositions = new int[rsetIndexPositions.length+1];
|
||||
for (int i = 0; i < rsetIndexPositions.length; i++) {
|
||||
// increment all the column indexes by 1
|
||||
this.rsetIndexPositions[i+1] = rsetIndexPositions[i]+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int pos() {
|
||||
int i = pos++;
|
||||
return rsetIndexPositions[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Reads from and binds to database columns.
|
||||
*/
|
||||
public interface ScalarDataReader<T> {
|
||||
|
||||
/**
|
||||
* Read and return the appropriate value from the dataReader.
|
||||
*/
|
||||
public T read(DataReader dataReader) throws SQLException;
|
||||
|
||||
/**
|
||||
* Ignore typically by moving the index position.
|
||||
*/
|
||||
public void loadIgnore(DataReader dataReader);
|
||||
|
||||
/**
|
||||
* Bind the value to the underlying preparedStatement.
|
||||
*/
|
||||
public void bind(DataBind b, T value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Accumulate all the scalar types used by an immutable compound value type.
|
||||
*/
|
||||
public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list);
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Reads from and binds to database columns.
|
||||
*/
|
||||
public interface ScalarDataReader<T> {
|
||||
|
||||
/**
|
||||
* Read and return the appropriate value from the dataReader.
|
||||
*/
|
||||
public T read(DataReader dataReader) throws SQLException;
|
||||
|
||||
/**
|
||||
* Ignore typically by moving the index position.
|
||||
*/
|
||||
public void loadIgnore(DataReader dataReader);
|
||||
|
||||
/**
|
||||
* Bind the value to the underlying preparedStatement.
|
||||
*/
|
||||
public void bind(DataBind b, T value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Accumulate all the scalar types used by an immutable compound value type.
|
||||
*/
|
||||
public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,207 +1,207 @@
|
||||
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.
|
||||
* <p>
|
||||
* Scalar in the sense that the types are not compound types. Scalar types only
|
||||
* map to a single database column.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that Booleans may be native for some databases and require conversion on
|
||||
* other databases.
|
||||
* </p>
|
||||
*/
|
||||
public interface ScalarType<T> extends StringParser, StringFormatter, ScalarDataReader<T> {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <p>
|
||||
* If a BeanProperty has no explicit length defined then this length should
|
||||
* be assigned.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is primarily to support defining a length on Enum types (to
|
||||
* supplement defining the length on the BeanProperty directly).
|
||||
* </p>
|
||||
*/
|
||||
public int getLength();
|
||||
|
||||
/**
|
||||
* Return true if the type is native to JDBC.
|
||||
* <p>
|
||||
* If it is native to JDBC then its values/instances do not need to be
|
||||
* converted to and from an associated JDBC type.
|
||||
* </p>
|
||||
*/
|
||||
public boolean isJdbcNative();
|
||||
|
||||
/**
|
||||
* Return the type as per java.sql.Types that this maps to.
|
||||
* <p>
|
||||
* This type should be consistent with the toJdbcType() method in converting
|
||||
* the type to the appropriate type for binding to preparedStatements.
|
||||
* </p>
|
||||
*/
|
||||
public int getJdbcType();
|
||||
|
||||
/**
|
||||
* Return the type that matches the bean property type.
|
||||
* <p>
|
||||
* This represents the 'logical' type rather than the JDBC type this maps
|
||||
* to.
|
||||
* </p>
|
||||
*/
|
||||
public Class<T> 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.
|
||||
* <p>
|
||||
* value may need to be converted from the logical bean property type to the
|
||||
* JDBC type.
|
||||
* </p>
|
||||
*/
|
||||
public void bind(DataBind b, T value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Convert the value as necessary to the JDBC type.
|
||||
* <p>
|
||||
* Note that this should also match the type as per the getJdbcType()
|
||||
* method.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
public Object toJdbcType(Object value);
|
||||
|
||||
/**
|
||||
* Convert the value as necessary to the logical Bean type.
|
||||
* <p>
|
||||
* The type as per the bean property.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is used to automatically convert id values (typically from a string
|
||||
* to a int, long or UUID).
|
||||
* </p>
|
||||
*/
|
||||
public T toBeanType(Object value);
|
||||
|
||||
/**
|
||||
* Convert the type into a string representation.
|
||||
* <p>
|
||||
* Reciprocal of parse().
|
||||
* </p>
|
||||
*/
|
||||
public String formatValue(T v);
|
||||
|
||||
/**
|
||||
* Convert the type into a string representation.
|
||||
* <p>
|
||||
* This assumes the value is of the correct type.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is so that ScalarType also implements the StringFormatter interface.
|
||||
* </p>
|
||||
*/
|
||||
public String format(Object v);
|
||||
|
||||
/**
|
||||
* Convert the string value to the appropriate java object.
|
||||
* <p>
|
||||
* Mostly used to support CSV, JSON and XML parsing.
|
||||
* </p>
|
||||
* <p>
|
||||
* Reciprocal of formatValue().
|
||||
* </p>
|
||||
*/
|
||||
public T parse(String value);
|
||||
|
||||
/**
|
||||
* Return true if the type can accept long systemTimeMillis input.
|
||||
* <p>
|
||||
* This is used to determine if is is sensible to use the
|
||||
* {@link #convertFromMillis(long)} method.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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).
|
||||
* </p>
|
||||
*/
|
||||
public boolean isDateTimeCapable();
|
||||
|
||||
/**
|
||||
* Convert the systemTimeMillis into the appropriate java object.
|
||||
* <p>
|
||||
* For non dateTime types this will throw an exception.
|
||||
* </p>
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* Scalar in the sense that the types are not compound types. Scalar types only
|
||||
* map to a single database column.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note that Booleans may be native for some databases and require conversion on
|
||||
* other databases.
|
||||
* </p>
|
||||
*/
|
||||
public interface ScalarType<T> extends StringParser, StringFormatter, ScalarDataReader<T> {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <p>
|
||||
* If a BeanProperty has no explicit length defined then this length should
|
||||
* be assigned.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is primarily to support defining a length on Enum types (to
|
||||
* supplement defining the length on the BeanProperty directly).
|
||||
* </p>
|
||||
*/
|
||||
public int getLength();
|
||||
|
||||
/**
|
||||
* Return true if the type is native to JDBC.
|
||||
* <p>
|
||||
* If it is native to JDBC then its values/instances do not need to be
|
||||
* converted to and from an associated JDBC type.
|
||||
* </p>
|
||||
*/
|
||||
public boolean isJdbcNative();
|
||||
|
||||
/**
|
||||
* Return the type as per java.sql.Types that this maps to.
|
||||
* <p>
|
||||
* This type should be consistent with the toJdbcType() method in converting
|
||||
* the type to the appropriate type for binding to preparedStatements.
|
||||
* </p>
|
||||
*/
|
||||
public int getJdbcType();
|
||||
|
||||
/**
|
||||
* Return the type that matches the bean property type.
|
||||
* <p>
|
||||
* This represents the 'logical' type rather than the JDBC type this maps
|
||||
* to.
|
||||
* </p>
|
||||
*/
|
||||
public Class<T> 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.
|
||||
* <p>
|
||||
* value may need to be converted from the logical bean property type to the
|
||||
* JDBC type.
|
||||
* </p>
|
||||
*/
|
||||
public void bind(DataBind b, T value) throws SQLException;
|
||||
|
||||
/**
|
||||
* Convert the value as necessary to the JDBC type.
|
||||
* <p>
|
||||
* Note that this should also match the type as per the getJdbcType()
|
||||
* method.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
public Object toJdbcType(Object value);
|
||||
|
||||
/**
|
||||
* Convert the value as necessary to the logical Bean type.
|
||||
* <p>
|
||||
* The type as per the bean property.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is used to automatically convert id values (typically from a string
|
||||
* to a int, long or UUID).
|
||||
* </p>
|
||||
*/
|
||||
public T toBeanType(Object value);
|
||||
|
||||
/**
|
||||
* Convert the type into a string representation.
|
||||
* <p>
|
||||
* Reciprocal of parse().
|
||||
* </p>
|
||||
*/
|
||||
public String formatValue(T v);
|
||||
|
||||
/**
|
||||
* Convert the type into a string representation.
|
||||
* <p>
|
||||
* This assumes the value is of the correct type.
|
||||
* </p>
|
||||
* <p>
|
||||
* This is so that ScalarType also implements the StringFormatter interface.
|
||||
* </p>
|
||||
*/
|
||||
public String format(Object v);
|
||||
|
||||
/**
|
||||
* Convert the string value to the appropriate java object.
|
||||
* <p>
|
||||
* Mostly used to support CSV, JSON and XML parsing.
|
||||
* </p>
|
||||
* <p>
|
||||
* Reciprocal of formatValue().
|
||||
* </p>
|
||||
*/
|
||||
public T parse(String value);
|
||||
|
||||
/**
|
||||
* Return true if the type can accept long systemTimeMillis input.
|
||||
* <p>
|
||||
* This is used to determine if is is sensible to use the
|
||||
* {@link #convertFromMillis(long)} method.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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).
|
||||
* </p>
|
||||
*/
|
||||
public boolean isDateTimeCapable();
|
||||
|
||||
/**
|
||||
* Convert the systemTimeMillis into the appropriate java object.
|
||||
* <p>
|
||||
* For non dateTime types this will throw an exception.
|
||||
* </p>
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
/**
|
||||
* Base ScalarType object.
|
||||
*/
|
||||
public abstract class ScalarTypeBase<T> implements ScalarType<T> {
|
||||
|
||||
protected final Class<T> type;
|
||||
|
||||
protected final boolean jdbcNative;
|
||||
|
||||
protected final int jdbcType;
|
||||
|
||||
public ScalarTypeBase(Class<T> 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<T> 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<T> implements ScalarType<T> {
|
||||
|
||||
protected final Class<T> type;
|
||||
|
||||
protected final boolean jdbcNative;
|
||||
|
||||
protected final int jdbcType;
|
||||
|
||||
public ScalarTypeBase(Class<T> 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<T> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<T> extends ScalarTypeBase<T> {
|
||||
|
||||
public ScalarTypeBaseDate(Class<T> 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<T> extends ScalarTypeBase<T> {
|
||||
|
||||
public ScalarTypeBaseDate(Class<T> 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<T> extends ScalarTypeBase<T> {
|
||||
|
||||
|
||||
protected final DateTimeJsonParser dateTimeParser = new DateTimeJsonParser();
|
||||
|
||||
protected final JsonConfig.DateTime mode;
|
||||
|
||||
public ScalarTypeBaseDateTime(JsonConfig.DateTime mode, Class<T> 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<T> extends ScalarTypeBase<T> {
|
||||
|
||||
|
||||
protected final DateTimeJsonParser dateTimeParser = new DateTimeJsonParser();
|
||||
|
||||
protected final JsonConfig.DateTime mode;
|
||||
|
||||
public ScalarTypeBaseDateTime(JsonConfig.DateTime mode, Class<T> 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<T> extends ScalarTypeBase<T> {
|
||||
|
||||
public ScalarTypeBaseVarchar(Class<T> type) {
|
||||
super(type, false, Types.VARCHAR);
|
||||
}
|
||||
|
||||
public ScalarTypeBaseVarchar(Class<T> 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<T> extends ScalarTypeBase<T> {
|
||||
|
||||
public ScalarTypeBaseVarchar(Class<T> type) {
|
||||
super(type, false, Types.VARCHAR);
|
||||
}
|
||||
|
||||
public ScalarTypeBaseVarchar(Class<T> 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BigDecimal> {
|
||||
|
||||
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<BigDecimal> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* This may or may not be a native jdbc type depending on the database and jdbc driver.
|
||||
* </p>
|
||||
*/
|
||||
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
|
||||
*
|
||||
* <p>
|
||||
* Sometimes booleans may be mapped to the JDBC type BIT. To use the BitBoolean specify
|
||||
* type.boolean.dbtype="bit" in the ebean configuration
|
||||
* </p>
|
||||
*/
|
||||
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<Boolean> {
|
||||
|
||||
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.
|
||||
* <p>
|
||||
* This may or may not be a native jdbc type depending on the database and jdbc driver.
|
||||
* </p>
|
||||
*/
|
||||
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
|
||||
*
|
||||
* <p>
|
||||
* Sometimes booleans may be mapped to the JDBC type BIT. To use the BitBoolean specify
|
||||
* type.boolean.dbtype="bit" in the ebean configuration
|
||||
* </p>
|
||||
*/
|
||||
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<Boolean> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Byte> {
|
||||
|
||||
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<Byte> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<byte[]> {
|
||||
|
||||
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<byte[]> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<byte[]> {
|
||||
|
||||
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<byte[]> 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<byte[]> {
|
||||
|
||||
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<byte[]> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+18
-18
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Calendar> {
|
||||
|
||||
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<Calendar> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Character> {
|
||||
|
||||
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<Character> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<char[]> {
|
||||
|
||||
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<char[]> {
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Class> {
|
||||
|
||||
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<Class> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<String> {
|
||||
|
||||
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<String> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Currency> {
|
||||
|
||||
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<Currency> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<java.sql.Date> {
|
||||
|
||||
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<java.sql.Date> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Double> {
|
||||
|
||||
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<Double> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Duration> {
|
||||
|
||||
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<Duration> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
+55
-55
@@ -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).
|
||||
* <p>
|
||||
* Stored in the DB as DECIMAL value.
|
||||
* </p>
|
||||
*/
|
||||
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).
|
||||
* <p>
|
||||
* Stored in the DB as DECIMAL value.
|
||||
* </p>
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+144
-144
@@ -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<T> implements ScalarType<T> {
|
||||
|
||||
private final ScalarType<T> wrapped;
|
||||
|
||||
private final DataEncryptSupport dataEncryptSupport;
|
||||
|
||||
private final ScalarTypeBytesBase byteArrayType;
|
||||
|
||||
public ScalarTypeEncryptedWrapper(ScalarType<T> 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<T> 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<T> implements ScalarType<T> {
|
||||
|
||||
private final ScalarType<T> wrapped;
|
||||
|
||||
private final DataEncryptSupport dataEncryptSupport;
|
||||
|
||||
private final ScalarTypeBytesBase byteArrayType;
|
||||
|
||||
public ScalarTypeEncryptedWrapper(ScalarType<T> 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<T> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* Converts between bean Enum types to database string or integer columns.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* Converts between bean Enum types to database string or integer columns.
|
||||
* </p>
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* This is for enum's mapped to strings.
|
||||
* </p>
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* This is for enum's mapped to strings.
|
||||
* </p>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<File> {
|
||||
|
||||
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<File> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Float> {
|
||||
|
||||
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<Float> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<InetAddress> {
|
||||
|
||||
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<InetAddress> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Instant> {
|
||||
|
||||
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<Instant> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Integer> {
|
||||
|
||||
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<Integer> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<DateMidnight> {
|
||||
|
||||
/**
|
||||
* 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<DateMidnight> {
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<DateTime> {
|
||||
|
||||
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<DateTime> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<LocalDate> {
|
||||
|
||||
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<LocalDate> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+67
-67
@@ -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<LocalDateTime> {
|
||||
|
||||
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<LocalDateTime> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<LocalTime> {
|
||||
|
||||
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<LocalTime> {
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<LocalDate> {
|
||||
|
||||
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<LocalDate> {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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<LocalDateTime> {
|
||||
|
||||
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<LocalDateTime> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<LocalTime> {
|
||||
|
||||
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<LocalTime> {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
+45
-45
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Locale> {
|
||||
|
||||
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<Locale> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Long> {
|
||||
|
||||
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<Long> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ScalarTypeLongToTimestamp extends ScalarTypeWrapper<Long, Timestamp> {
|
||||
|
||||
public ScalarTypeLongToTimestamp(JsonConfig.DateTime mode) {
|
||||
super(Long.class, new ScalarTypeTimestamp(mode), new LongToTimestampConverter());
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class ScalarTypeLongToTimestamp extends ScalarTypeWrapper<Long, Timestamp> {
|
||||
|
||||
public ScalarTypeLongToTimestamp(JsonConfig.DateTime mode) {
|
||||
super(Long.class, new ScalarTypeTimestamp(mode), new LongToTimestampConverter());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* ScalarType for String.
|
||||
*/
|
||||
public class ScalarTypeLongVarchar extends ScalarTypeClob {
|
||||
|
||||
public ScalarTypeLongVarchar() {
|
||||
super(true, Types.LONGVARCHAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getStringFromStream();
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* ScalarType for String.
|
||||
*/
|
||||
public class ScalarTypeLongVarchar extends ScalarTypeClob {
|
||||
|
||||
public ScalarTypeLongVarchar() {
|
||||
super(true, Types.LONGVARCHAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getStringFromStream();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,106 +1,106 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
|
||||
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 java.math.BigInteger.
|
||||
*/
|
||||
public class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
|
||||
|
||||
public ScalarTypeMathBigInteger() {
|
||||
super(BigInteger.class, false, Types.BIGINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, BigInteger value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.BIGINT);
|
||||
} else {
|
||||
b.setLong(value.longValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger read(DataReader dataReader) throws SQLException {
|
||||
|
||||
Long l = dataReader.getLong();
|
||||
if (l == null) {
|
||||
return null;
|
||||
}
|
||||
return new BigInteger(String.valueOf(l));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger toBeanType(Object value) {
|
||||
return BasicTypeConverter.toMathBigInteger(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(BigInteger v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger parse(String value) {
|
||||
return new BigInteger(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger convertFromMillis(long systemTimeMillis) {
|
||||
return BigInteger.valueOf(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
long val = dataInput.readLong();
|
||||
return BigInteger.valueOf(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, BigInteger value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeLong(value.longValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getDecimalValue().toBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, BigInteger value) throws IOException {
|
||||
ctx.writeNumberField(name, ((BigInteger) value).longValue());
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
|
||||
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 java.math.BigInteger.
|
||||
*/
|
||||
public class ScalarTypeMathBigInteger extends ScalarTypeBase<BigInteger> {
|
||||
|
||||
public ScalarTypeMathBigInteger() {
|
||||
super(BigInteger.class, false, Types.BIGINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, BigInteger value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.BIGINT);
|
||||
} else {
|
||||
b.setLong(value.longValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger read(DataReader dataReader) throws SQLException {
|
||||
|
||||
Long l = dataReader.getLong();
|
||||
if (l == null) {
|
||||
return null;
|
||||
}
|
||||
return new BigInteger(String.valueOf(l));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toLong(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger toBeanType(Object value) {
|
||||
return BasicTypeConverter.toMathBigInteger(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(BigInteger v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger parse(String value) {
|
||||
return new BigInteger(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger convertFromMillis(long systemTimeMillis) {
|
||||
return BigInteger.valueOf(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
long val = dataInput.readLong();
|
||||
return BigInteger.valueOf(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, BigInteger value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeLong(value.longValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getDecimalValue().toBigInteger();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, BigInteger value) throws IOException {
|
||||
ctx.writeNumberField(name, ((BigInteger) value).longValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
/**
|
||||
* ScalarType for java.sql.Timestamp.
|
||||
*/
|
||||
public class ScalarTypeOffsetDateTime extends ScalarTypeBaseDateTime<OffsetDateTime> {
|
||||
|
||||
public ScalarTypeOffsetDateTime(JsonConfig.DateTime mode) {
|
||||
super(mode, OffsetDateTime.class, true, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(OffsetDateTime value) {
|
||||
return toJsonNanos(value.toEpochSecond(), value.getNano());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(OffsetDateTime value) {
|
||||
return value.toInstant().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(OffsetDateTime value) {
|
||||
return value.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime convertFromMillis(long systemTimeMillis) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(systemTimeMillis), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime convertFromTimestamp(Timestamp ts) {
|
||||
return OffsetDateTime.ofInstant(ts.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(OffsetDateTime t) {
|
||||
return Timestamp.from(t.toInstant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Timestamp) return value;
|
||||
return convertToTimestamp((OffsetDateTime)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime toBeanType(Object value) {
|
||||
if (value instanceof OffsetDateTime) return (OffsetDateTime) 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;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
/**
|
||||
* ScalarType for java.sql.Timestamp.
|
||||
*/
|
||||
public class ScalarTypeOffsetDateTime extends ScalarTypeBaseDateTime<OffsetDateTime> {
|
||||
|
||||
public ScalarTypeOffsetDateTime(JsonConfig.DateTime mode) {
|
||||
super(mode, OffsetDateTime.class, true, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(OffsetDateTime value) {
|
||||
return toJsonNanos(value.toEpochSecond(), value.getNano());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(OffsetDateTime value) {
|
||||
return value.toInstant().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(OffsetDateTime value) {
|
||||
return value.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime convertFromMillis(long systemTimeMillis) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(systemTimeMillis), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime convertFromTimestamp(Timestamp ts) {
|
||||
return OffsetDateTime.ofInstant(ts.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(OffsetDateTime t) {
|
||||
return Timestamp.from(t.toInstant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Timestamp) return value;
|
||||
return convertToTimestamp((OffsetDateTime)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetDateTime toBeanType(Object value) {
|
||||
if (value instanceof OffsetDateTime) return (OffsetDateTime) value;
|
||||
return convertFromTimestamp((Timestamp)value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.time.OffsetTime;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypeOffsetTime extends ScalarTypeBaseVarchar<OffsetTime> {
|
||||
|
||||
public ScalarTypeOffsetTime() {
|
||||
super(OffsetTime.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(OffsetTime v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetTime parse(String value) {
|
||||
return OffsetTime.parse(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetTime convertFromDbString(String dbValue) {
|
||||
return OffsetTime.parse(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(OffsetTime beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.time.OffsetTime;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypeOffsetTime extends ScalarTypeBaseVarchar<OffsetTime> {
|
||||
|
||||
public ScalarTypeOffsetTime() {
|
||||
super(OffsetTime.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 25;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(OffsetTime v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetTime parse(String value) {
|
||||
return OffsetTime.parse(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OffsetTime convertFromDbString(String dbValue) {
|
||||
return OffsetTime.parse(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(OffsetTime beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.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 Short and short.
|
||||
*/
|
||||
public class ScalarTypeShort extends ScalarTypeBase<Short> {
|
||||
|
||||
public ScalarTypeShort() {
|
||||
super(Short.class, true, Types.SMALLINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, Short value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.SMALLINT);
|
||||
} else {
|
||||
b.setShort(value.shortValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short toBeanType(Object value) {
|
||||
return BasicTypeConverter.toShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Short v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short parse(String value) {
|
||||
return Short.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short convertFromMillis(long systemTimeMillis) {
|
||||
throw new TextException("Not Supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
return dataInput.readShort();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, Short value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeShort(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getShortValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Short value) throws IOException {
|
||||
ctx.writeNumberField(name, (Short) 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 Short and short.
|
||||
*/
|
||||
public class ScalarTypeShort extends ScalarTypeBase<Short> {
|
||||
|
||||
public ScalarTypeShort() {
|
||||
super(Short.class, true, Types.SMALLINT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, Short value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.SMALLINT);
|
||||
} else {
|
||||
b.setShort(value.shortValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short toBeanType(Object value) {
|
||||
return BasicTypeConverter.toShort(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Short v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short parse(String value) {
|
||||
return Short.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short convertFromMillis(long systemTimeMillis) {
|
||||
throw new TextException("Not Supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
return dataInput.readShort();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, Short value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeShort(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Short jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getShortValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Short value) throws IOException {
|
||||
ctx.writeNumberField(name, (Short) value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 String.
|
||||
*/
|
||||
public class ScalarTypeString extends ScalarTypeBase<String> {
|
||||
|
||||
public ScalarTypeString() {
|
||||
super(String.class, true, Types.VARCHAR);
|
||||
}
|
||||
|
||||
@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.getString();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertFromMillis(long systemTimeMillis) {
|
||||
return String.valueOf(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
return dataInput.readUTF();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, String value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeUTF(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getValueAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, String value) throws IOException {
|
||||
ctx.writeStringField(name, (String) 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 String.
|
||||
*/
|
||||
public class ScalarTypeString extends ScalarTypeBase<String> {
|
||||
|
||||
public ScalarTypeString() {
|
||||
super(String.class, true, Types.VARCHAR);
|
||||
}
|
||||
|
||||
@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.getString();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertFromMillis(long systemTimeMillis) {
|
||||
return String.valueOf(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
return dataInput.readUTF();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, String value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeUTF(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return ctx.getValueAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, String value) throws IOException {
|
||||
ctx.writeStringField(name, (String) value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,99 +1,99 @@
|
||||
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 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 java.sql.Time.
|
||||
*/
|
||||
public class ScalarTypeTime extends ScalarTypeBase<Time> {
|
||||
|
||||
public ScalarTypeTime() {
|
||||
super(Time.class, true, Types.TIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, Time value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.TIME);
|
||||
} else {
|
||||
b.setTime(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toTime(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time toBeanType(Object value) {
|
||||
return BasicTypeConverter.toTime(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Time v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time parse(String value) {
|
||||
return Time.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time convertFromMillis(long systemTimeMillis) {
|
||||
return new Time(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
String val = dataInput.readUTF();
|
||||
return parse(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, Time value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeUTF(format(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return parse(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Time 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.Time;
|
||||
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 java.sql.Time.
|
||||
*/
|
||||
public class ScalarTypeTime extends ScalarTypeBase<Time> {
|
||||
|
||||
public ScalarTypeTime() {
|
||||
super(Time.class, true, Types.TIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, Time value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.TIME);
|
||||
} else {
|
||||
b.setTime(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toTime(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time toBeanType(Object value) {
|
||||
return BasicTypeConverter.toTime(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Time v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time parse(String value) {
|
||||
return Time.valueOf(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time convertFromMillis(long systemTimeMillis) {
|
||||
return new Time(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
String val = dataInput.readUTF();
|
||||
return parse(val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, Time value) throws IOException {
|
||||
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeUTF(format(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Time jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return parse(ctx.getValueAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Time value) throws IOException {
|
||||
ctx.writeStringField(name, format(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.TimeZone which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeTimeZone extends ScalarTypeBaseVarchar<TimeZone> {
|
||||
|
||||
public ScalarTypeTimeZone() {
|
||||
super(TimeZone.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone convertFromDbString(String dbValue) {
|
||||
return TimeZone.getTimeZone(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(TimeZone beanValue) {
|
||||
return ((TimeZone) beanValue).getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(TimeZone v) {
|
||||
return v.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone parse(String value) {
|
||||
return TimeZone.getTimeZone(value);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.TimeZone which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeTimeZone extends ScalarTypeBaseVarchar<TimeZone> {
|
||||
|
||||
public ScalarTypeTimeZone() {
|
||||
super(TimeZone.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone convertFromDbString(String dbValue) {
|
||||
return TimeZone.getTimeZone(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(TimeZone beanValue) {
|
||||
return ((TimeZone) beanValue).getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(TimeZone v) {
|
||||
return v.getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimeZone parse(String value) {
|
||||
return TimeZone.getTimeZone(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.sql.Timestamp.
|
||||
*/
|
||||
public class ScalarTypeTimestamp extends ScalarTypeBaseDateTime<Timestamp> {
|
||||
|
||||
public ScalarTypeTimestamp(JsonConfig.DateTime mode) {
|
||||
super(mode, Timestamp.class, true, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(Timestamp value) {
|
||||
return String.valueOf(value.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(Timestamp value) {
|
||||
return dateTimeParser.format(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(Timestamp value) {
|
||||
return value.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertFromMillis(long systemTimeMillis) {
|
||||
return new Timestamp(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertFromTimestamp(Timestamp ts) {
|
||||
return ts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(Timestamp t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, Timestamp value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.TIMESTAMP);
|
||||
} else {
|
||||
b.setTimestamp(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toTimestamp(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp toBeanType(Object value) {
|
||||
return BasicTypeConverter.toTimestamp(value);
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.sql.Timestamp.
|
||||
*/
|
||||
public class ScalarTypeTimestamp extends ScalarTypeBaseDateTime<Timestamp> {
|
||||
|
||||
public ScalarTypeTimestamp(JsonConfig.DateTime mode) {
|
||||
super(mode, Timestamp.class, true, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(Timestamp value) {
|
||||
return String.valueOf(value.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(Timestamp value) {
|
||||
return dateTimeParser.format(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(Timestamp value) {
|
||||
return value.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertFromMillis(long systemTimeMillis) {
|
||||
return new Timestamp(systemTimeMillis);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertFromTimestamp(Timestamp ts) {
|
||||
return ts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(Timestamp t) {
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, Timestamp value) throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.TIMESTAMP);
|
||||
} else {
|
||||
b.setTimestamp(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp read(DataReader dataReader) throws SQLException {
|
||||
return dataReader.getTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toTimestamp(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp toBeanType(Object value) {
|
||||
return BasicTypeConverter.toTimestamp(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
|
||||
/**
|
||||
* ScalarType for java.net.URI which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeURI extends ScalarTypeBaseVarchar<URI> {
|
||||
|
||||
public ScalarTypeURI() {
|
||||
super(URI.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI convertFromDbString(String dbValue) {
|
||||
try {
|
||||
return new URI(dbValue);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException("Error with URI [" + dbValue + "] " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(URI beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(URI v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI parse(String value) {
|
||||
try {
|
||||
return new URI(value);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new TextException("Error with URI [" + value + "] ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
|
||||
/**
|
||||
* ScalarType for java.net.URI which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeURI extends ScalarTypeBaseVarchar<URI> {
|
||||
|
||||
public ScalarTypeURI() {
|
||||
super(URI.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI convertFromDbString(String dbValue) {
|
||||
try {
|
||||
return new URI(dbValue);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException("Error with URI [" + dbValue + "] " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(URI beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(URI v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI parse(String value) {
|
||||
try {
|
||||
return new URI(value);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new TextException("Error with URI [" + value + "] ", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
|
||||
/**
|
||||
* ScalarType for java.net.URL which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeURL extends ScalarTypeBaseVarchar<URL> {
|
||||
|
||||
public ScalarTypeURL() {
|
||||
super(URL.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL convertFromDbString(String dbValue) {
|
||||
try {
|
||||
return new URL(dbValue);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException("Error with URL [" + dbValue + "] " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(URL beanValue) {
|
||||
return formatValue(beanValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(URL v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL parse(String value) {
|
||||
try {
|
||||
return new URL(value);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new TextException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
|
||||
/**
|
||||
* ScalarType for java.net.URL which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeURL extends ScalarTypeBaseVarchar<URL> {
|
||||
|
||||
public ScalarTypeURL() {
|
||||
super(URL.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL convertFromDbString(String dbValue) {
|
||||
try {
|
||||
return new URL(dbValue);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException("Error with URL [" + dbValue + "] " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(URL beanValue) {
|
||||
return formatValue(beanValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(URL v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL parse(String value) {
|
||||
try {
|
||||
return new URL(value);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new TextException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.UUID which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeUUIDVarchar extends ScalarTypeBaseVarchar<UUID> {
|
||||
|
||||
public ScalarTypeUUIDVarchar() {
|
||||
super(UUID.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID convertFromDbString(String dbValue) {
|
||||
return UUID.fromString(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(UUID beanValue) {
|
||||
return formatValue(beanValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUUID(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.convert(value, jdbcType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(UUID v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID parse(String value) {
|
||||
return UUID.fromString(value);
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.UUID which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
public class ScalarTypeUUIDVarchar extends ScalarTypeBaseVarchar<UUID> {
|
||||
|
||||
public ScalarTypeUUIDVarchar() {
|
||||
super(UUID.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID convertFromDbString(String dbValue) {
|
||||
return UUID.fromString(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(UUID beanValue) {
|
||||
return formatValue(beanValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUUID(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.convert(value, jdbcType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(UUID v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID parse(String value) {
|
||||
return UUID.fromString(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,118 +1,118 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.util.Date;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.Date.
|
||||
*/
|
||||
public class ScalarTypeUtilDate {
|
||||
|
||||
public static class TimestampType extends ScalarTypeBaseDateTime<java.util.Date> {
|
||||
|
||||
public TimestampType(JsonConfig.DateTime mode) {
|
||||
super(mode, java.util.Date.class, false, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(Date value) {
|
||||
return String.valueOf(value.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(Date value) {
|
||||
return dateTimeParser.format(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(Date value) {
|
||||
return value.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date read(DataReader dataReader) throws SQLException {
|
||||
Timestamp timestamp = dataReader.getTimestamp();
|
||||
if (timestamp == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new java.util.Date(timestamp.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, java.util.Date value)
|
||||
throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.TIMESTAMP);
|
||||
} else {
|
||||
|
||||
Timestamp timestamp = new Timestamp(value.getTime());
|
||||
b.setTimestamp(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toTimestamp(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUtilDate(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Date convertFromTimestamp(Timestamp ts) {
|
||||
return new java.util.Date(ts.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(Date t) {
|
||||
return new Timestamp(t.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date convertFromMillis(long systemTimeMillis) {
|
||||
return new java.util.Date(systemTimeMillis);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DateType extends ScalarTypeBaseDate<java.util.Date> {
|
||||
|
||||
public DateType() {
|
||||
super(Date.class, false, Types.DATE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long convertToMillis(java.util.Date value) {
|
||||
return value.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date convertFromDate(java.sql.Date ts) {
|
||||
return new java.util.Date(ts.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.sql.Date convertToDate(Date t) {
|
||||
return new java.sql.Date(t.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toDate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUtilDate(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.util.Date;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.util.Date.
|
||||
*/
|
||||
public class ScalarTypeUtilDate {
|
||||
|
||||
public static class TimestampType extends ScalarTypeBaseDateTime<java.util.Date> {
|
||||
|
||||
public TimestampType(JsonConfig.DateTime mode) {
|
||||
super(mode, java.util.Date.class, false, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(Date value) {
|
||||
return String.valueOf(value.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(Date value) {
|
||||
return dateTimeParser.format(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(Date value) {
|
||||
return value.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date read(DataReader dataReader) throws SQLException {
|
||||
Timestamp timestamp = dataReader.getTimestamp();
|
||||
if (timestamp == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new java.util.Date(timestamp.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, java.util.Date value)
|
||||
throws SQLException {
|
||||
if (value == null) {
|
||||
b.setNull(Types.TIMESTAMP);
|
||||
} else {
|
||||
|
||||
Timestamp timestamp = new Timestamp(value.getTime());
|
||||
b.setTimestamp(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toTimestamp(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUtilDate(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Date convertFromTimestamp(Timestamp ts) {
|
||||
return new java.util.Date(ts.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(Date t) {
|
||||
return new Timestamp(t.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date convertFromMillis(long systemTimeMillis) {
|
||||
return new java.util.Date(systemTimeMillis);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DateType extends ScalarTypeBaseDate<java.util.Date> {
|
||||
|
||||
public DateType() {
|
||||
super(Date.class, false, Types.DATE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long convertToMillis(java.util.Date value) {
|
||||
return value.getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date convertFromDate(java.sql.Date ts) {
|
||||
return new java.util.Date(ts.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.sql.Date convertToDate(Date t) {
|
||||
return new java.sql.Date(t.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.toDate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.Date toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUtilDate(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,200 +1,200 @@
|
||||
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.config.ScalarTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* A ScalarType that uses a ScalarTypeConverter to convert to and from another underlying
|
||||
* ScalarType.
|
||||
* <p>
|
||||
* Enables the use of a simple interface to add additional scalarTypes.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*
|
||||
* @param <B>
|
||||
* the logical type
|
||||
* @param <S>
|
||||
* the underlying scalar type this is converted to
|
||||
*/
|
||||
public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
|
||||
|
||||
private final ScalarType<S> scalarType;
|
||||
|
||||
private final ScalarTypeConverter<B, S> converter;
|
||||
|
||||
private final Class<B> wrapperType;
|
||||
|
||||
private final B nullValue;
|
||||
|
||||
public ScalarTypeWrapper(Class<B> wrapperType, ScalarType<S> scalarType, ScalarTypeConverter<B, S> converter) {
|
||||
this.scalarType = scalarType;
|
||||
this.converter = converter;
|
||||
this.nullValue = converter.getNullValue();
|
||||
this.wrapperType = wrapperType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ScalarTypeWrapper " + wrapperType + " to " + scalarType.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return scalarType.isMutable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty(Object value) {
|
||||
return scalarType.isDirty(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public B readData(DataInput dataInput) throws IOException {
|
||||
S unwrapValue = scalarType.readData(dataInput);
|
||||
return converter.wrapValue(unwrapValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeData(DataOutput dataOutput, B value) throws IOException {
|
||||
S unwrapValue = converter.unwrapValue(value);
|
||||
scalarType.writeData(dataOutput, unwrapValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, B value) throws SQLException {
|
||||
if (value == null) {
|
||||
scalarType.bind(b, null);
|
||||
} else {
|
||||
S sv = converter.unwrapValue(value);
|
||||
scalarType.bind(b, sv);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getJdbcType() {
|
||||
return scalarType.getJdbcType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return scalarType.getLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<B> getType() {
|
||||
return wrapperType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return scalarType.isDateTimeCapable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJdbcNative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String format(Object v) {
|
||||
return formatValue((B) v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(B v) {
|
||||
S sv = converter.unwrapValue(v);
|
||||
return scalarType.formatValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public B parse(String value) {
|
||||
S sv = scalarType.parse(value);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public B convertFromMillis(long systemTimeMillis) {
|
||||
S sv = scalarType.convertFromMillis(systemTimeMillis);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIgnore(DataReader dataReader) {
|
||||
dataReader.incrementPos(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public B read(DataReader dataReader) throws SQLException {
|
||||
|
||||
S sv = scalarType.read(dataReader);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public B toBeanType(Object value) {
|
||||
if (value == null) {
|
||||
return nullValue;
|
||||
}
|
||||
if (getType().isAssignableFrom(value.getClass())) {
|
||||
return (B) value;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return parse((String) value);
|
||||
}
|
||||
S sv = scalarType.toBeanType(value);
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object toJdbcType(Object value) {
|
||||
|
||||
Object sv = converter.unwrapValue((B) value);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return scalarType.toJdbcType(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
|
||||
list.addScalarType(propName, this);
|
||||
}
|
||||
|
||||
public ScalarType<?> getScalarType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public B jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
S object = scalarType.jsonRead(ctx, event);
|
||||
return converter.wrapValue(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, B beanValue) throws IOException {
|
||||
S unwrapValue = converter.unwrapValue(beanValue);
|
||||
scalarType.jsonWrite(ctx, name, unwrapValue);
|
||||
}
|
||||
|
||||
}
|
||||
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.config.ScalarTypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
/**
|
||||
* A ScalarType that uses a ScalarTypeConverter to convert to and from another underlying
|
||||
* ScalarType.
|
||||
* <p>
|
||||
* Enables the use of a simple interface to add additional scalarTypes.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*
|
||||
* @param <B>
|
||||
* the logical type
|
||||
* @param <S>
|
||||
* the underlying scalar type this is converted to
|
||||
*/
|
||||
public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
|
||||
|
||||
private final ScalarType<S> scalarType;
|
||||
|
||||
private final ScalarTypeConverter<B, S> converter;
|
||||
|
||||
private final Class<B> wrapperType;
|
||||
|
||||
private final B nullValue;
|
||||
|
||||
public ScalarTypeWrapper(Class<B> wrapperType, ScalarType<S> scalarType, ScalarTypeConverter<B, S> converter) {
|
||||
this.scalarType = scalarType;
|
||||
this.converter = converter;
|
||||
this.nullValue = converter.getNullValue();
|
||||
this.wrapperType = wrapperType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ScalarTypeWrapper " + wrapperType + " to " + scalarType.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return scalarType.isMutable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty(Object value) {
|
||||
return scalarType.isDirty(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public B readData(DataInput dataInput) throws IOException {
|
||||
S unwrapValue = scalarType.readData(dataInput);
|
||||
return converter.wrapValue(unwrapValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void writeData(DataOutput dataOutput, B value) throws IOException {
|
||||
S unwrapValue = converter.unwrapValue(value);
|
||||
scalarType.writeData(dataOutput, unwrapValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, B value) throws SQLException {
|
||||
if (value == null) {
|
||||
scalarType.bind(b, null);
|
||||
} else {
|
||||
S sv = converter.unwrapValue(value);
|
||||
scalarType.bind(b, sv);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getJdbcType() {
|
||||
return scalarType.getJdbcType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return scalarType.getLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<B> getType() {
|
||||
return wrapperType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return scalarType.isDateTimeCapable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJdbcNative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String format(Object v) {
|
||||
return formatValue((B) v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(B v) {
|
||||
S sv = converter.unwrapValue(v);
|
||||
return scalarType.formatValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public B parse(String value) {
|
||||
S sv = scalarType.parse(value);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public B convertFromMillis(long systemTimeMillis) {
|
||||
S sv = scalarType.convertFromMillis(systemTimeMillis);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadIgnore(DataReader dataReader) {
|
||||
dataReader.incrementPos(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public B read(DataReader dataReader) throws SQLException {
|
||||
|
||||
S sv = scalarType.read(dataReader);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public B toBeanType(Object value) {
|
||||
if (value == null) {
|
||||
return nullValue;
|
||||
}
|
||||
if (getType().isAssignableFrom(value.getClass())) {
|
||||
return (B) value;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return parse((String) value);
|
||||
}
|
||||
S sv = scalarType.toBeanType(value);
|
||||
return converter.wrapValue(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object toJdbcType(Object value) {
|
||||
|
||||
Object sv = converter.unwrapValue((B) value);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return scalarType.toJdbcType(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list) {
|
||||
list.addScalarType(propName, this);
|
||||
}
|
||||
|
||||
public ScalarType<?> getScalarType() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public B jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
S object = scalarType.jsonRead(ctx, event);
|
||||
return converter.wrapValue(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, B beanValue) throws IOException {
|
||||
S unwrapValue = converter.unwrapValue(beanValue);
|
||||
scalarType.jsonWrite(ctx, name, unwrapValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,100 +1,100 @@
|
||||
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.Types;
|
||||
import java.time.Year;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.Year
|
||||
*/
|
||||
public class ScalarTypeYear extends ScalarTypeBase<Year> {
|
||||
|
||||
public ScalarTypeYear() {
|
||||
super(Year.class, true, Types.INTEGER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind bind, Year value) throws SQLException {
|
||||
if (value == null) {
|
||||
bind.setNull(Types.INTEGER);
|
||||
} else {
|
||||
bind.setInt(value.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year read(DataReader dataReader) throws SQLException {
|
||||
Integer value = dataReader.getInt();
|
||||
return (value == null) ? null : Year.of(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
return Year.of(dataInput.readInt());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, Year value) throws IOException {
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeInt(value.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Year) return ((Year)value).getValue();
|
||||
return BasicTypeConverter.toInteger(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year toBeanType(Object value) {
|
||||
if (value instanceof Year) return (Year) value;
|
||||
return Year.of(BasicTypeConverter.toInteger(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Year v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year parse(String value) {
|
||||
return Year.parse(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year convertFromMillis(long systemTimeMillis) {
|
||||
throw new TextException("Not Supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return Year.of(ctx.getIntValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Year value) throws IOException {
|
||||
ctx.writeNumberField(name, value.getValue());
|
||||
}
|
||||
}
|
||||
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.Types;
|
||||
import java.time.Year;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.Year
|
||||
*/
|
||||
public class ScalarTypeYear extends ScalarTypeBase<Year> {
|
||||
|
||||
public ScalarTypeYear() {
|
||||
super(Year.class, true, Types.INTEGER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind bind, Year value) throws SQLException {
|
||||
if (value == null) {
|
||||
bind.setNull(Types.INTEGER);
|
||||
} else {
|
||||
bind.setInt(value.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year read(DataReader dataReader) throws SQLException {
|
||||
Integer value = dataReader.getInt();
|
||||
return (value == null) ? null : Year.of(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
return null;
|
||||
} else {
|
||||
return Year.of(dataInput.readInt());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, Year value) throws IOException {
|
||||
if (value == null) {
|
||||
dataOutput.writeBoolean(false);
|
||||
} else {
|
||||
dataOutput.writeBoolean(true);
|
||||
dataOutput.writeInt(value.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Year) return ((Year)value).getValue();
|
||||
return BasicTypeConverter.toInteger(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year toBeanType(Object value) {
|
||||
if (value instanceof Year) return (Year) value;
|
||||
return Year.of(BasicTypeConverter.toInteger(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(Year v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year parse(String value) {
|
||||
return Year.parse(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDateTimeCapable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year convertFromMillis(long systemTimeMillis) {
|
||||
throw new TextException("Not Supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Year jsonRead(JsonParser ctx, JsonToken event) throws IOException {
|
||||
return Year.of(ctx.getIntValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonWrite(JsonGenerator ctx, String name, Year value) throws IOException {
|
||||
ctx.writeNumberField(name, value.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
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.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.LocalDate. This maps to a JDBC Date.
|
||||
*/
|
||||
public class ScalarTypeYearMonthDate extends ScalarTypeBaseDate<YearMonth> {
|
||||
|
||||
public ScalarTypeYearMonthDate() {
|
||||
super(YearMonth.class, false, Types.DATE);
|
||||
}
|
||||
|
||||
protected LocalDate toLocalDate(YearMonth yearMonth) {
|
||||
return LocalDate.of(yearMonth.getYear(), yearMonth.getMonth(), 1);
|
||||
}
|
||||
|
||||
protected YearMonth fromLocalDate(LocalDate localDate) {
|
||||
return YearMonth.of(localDate.getYear(), localDate.getMonth());
|
||||
}
|
||||
|
||||
@Override
|
||||
public YearMonth convertFromMillis(long systemTimeMillis) {
|
||||
return fromLocalDate(new Timestamp(systemTimeMillis).toLocalDateTime().toLocalDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(YearMonth value) {
|
||||
LocalDate localDate = toLocalDate(value);
|
||||
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
public YearMonth convertFromDate(Date ts) {
|
||||
return fromLocalDate(ts.toLocalDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date convertToDate(YearMonth t) {
|
||||
return Date.valueOf(toLocalDate(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Date) return value;
|
||||
if (value instanceof YearMonth) return Date.valueOf(toLocalDate((YearMonth) value));
|
||||
if (value instanceof LocalDate) return Date.valueOf((LocalDate)value);
|
||||
return BasicTypeConverter.toDate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YearMonth toBeanType(Object value) {
|
||||
if (value instanceof YearMonth) return (YearMonth) value;
|
||||
if (value instanceof LocalDate) return fromLocalDate((LocalDate) value);
|
||||
return fromLocalDate(BasicTypeConverter.toDate(value).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.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.LocalDate. This maps to a JDBC Date.
|
||||
*/
|
||||
public class ScalarTypeYearMonthDate extends ScalarTypeBaseDate<YearMonth> {
|
||||
|
||||
public ScalarTypeYearMonthDate() {
|
||||
super(YearMonth.class, false, Types.DATE);
|
||||
}
|
||||
|
||||
protected LocalDate toLocalDate(YearMonth yearMonth) {
|
||||
return LocalDate.of(yearMonth.getYear(), yearMonth.getMonth(), 1);
|
||||
}
|
||||
|
||||
protected YearMonth fromLocalDate(LocalDate localDate) {
|
||||
return YearMonth.of(localDate.getYear(), localDate.getMonth());
|
||||
}
|
||||
|
||||
@Override
|
||||
public YearMonth convertFromMillis(long systemTimeMillis) {
|
||||
return fromLocalDate(new Timestamp(systemTimeMillis).toLocalDateTime().toLocalDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(YearMonth value) {
|
||||
LocalDate localDate = toLocalDate(value);
|
||||
ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
|
||||
return zonedDateTime.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
public YearMonth convertFromDate(Date ts) {
|
||||
return fromLocalDate(ts.toLocalDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date convertToDate(YearMonth t) {
|
||||
return Date.valueOf(toLocalDate(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Date) return value;
|
||||
if (value instanceof YearMonth) return Date.valueOf(toLocalDate((YearMonth) value));
|
||||
if (value instanceof LocalDate) return Date.valueOf((LocalDate)value);
|
||||
return BasicTypeConverter.toDate(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YearMonth toBeanType(Object value) {
|
||||
if (value instanceof YearMonth) return (YearMonth) value;
|
||||
if (value instanceof LocalDate) return fromLocalDate((LocalDate) value);
|
||||
return fromLocalDate(BasicTypeConverter.toDate(value).toLocalDate());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.time.OffsetTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypeZoneId extends ScalarTypeBaseVarchar<ZoneId> {
|
||||
|
||||
public ScalarTypeZoneId() {
|
||||
super(ZoneId.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(ZoneId v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneId parse(String value) {
|
||||
return ZoneId.of(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneId convertFromDbString(String dbValue) {
|
||||
return ZoneId.of(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(ZoneId beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.time.OffsetTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypeZoneId extends ScalarTypeBaseVarchar<ZoneId> {
|
||||
|
||||
public ScalarTypeZoneId() {
|
||||
super(ZoneId.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(ZoneId v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneId parse(String value) {
|
||||
return ZoneId.of(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneId convertFromDbString(String dbValue) {
|
||||
return ZoneId.of(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(ZoneId beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypeZoneOffset extends ScalarTypeBaseVarchar<ZoneOffset> {
|
||||
|
||||
public ScalarTypeZoneOffset() {
|
||||
super(ZoneOffset.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(ZoneOffset v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneOffset parse(String value) {
|
||||
return ZoneOffset.of(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneOffset convertFromDbString(String dbValue) {
|
||||
return ZoneOffset.of(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(ZoneOffset beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
/**
|
||||
* ScalarType for java.time.OffsetTime stored as DB VARCHAR
|
||||
*/
|
||||
public class ScalarTypeZoneOffset extends ScalarTypeBaseVarchar<ZoneOffset> {
|
||||
|
||||
public ScalarTypeZoneOffset() {
|
||||
super(ZoneOffset.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String formatValue(ZoneOffset v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneOffset parse(String value) {
|
||||
return ZoneOffset.of(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZoneOffset convertFromDbString(String dbValue) {
|
||||
return ZoneOffset.of(dbValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToDbString(ZoneOffset beanValue) {
|
||||
return beanValue.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.time.Instant;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* ScalarType for ZonedDateTime.
|
||||
*/
|
||||
public class ScalarTypeZonedDateTime extends ScalarTypeBaseDateTime<ZonedDateTime> {
|
||||
|
||||
public ScalarTypeZonedDateTime(JsonConfig.DateTime mode) {
|
||||
super(mode, ZonedDateTime.class, true, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(ZonedDateTime value) {
|
||||
return toJsonNanos(value.toEpochSecond(), value.getNano());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(ZonedDateTime value) {
|
||||
return value.toInstant().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(ZonedDateTime value) {
|
||||
return value.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime convertFromMillis(long systemTimeMillis) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(systemTimeMillis), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime convertFromTimestamp(Timestamp ts) {
|
||||
return ZonedDateTime.ofInstant(ts.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(ZonedDateTime t) {
|
||||
return Timestamp.from(t.toInstant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Timestamp) return value;
|
||||
return convertToTimestamp((ZonedDateTime)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime toBeanType(Object value) {
|
||||
if (value instanceof ZonedDateTime) return (ZonedDateTime) 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;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
/**
|
||||
* ScalarType for ZonedDateTime.
|
||||
*/
|
||||
public class ScalarTypeZonedDateTime extends ScalarTypeBaseDateTime<ZonedDateTime> {
|
||||
|
||||
public ScalarTypeZonedDateTime(JsonConfig.DateTime mode) {
|
||||
super(mode, ZonedDateTime.class, true, Types.TIMESTAMP);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonNanos(ZonedDateTime value) {
|
||||
return toJsonNanos(value.toEpochSecond(), value.getNano());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toJsonISO8601(ZonedDateTime value) {
|
||||
return value.toInstant().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long convertToMillis(ZonedDateTime value) {
|
||||
return value.toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime convertFromMillis(long systemTimeMillis) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(systemTimeMillis), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime convertFromTimestamp(Timestamp ts) {
|
||||
return ZonedDateTime.ofInstant(ts.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp convertToTimestamp(ZonedDateTime t) {
|
||||
return Timestamp.from(t.toInstant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Timestamp) return value;
|
||||
return convertToTimestamp((ZonedDateTime)value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime toBeanType(Object value) {
|
||||
if (value instanceof ZonedDateTime) return (ZonedDateTime) value;
|
||||
return convertFromTimestamp((Timestamp)value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,128 +1,128 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.Encryptor;
|
||||
|
||||
/**
|
||||
* Simple AES based encryption and decryption.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class SimpleAesEncryptor implements Encryptor {
|
||||
|
||||
private static final String AES_CIPHER = "AES/CBC/PKCS5Padding";
|
||||
|
||||
private static final String padding = "asldkalsdkadsdfkjsldfjl";
|
||||
|
||||
public SimpleAesEncryptor() {
|
||||
}
|
||||
|
||||
private String paddKey(EncryptKey encryptKey) {
|
||||
|
||||
String key = encryptKey.getStringValue();
|
||||
int addChars = 16 - key.length();
|
||||
if (addChars < 0) {
|
||||
return key.substring(0, 16);
|
||||
} else if (addChars > 0) {
|
||||
return key + padding.substring(0, addChars);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
private byte[] getKeyBytes(String skey) {
|
||||
|
||||
try {
|
||||
return skey.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private IvParameterSpec getIvParameterSpec(String initialVector) {
|
||||
return new IvParameterSpec(initialVector.getBytes());
|
||||
}
|
||||
|
||||
public byte[] decrypt(byte[] data, EncryptKey encryptKey) {
|
||||
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = paddKey(encryptKey);
|
||||
|
||||
try {
|
||||
|
||||
byte[] keyBytes = getKeyBytes(key);
|
||||
IvParameterSpec iv = getIvParameterSpec(key);
|
||||
|
||||
SecretKeySpec sks = new SecretKeySpec(keyBytes, "AES");
|
||||
Cipher c = Cipher.getInstance(AES_CIPHER);
|
||||
|
||||
c.init(Cipher.DECRYPT_MODE, sks, iv);
|
||||
|
||||
return c.doFinal(data);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encrypt(byte[] data, EncryptKey encryptKey) {
|
||||
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = paddKey(encryptKey);
|
||||
|
||||
try {
|
||||
byte[] keyBytes = getKeyBytes(key);
|
||||
IvParameterSpec iv = getIvParameterSpec(key);
|
||||
|
||||
SecretKeySpec sks = new SecretKeySpec(keyBytes, "AES");
|
||||
Cipher c = Cipher.getInstance(AES_CIPHER);
|
||||
|
||||
c.init(Cipher.ENCRYPT_MODE, sks, iv);
|
||||
|
||||
return c.doFinal(data);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String decryptString(byte[] data, EncryptKey key) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes = decrypt(data, key);
|
||||
try {
|
||||
return new String(bytes, "UTF-8");
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encryptString(String valueFormatValue, EncryptKey key) {
|
||||
|
||||
if (valueFormatValue == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
byte[] d = valueFormatValue.getBytes("UTF-8");
|
||||
return encrypt(d, key);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.Encryptor;
|
||||
|
||||
/**
|
||||
* Simple AES based encryption and decryption.
|
||||
*
|
||||
* @author rbygrave
|
||||
*/
|
||||
public class SimpleAesEncryptor implements Encryptor {
|
||||
|
||||
private static final String AES_CIPHER = "AES/CBC/PKCS5Padding";
|
||||
|
||||
private static final String padding = "asldkalsdkadsdfkjsldfjl";
|
||||
|
||||
public SimpleAesEncryptor() {
|
||||
}
|
||||
|
||||
private String paddKey(EncryptKey encryptKey) {
|
||||
|
||||
String key = encryptKey.getStringValue();
|
||||
int addChars = 16 - key.length();
|
||||
if (addChars < 0) {
|
||||
return key.substring(0, 16);
|
||||
} else if (addChars > 0) {
|
||||
return key + padding.substring(0, addChars);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
private byte[] getKeyBytes(String skey) {
|
||||
|
||||
try {
|
||||
return skey.getBytes("UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private IvParameterSpec getIvParameterSpec(String initialVector) {
|
||||
return new IvParameterSpec(initialVector.getBytes());
|
||||
}
|
||||
|
||||
public byte[] decrypt(byte[] data, EncryptKey encryptKey) {
|
||||
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = paddKey(encryptKey);
|
||||
|
||||
try {
|
||||
|
||||
byte[] keyBytes = getKeyBytes(key);
|
||||
IvParameterSpec iv = getIvParameterSpec(key);
|
||||
|
||||
SecretKeySpec sks = new SecretKeySpec(keyBytes, "AES");
|
||||
Cipher c = Cipher.getInstance(AES_CIPHER);
|
||||
|
||||
c.init(Cipher.DECRYPT_MODE, sks, iv);
|
||||
|
||||
return c.doFinal(data);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encrypt(byte[] data, EncryptKey encryptKey) {
|
||||
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String key = paddKey(encryptKey);
|
||||
|
||||
try {
|
||||
byte[] keyBytes = getKeyBytes(key);
|
||||
IvParameterSpec iv = getIvParameterSpec(key);
|
||||
|
||||
SecretKeySpec sks = new SecretKeySpec(keyBytes, "AES");
|
||||
Cipher c = Cipher.getInstance(AES_CIPHER);
|
||||
|
||||
c.init(Cipher.ENCRYPT_MODE, sks, iv);
|
||||
|
||||
return c.doFinal(data);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String decryptString(byte[] data, EncryptKey key) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bytes = decrypt(data, key);
|
||||
try {
|
||||
return new String(bytes, "UTF-8");
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] encryptString(String valueFormatValue, EncryptKey key) {
|
||||
|
||||
if (valueFormatValue == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
byte[] d = valueFormatValue.getBytes("UTF-8");
|
||||
return encrypt(d, key);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeaninternal.server.type.reflect.CheckImmutableResponse;
|
||||
|
||||
/**
|
||||
* Convert an Object to the required type.
|
||||
*/
|
||||
public interface TypeManager {
|
||||
|
||||
/**
|
||||
* Check if the type is immutable using reflection.
|
||||
*/
|
||||
public CheckImmutableResponse checkImmutable(Class<?> cls);
|
||||
|
||||
/**
|
||||
* Create ScalarDataReader's for the Immutable compound type.
|
||||
*/
|
||||
public ScalarDataReader<?> recursiveCreateScalarDataReader(Class<?> cls);
|
||||
|
||||
/**
|
||||
* Create ScalarTypes for this Immutable Value Object type.
|
||||
*/
|
||||
public ScalarType<?> recursiveCreateScalarTypes(Class<?> cls);
|
||||
|
||||
/**
|
||||
* Register a ScalarType with the system.
|
||||
*/
|
||||
public void add(ScalarType<?> scalarType);
|
||||
|
||||
/**
|
||||
* Return the Internal CompoundType handler for a given compound type.
|
||||
*/
|
||||
public CtCompoundType<?> getCompoundType(Class<?> type);
|
||||
|
||||
/**
|
||||
* Return the ScalarType for a given jdbc type.
|
||||
*
|
||||
* @param jdbcType
|
||||
* as per java.sql.Types
|
||||
*/
|
||||
public ScalarType<?> getScalarType(int jdbcType);
|
||||
|
||||
/**
|
||||
* Return the ScalarType for a given logical type.
|
||||
*/
|
||||
public <T> ScalarType<T> getScalarType(Class<T> type);
|
||||
|
||||
/**
|
||||
* For java.util.Date and java.util.Calendar additionally pass the jdbc type
|
||||
* that you would like the ScalarType to map to. This is because these types
|
||||
* can map to different java.sql.Types depending on the property.
|
||||
*/
|
||||
public <T> ScalarType<T> getScalarType(Class<T> type, int jdbcType);
|
||||
|
||||
/**
|
||||
* Create a ScalarType for an Enum using a mapping (rather than JPA Ordinal
|
||||
* or String which has limitations).
|
||||
*/
|
||||
public ScalarType<?> createEnumScalarType(Class<?> enumType);
|
||||
|
||||
/**
|
||||
* Find a scalarType using a custom type key. Used for Hstore and similar special types.
|
||||
*/
|
||||
public ScalarType<?> getScalarTypeFromKey(String specialTypeKey);
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeaninternal.server.type.reflect.CheckImmutableResponse;
|
||||
|
||||
/**
|
||||
* Convert an Object to the required type.
|
||||
*/
|
||||
public interface TypeManager {
|
||||
|
||||
/**
|
||||
* Check if the type is immutable using reflection.
|
||||
*/
|
||||
public CheckImmutableResponse checkImmutable(Class<?> cls);
|
||||
|
||||
/**
|
||||
* Create ScalarDataReader's for the Immutable compound type.
|
||||
*/
|
||||
public ScalarDataReader<?> recursiveCreateScalarDataReader(Class<?> cls);
|
||||
|
||||
/**
|
||||
* Create ScalarTypes for this Immutable Value Object type.
|
||||
*/
|
||||
public ScalarType<?> recursiveCreateScalarTypes(Class<?> cls);
|
||||
|
||||
/**
|
||||
* Register a ScalarType with the system.
|
||||
*/
|
||||
public void add(ScalarType<?> scalarType);
|
||||
|
||||
/**
|
||||
* Return the Internal CompoundType handler for a given compound type.
|
||||
*/
|
||||
public CtCompoundType<?> getCompoundType(Class<?> type);
|
||||
|
||||
/**
|
||||
* Return the ScalarType for a given jdbc type.
|
||||
*
|
||||
* @param jdbcType
|
||||
* as per java.sql.Types
|
||||
*/
|
||||
public ScalarType<?> getScalarType(int jdbcType);
|
||||
|
||||
/**
|
||||
* Return the ScalarType for a given logical type.
|
||||
*/
|
||||
public <T> ScalarType<T> getScalarType(Class<T> type);
|
||||
|
||||
/**
|
||||
* For java.util.Date and java.util.Calendar additionally pass the jdbc type
|
||||
* that you would like the ScalarType to map to. This is because these types
|
||||
* can map to different java.sql.Types depending on the property.
|
||||
*/
|
||||
public <T> ScalarType<T> getScalarType(Class<T> type, int jdbcType);
|
||||
|
||||
/**
|
||||
* Create a ScalarType for an Enum using a mapping (rather than JPA Ordinal
|
||||
* or String which has limitations).
|
||||
*/
|
||||
public ScalarType<?> createEnumScalarType(Class<?> enumType);
|
||||
|
||||
/**
|
||||
* Find a scalarType using a custom type key. Used for Hstore and similar special types.
|
||||
*/
|
||||
public ScalarType<?> getScalarTypeFromKey(String specialTypeKey);
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class TypeReflectHelper {
|
||||
|
||||
public static Class<?>[] getParams(Class<?> cls, Class<?> matchRawType) {
|
||||
|
||||
Type[] types = getParamType(cls, matchRawType);
|
||||
Class<?>[] result = new Class<?>[types.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = getClass(types[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Class<?> getClass(Type type){
|
||||
|
||||
if (type instanceof ParameterizedType){
|
||||
return getClass(((ParameterizedType)type).getRawType());
|
||||
}
|
||||
|
||||
return (Class<?>)type;
|
||||
}
|
||||
|
||||
private static Type[] getParamType(Class<?> cls, Class<?> matchRawType) {
|
||||
|
||||
Type[] gis = cls.getGenericInterfaces();
|
||||
for (int i = 0; i < gis.length; i++) {
|
||||
Type type = gis[i];
|
||||
if (type instanceof ParameterizedType) {
|
||||
ParameterizedType paramType = (ParameterizedType) type;
|
||||
Type rawType = paramType.getRawType();
|
||||
if (rawType.equals(matchRawType)) {
|
||||
|
||||
return paramType.getActualTypeArguments();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class TypeReflectHelper {
|
||||
|
||||
public static Class<?>[] getParams(Class<?> cls, Class<?> matchRawType) {
|
||||
|
||||
Type[] types = getParamType(cls, matchRawType);
|
||||
Class<?>[] result = new Class<?>[types.length];
|
||||
for (int i = 0; i < result.length; i++) {
|
||||
result[i] = getClass(types[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Class<?> getClass(Type type){
|
||||
|
||||
if (type instanceof ParameterizedType){
|
||||
return getClass(((ParameterizedType)type).getRawType());
|
||||
}
|
||||
|
||||
return (Class<?>)type;
|
||||
}
|
||||
|
||||
private static Type[] getParamType(Class<?> cls, Class<?> matchRawType) {
|
||||
|
||||
Type[] gis = cls.getGenericInterfaces();
|
||||
for (int i = 0; i < gis.length; i++) {
|
||||
Type type = gis[i];
|
||||
if (type instanceof ParameterizedType) {
|
||||
ParameterizedType paramType = (ParameterizedType) type;
|
||||
Type rawType = paramType.getRawType();
|
||||
if (rawType.equals(matchRawType)) {
|
||||
|
||||
return paramType.getActualTypeArguments();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+228
-228
@@ -1,228 +1,228 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ImmutableMetaFactory {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImmutableMetaFactory.class);
|
||||
|
||||
public ImmutableMeta createImmutableMeta(Class<?> cls) {
|
||||
|
||||
ScoreConstructor[] scoreConstructors = scoreConstructors(cls);
|
||||
|
||||
ArrayList<RuntimeException> errors = new ArrayList<RuntimeException>();
|
||||
|
||||
// search the constructors in score order ...
|
||||
// ... we need to find a set of readers for each
|
||||
// ... type in the constructor
|
||||
for (int i = 0; i < scoreConstructors.length; i++) {
|
||||
Constructor<?> constructor = scoreConstructors[i].constructor;
|
||||
|
||||
try {
|
||||
Method[] getters = findGetters(cls, constructor);
|
||||
|
||||
return new ImmutableMeta(constructor, getters);
|
||||
|
||||
} catch (NoSuchMethodException e){
|
||||
String msg = "Error finding getter method on "+cls+" with constructor "+constructor;
|
||||
errors.add(new RuntimeException(msg, e));
|
||||
}
|
||||
}
|
||||
|
||||
String msg = "Was unable to use reflection to find a constructor and appropriate getters for" +
|
||||
"immutable type "+cls+". The errors while looking for the getter methods follow:";
|
||||
logger.error(msg);
|
||||
|
||||
for (RuntimeException runtimeException : errors) {
|
||||
logger.error("Error with " + cls, runtimeException);
|
||||
}
|
||||
|
||||
msg = "Unable to use reflection to build ImmutableMeta for " + cls
|
||||
+ ". Associated Errors trying to find a constructor and getter methods have been logged";
|
||||
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
private ScoreConstructor getScore(Constructor<?> c) {
|
||||
|
||||
Class<?>[] parameterTypes = c.getParameterTypes();
|
||||
int score = -1000 * parameterTypes.length;
|
||||
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (parameterTypes[i].equals(String.class)){
|
||||
// string is very generic and we would prefer
|
||||
// a more specific type if that was available
|
||||
score = score + 1;
|
||||
|
||||
} else if (parameterTypes[i].equals(BigDecimal.class)) {
|
||||
score = score - 10;
|
||||
} else if (parameterTypes[i].equals(Timestamp.class)) {
|
||||
score = score - 10;
|
||||
} else if (parameterTypes[i].equals(double.class)) {
|
||||
score = score - 9;
|
||||
} else if (parameterTypes[i].equals(Double.class)) {
|
||||
score = score - 8;
|
||||
} else if (parameterTypes[i].equals(float.class)) {
|
||||
score = score - 7;
|
||||
} else if (parameterTypes[i].equals(Float.class)) {
|
||||
score = score - 6;
|
||||
} else if (parameterTypes[i].equals(long.class)) {
|
||||
score = score - 5;
|
||||
} else if (parameterTypes[i].equals(Long.class)) {
|
||||
score = score - 4;
|
||||
} else if (parameterTypes[i].equals(int.class)) {
|
||||
score = score - 3;
|
||||
} else if (parameterTypes[i].equals(Integer.class)) {
|
||||
score = score - 2;
|
||||
}
|
||||
}
|
||||
|
||||
return new ScoreConstructor(score, c);
|
||||
}
|
||||
|
||||
private ScoreConstructor[] scoreConstructors(Class<?> cls) {
|
||||
|
||||
// find the constructor with the most number of parameters
|
||||
int maxParamCount = 0;
|
||||
|
||||
Constructor<?>[] constructors = cls.getConstructors();
|
||||
|
||||
ScoreConstructor[] score = new ScoreConstructor[constructors.length];
|
||||
|
||||
for (int i = 0; i < constructors.length; i++) {
|
||||
score[i] = getScore(constructors[i]);
|
||||
if (score[i].hasDuplicateParamTypes()){
|
||||
String msg = "Duplicate parameter types in "+score[i].constructor;
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
if (score[i].getParamCount() > maxParamCount){
|
||||
maxParamCount = score[i].getParamCount();
|
||||
}
|
||||
}
|
||||
|
||||
// filter out any constructors with less parameters than the max
|
||||
ArrayList<ScoreConstructor> list = new ArrayList<ScoreConstructor>();
|
||||
for (int i = 0; i < score.length; i++) {
|
||||
if (score[i].getParamCount() == maxParamCount){
|
||||
list.add(score[i]);
|
||||
}
|
||||
}
|
||||
|
||||
score = list.toArray(new ScoreConstructor[list.size()]);
|
||||
|
||||
// sort into score ascending order
|
||||
Arrays.sort(score);
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Method[] findGetters(Class<?> cls, Constructor<?> c) throws NoSuchMethodException {
|
||||
|
||||
Method[] methods = cls.getMethods();
|
||||
|
||||
Class<?>[] paramTypes = c.getParameterTypes();
|
||||
|
||||
Method[] readers = new Method[paramTypes.length];
|
||||
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
Method getter = findGetter(paramTypes[i], methods);
|
||||
if (getter == null && paramTypes.length == 1 && paramTypes[i].equals(String.class)){
|
||||
getter = findToString(cls);
|
||||
}
|
||||
if (getter == null) {
|
||||
throw new NoSuchMethodException("Get Method not found for "+paramTypes[i]+" in "+cls);
|
||||
}
|
||||
readers[i] = getter;
|
||||
}
|
||||
|
||||
return readers;
|
||||
}
|
||||
|
||||
private Method findToString(Class<?> cls) throws NoSuchMethodException {
|
||||
|
||||
try {
|
||||
return cls.getDeclaredMethod("toString", new Class<?>[0]);
|
||||
} catch (SecurityException e) {
|
||||
throw new NoSuchMethodException("SecurityException "+e+" trying to find toString method on "+cls);
|
||||
}
|
||||
}
|
||||
|
||||
private Method findGetter(Class<?> paramType, Method[] methods) {
|
||||
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (Modifier.isStatic(methods[i].getModifiers())) {
|
||||
|
||||
} else {
|
||||
if (methods[i].getParameterTypes().length == 0) {
|
||||
// could be a getter
|
||||
String methName = methods[i].getName();
|
||||
if (methName.equals("hashCode")){
|
||||
|
||||
} else if (methName.equals("toString")) {
|
||||
|
||||
} else {
|
||||
Class<?> returnType = methods[i].getReturnType();
|
||||
if (paramType.equals(returnType)){
|
||||
return methods[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class ScoreConstructor implements Comparable<ScoreConstructor>{
|
||||
|
||||
final int score;
|
||||
final Constructor<?> constructor;
|
||||
|
||||
private ScoreConstructor(int score, Constructor<?> constructor) {
|
||||
this.score = score;
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
// remove FindBugs warning
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
public int compareTo(ScoreConstructor o) {
|
||||
return (score<o.score ? -1 : (score==o.score ? 0 : 1));
|
||||
}
|
||||
|
||||
public int getParamCount() {
|
||||
return constructor.getParameterTypes().length;
|
||||
}
|
||||
|
||||
public boolean hasDuplicateParamTypes() {
|
||||
|
||||
Class<?>[] parameterTypes = constructor.getParameterTypes();
|
||||
if (parameterTypes.length < 2){
|
||||
return false;
|
||||
}
|
||||
HashSet<Class<?>> set = new HashSet<Class<?>>();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (!set.add(parameterTypes[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ImmutableMetaFactory {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImmutableMetaFactory.class);
|
||||
|
||||
public ImmutableMeta createImmutableMeta(Class<?> cls) {
|
||||
|
||||
ScoreConstructor[] scoreConstructors = scoreConstructors(cls);
|
||||
|
||||
ArrayList<RuntimeException> errors = new ArrayList<RuntimeException>();
|
||||
|
||||
// search the constructors in score order ...
|
||||
// ... we need to find a set of readers for each
|
||||
// ... type in the constructor
|
||||
for (int i = 0; i < scoreConstructors.length; i++) {
|
||||
Constructor<?> constructor = scoreConstructors[i].constructor;
|
||||
|
||||
try {
|
||||
Method[] getters = findGetters(cls, constructor);
|
||||
|
||||
return new ImmutableMeta(constructor, getters);
|
||||
|
||||
} catch (NoSuchMethodException e){
|
||||
String msg = "Error finding getter method on "+cls+" with constructor "+constructor;
|
||||
errors.add(new RuntimeException(msg, e));
|
||||
}
|
||||
}
|
||||
|
||||
String msg = "Was unable to use reflection to find a constructor and appropriate getters for" +
|
||||
"immutable type "+cls+". The errors while looking for the getter methods follow:";
|
||||
logger.error(msg);
|
||||
|
||||
for (RuntimeException runtimeException : errors) {
|
||||
logger.error("Error with " + cls, runtimeException);
|
||||
}
|
||||
|
||||
msg = "Unable to use reflection to build ImmutableMeta for " + cls
|
||||
+ ". Associated Errors trying to find a constructor and getter methods have been logged";
|
||||
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
private ScoreConstructor getScore(Constructor<?> c) {
|
||||
|
||||
Class<?>[] parameterTypes = c.getParameterTypes();
|
||||
int score = -1000 * parameterTypes.length;
|
||||
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (parameterTypes[i].equals(String.class)){
|
||||
// string is very generic and we would prefer
|
||||
// a more specific type if that was available
|
||||
score = score + 1;
|
||||
|
||||
} else if (parameterTypes[i].equals(BigDecimal.class)) {
|
||||
score = score - 10;
|
||||
} else if (parameterTypes[i].equals(Timestamp.class)) {
|
||||
score = score - 10;
|
||||
} else if (parameterTypes[i].equals(double.class)) {
|
||||
score = score - 9;
|
||||
} else if (parameterTypes[i].equals(Double.class)) {
|
||||
score = score - 8;
|
||||
} else if (parameterTypes[i].equals(float.class)) {
|
||||
score = score - 7;
|
||||
} else if (parameterTypes[i].equals(Float.class)) {
|
||||
score = score - 6;
|
||||
} else if (parameterTypes[i].equals(long.class)) {
|
||||
score = score - 5;
|
||||
} else if (parameterTypes[i].equals(Long.class)) {
|
||||
score = score - 4;
|
||||
} else if (parameterTypes[i].equals(int.class)) {
|
||||
score = score - 3;
|
||||
} else if (parameterTypes[i].equals(Integer.class)) {
|
||||
score = score - 2;
|
||||
}
|
||||
}
|
||||
|
||||
return new ScoreConstructor(score, c);
|
||||
}
|
||||
|
||||
private ScoreConstructor[] scoreConstructors(Class<?> cls) {
|
||||
|
||||
// find the constructor with the most number of parameters
|
||||
int maxParamCount = 0;
|
||||
|
||||
Constructor<?>[] constructors = cls.getConstructors();
|
||||
|
||||
ScoreConstructor[] score = new ScoreConstructor[constructors.length];
|
||||
|
||||
for (int i = 0; i < constructors.length; i++) {
|
||||
score[i] = getScore(constructors[i]);
|
||||
if (score[i].hasDuplicateParamTypes()){
|
||||
String msg = "Duplicate parameter types in "+score[i].constructor;
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
if (score[i].getParamCount() > maxParamCount){
|
||||
maxParamCount = score[i].getParamCount();
|
||||
}
|
||||
}
|
||||
|
||||
// filter out any constructors with less parameters than the max
|
||||
ArrayList<ScoreConstructor> list = new ArrayList<ScoreConstructor>();
|
||||
for (int i = 0; i < score.length; i++) {
|
||||
if (score[i].getParamCount() == maxParamCount){
|
||||
list.add(score[i]);
|
||||
}
|
||||
}
|
||||
|
||||
score = list.toArray(new ScoreConstructor[list.size()]);
|
||||
|
||||
// sort into score ascending order
|
||||
Arrays.sort(score);
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Method[] findGetters(Class<?> cls, Constructor<?> c) throws NoSuchMethodException {
|
||||
|
||||
Method[] methods = cls.getMethods();
|
||||
|
||||
Class<?>[] paramTypes = c.getParameterTypes();
|
||||
|
||||
Method[] readers = new Method[paramTypes.length];
|
||||
|
||||
for (int i = 0; i < paramTypes.length; i++) {
|
||||
Method getter = findGetter(paramTypes[i], methods);
|
||||
if (getter == null && paramTypes.length == 1 && paramTypes[i].equals(String.class)){
|
||||
getter = findToString(cls);
|
||||
}
|
||||
if (getter == null) {
|
||||
throw new NoSuchMethodException("Get Method not found for "+paramTypes[i]+" in "+cls);
|
||||
}
|
||||
readers[i] = getter;
|
||||
}
|
||||
|
||||
return readers;
|
||||
}
|
||||
|
||||
private Method findToString(Class<?> cls) throws NoSuchMethodException {
|
||||
|
||||
try {
|
||||
return cls.getDeclaredMethod("toString", new Class<?>[0]);
|
||||
} catch (SecurityException e) {
|
||||
throw new NoSuchMethodException("SecurityException "+e+" trying to find toString method on "+cls);
|
||||
}
|
||||
}
|
||||
|
||||
private Method findGetter(Class<?> paramType, Method[] methods) {
|
||||
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (Modifier.isStatic(methods[i].getModifiers())) {
|
||||
|
||||
} else {
|
||||
if (methods[i].getParameterTypes().length == 0) {
|
||||
// could be a getter
|
||||
String methName = methods[i].getName();
|
||||
if (methName.equals("hashCode")){
|
||||
|
||||
} else if (methName.equals("toString")) {
|
||||
|
||||
} else {
|
||||
Class<?> returnType = methods[i].getReturnType();
|
||||
if (paramType.equals(returnType)){
|
||||
return methods[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static class ScoreConstructor implements Comparable<ScoreConstructor>{
|
||||
|
||||
final int score;
|
||||
final Constructor<?> constructor;
|
||||
|
||||
private ScoreConstructor(int score, Constructor<?> constructor) {
|
||||
this.score = score;
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
// remove FindBugs warning
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
public int compareTo(ScoreConstructor o) {
|
||||
return (score<o.score ? -1 : (score==o.score ? 0 : 1));
|
||||
}
|
||||
|
||||
public int getParamCount() {
|
||||
return constructor.getParameterTypes().length;
|
||||
}
|
||||
|
||||
public boolean hasDuplicateParamTypes() {
|
||||
|
||||
Class<?>[] parameterTypes = constructor.getParameterTypes();
|
||||
if (parameterTypes.length < 2){
|
||||
return false;
|
||||
}
|
||||
HashSet<Class<?>> set = new HashSet<Class<?>>();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (!set.add(parameterTypes[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
public interface KnownImmutable {
|
||||
|
||||
public boolean isKnownImmutable(Class<?> cls);
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
public interface KnownImmutable {
|
||||
|
||||
public boolean isKnownImmutable(Class<?> cls);
|
||||
}
|
||||
|
||||
+46
-46
@@ -1,46 +1,46 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.avaje.ebean.config.CompoundType;
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ReflectionBasedCompoundType implements CompoundType {
|
||||
|
||||
private final Constructor<?> constructor;
|
||||
|
||||
private final ReflectionBasedCompoundTypeProperty[] props;
|
||||
|
||||
public ReflectionBasedCompoundType(Constructor<?> constructor, ReflectionBasedCompoundTypeProperty[] props) {
|
||||
this.constructor = constructor;
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ReflectionBasedCompoundType "+constructor+" "+Arrays.toString(props);
|
||||
}
|
||||
|
||||
public Object create(Object[] propertyValues) {
|
||||
|
||||
try {
|
||||
return constructor.newInstance(propertyValues);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundTypeProperty[] getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public Class<?> getPropertyType(int i){
|
||||
return props[i].getPropertyType();
|
||||
}
|
||||
|
||||
public Class<?> getCompoundType() {
|
||||
return constructor.getDeclaringClass();
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.avaje.ebean.config.CompoundType;
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ReflectionBasedCompoundType implements CompoundType {
|
||||
|
||||
private final Constructor<?> constructor;
|
||||
|
||||
private final ReflectionBasedCompoundTypeProperty[] props;
|
||||
|
||||
public ReflectionBasedCompoundType(Constructor<?> constructor, ReflectionBasedCompoundTypeProperty[] props) {
|
||||
this.constructor = constructor;
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ReflectionBasedCompoundType "+constructor+" "+Arrays.toString(props);
|
||||
}
|
||||
|
||||
public Object create(Object[] propertyValues) {
|
||||
|
||||
try {
|
||||
return constructor.newInstance(propertyValues);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundTypeProperty[] getProperties() {
|
||||
return props;
|
||||
}
|
||||
|
||||
public Class<?> getPropertyType(int i){
|
||||
return props[i].getPropertyType();
|
||||
}
|
||||
|
||||
public Class<?> getCompoundType() {
|
||||
return constructor.getDeclaringClass();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+50
-50
@@ -1,50 +1,50 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ReflectionBasedCompoundTypeProperty implements CompoundTypeProperty {
|
||||
|
||||
private static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private final Method reader;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Class<?> propertyType;
|
||||
|
||||
public ReflectionBasedCompoundTypeProperty(String name, Method reader, Class<?> propertyType) {
|
||||
this.name = name;
|
||||
this.reader = reader;
|
||||
this.propertyType = propertyType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getDbType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Object getValue(Object valueObject) {
|
||||
|
||||
try {
|
||||
return reader.invoke(valueObject, NO_ARGS);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getPropertyType(){
|
||||
return propertyType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ReflectionBasedCompoundTypeProperty implements CompoundTypeProperty {
|
||||
|
||||
private static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private final Method reader;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Class<?> propertyType;
|
||||
|
||||
public ReflectionBasedCompoundTypeProperty(String name, Method reader, Class<?> propertyType) {
|
||||
this.name = name;
|
||||
this.reader = reader;
|
||||
this.propertyType = propertyType;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getDbType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Object getValue(Object valueObject) {
|
||||
|
||||
try {
|
||||
return reader.invoke(valueObject, NO_ARGS);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getPropertyType(){
|
||||
return propertyType;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+49
-49
@@ -1,49 +1,49 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ReflectionBasedScalarTypeConverter implements ScalarTypeConverter {
|
||||
|
||||
private static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private final Constructor<?> constructor;
|
||||
|
||||
private final Method reader;
|
||||
|
||||
public ReflectionBasedScalarTypeConverter(Constructor<?> constructor, Method reader) {
|
||||
this.constructor = constructor;
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public Object getNullValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object unwrapValue(Object beanType) {
|
||||
if (beanType == null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return reader.invoke(beanType, NO_ARGS);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error invoking read method "+reader.getName()
|
||||
+" on "+beanType.getClass().getName();
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public Object wrapValue(Object scalarType) {
|
||||
try {
|
||||
return constructor.newInstance(scalarType);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error invoking constructor "+constructor+" with "+scalarType;
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ReflectionBasedScalarTypeConverter implements ScalarTypeConverter {
|
||||
|
||||
private static final Object[] NO_ARGS = new Object[0];
|
||||
|
||||
private final Constructor<?> constructor;
|
||||
|
||||
private final Method reader;
|
||||
|
||||
public ReflectionBasedScalarTypeConverter(Constructor<?> constructor, Method reader) {
|
||||
this.constructor = constructor;
|
||||
this.reader = reader;
|
||||
}
|
||||
|
||||
public Object getNullValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object unwrapValue(Object beanType) {
|
||||
if (beanType == null){
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return reader.invoke(beanType, NO_ARGS);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error invoking read method "+reader.getName()
|
||||
+" on "+beanType.getClass().getName();
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public Object wrapValue(Object scalarType) {
|
||||
try {
|
||||
return constructor.newInstance(scalarType);
|
||||
} catch (Exception e) {
|
||||
String msg = "Error invoking constructor "+constructor+" with "+scalarType;
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+80
-80
@@ -1,80 +1,80 @@
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarTypeWrapper;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
|
||||
public class ReflectionBasedTypeBuilder {
|
||||
|
||||
private final TypeManager typeManager;
|
||||
|
||||
public ReflectionBasedTypeBuilder(TypeManager typeManager) {
|
||||
this.typeManager = typeManager;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public ScalarType<?> buildScalarType(ImmutableMeta meta) {
|
||||
|
||||
if (meta.isCompoundType()){
|
||||
throw new RuntimeException("Must be scalar");
|
||||
}
|
||||
|
||||
Constructor<?> constructor = meta.getConstructor();
|
||||
|
||||
Class<?> logicalType = constructor.getDeclaringClass();
|
||||
|
||||
Method[] readers = meta.getReaders();
|
||||
Class<?> returnType = readers[0].getReturnType();
|
||||
|
||||
ScalarType<?> scalarType = typeManager.recursiveCreateScalarTypes(returnType);
|
||||
|
||||
ReflectionBasedScalarTypeConverter r = new ReflectionBasedScalarTypeConverter(constructor, readers[0]);
|
||||
|
||||
ScalarTypeWrapper st = new ScalarTypeWrapper(logicalType, scalarType, r);
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
public ReflectionBasedCompoundType buildCompound(ImmutableMeta meta) {
|
||||
|
||||
Constructor<?> constructor = meta.getConstructor();
|
||||
|
||||
Method[] readers = meta.getReaders();
|
||||
|
||||
ReflectionBasedCompoundTypeProperty[] props = new ReflectionBasedCompoundTypeProperty[readers.length];
|
||||
|
||||
|
||||
for (int i = 0; i < readers.length; i++) {
|
||||
Class<?> returnType = readers[i].getReturnType();
|
||||
|
||||
// ensure that return type is also a ScalarDataReader
|
||||
typeManager.recursiveCreateScalarDataReader(returnType);
|
||||
|
||||
String name = getPropertyName(readers[i]);
|
||||
|
||||
props[i] = new ReflectionBasedCompoundTypeProperty(name, readers[i], returnType);
|
||||
}
|
||||
|
||||
return new ReflectionBasedCompoundType(constructor, props);
|
||||
}
|
||||
|
||||
private String getPropertyName(Method method){
|
||||
|
||||
String name = method.getName();
|
||||
if (name.startsWith("is")){
|
||||
return lowerFirstChar(name.substring(2));
|
||||
} else if (name.startsWith("get")){
|
||||
return lowerFirstChar(name.substring(3));
|
||||
}
|
||||
String msg = "Expecting method "+name+" to start with is or get "
|
||||
+" so as to follow bean specification?";
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
private String lowerFirstChar(String name) {
|
||||
return Character.toLowerCase(name.charAt(0))+name.substring(1);
|
||||
}
|
||||
}
|
||||
package com.avaje.ebeaninternal.server.type.reflect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarTypeWrapper;
|
||||
import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
|
||||
public class ReflectionBasedTypeBuilder {
|
||||
|
||||
private final TypeManager typeManager;
|
||||
|
||||
public ReflectionBasedTypeBuilder(TypeManager typeManager) {
|
||||
this.typeManager = typeManager;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public ScalarType<?> buildScalarType(ImmutableMeta meta) {
|
||||
|
||||
if (meta.isCompoundType()){
|
||||
throw new RuntimeException("Must be scalar");
|
||||
}
|
||||
|
||||
Constructor<?> constructor = meta.getConstructor();
|
||||
|
||||
Class<?> logicalType = constructor.getDeclaringClass();
|
||||
|
||||
Method[] readers = meta.getReaders();
|
||||
Class<?> returnType = readers[0].getReturnType();
|
||||
|
||||
ScalarType<?> scalarType = typeManager.recursiveCreateScalarTypes(returnType);
|
||||
|
||||
ReflectionBasedScalarTypeConverter r = new ReflectionBasedScalarTypeConverter(constructor, readers[0]);
|
||||
|
||||
ScalarTypeWrapper st = new ScalarTypeWrapper(logicalType, scalarType, r);
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
public ReflectionBasedCompoundType buildCompound(ImmutableMeta meta) {
|
||||
|
||||
Constructor<?> constructor = meta.getConstructor();
|
||||
|
||||
Method[] readers = meta.getReaders();
|
||||
|
||||
ReflectionBasedCompoundTypeProperty[] props = new ReflectionBasedCompoundTypeProperty[readers.length];
|
||||
|
||||
|
||||
for (int i = 0; i < readers.length; i++) {
|
||||
Class<?> returnType = readers[i].getReturnType();
|
||||
|
||||
// ensure that return type is also a ScalarDataReader
|
||||
typeManager.recursiveCreateScalarDataReader(returnType);
|
||||
|
||||
String name = getPropertyName(readers[i]);
|
||||
|
||||
props[i] = new ReflectionBasedCompoundTypeProperty(name, readers[i], returnType);
|
||||
}
|
||||
|
||||
return new ReflectionBasedCompoundType(constructor, props);
|
||||
}
|
||||
|
||||
private String getPropertyName(Method method){
|
||||
|
||||
String name = method.getName();
|
||||
if (name.startsWith("is")){
|
||||
return lowerFirstChar(name.substring(2));
|
||||
} else if (name.startsWith("get")){
|
||||
return lowerFirstChar(name.substring(3));
|
||||
}
|
||||
String msg = "Expecting method "+name+" to start with is or get "
|
||||
+" so as to follow bean specification?";
|
||||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
private String lowerFirstChar(String name) {
|
||||
return Character.toLowerCase(name.charAt(0))+name.substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user