mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
No effective change - format and imports
This commit is contained in:
1 parent
e3a7c3040b
commit
4606c7c99f
42 files changed
+240
-246
No files matched your search
@@ -37,9 +37,9 @@ public interface ArrayElementConverter<T> {
|
||||
@Override
|
||||
public Long toElement(Object rawValue) {
|
||||
if (rawValue instanceof Long) {
|
||||
return (Long)rawValue;
|
||||
return (Long) rawValue;
|
||||
} else {
|
||||
return ((Number)rawValue).longValue();
|
||||
return ((Number) rawValue).longValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,9 @@ public interface ArrayElementConverter<T> {
|
||||
@Override
|
||||
public Integer toElement(Object rawValue) {
|
||||
if (rawValue instanceof Integer) {
|
||||
return (Integer)rawValue;
|
||||
return (Integer) rawValue;
|
||||
} else {
|
||||
return ((Number)rawValue).intValue();
|
||||
return ((Number) rawValue).intValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public interface ArrayElementConverter<T> {
|
||||
|
||||
@Override
|
||||
public T toElement(Object rawValue) {
|
||||
return (T)rawValue;
|
||||
return (T) rawValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public class CompoundTypePeriod implements CompoundType<Period> {
|
||||
|
||||
@Override
|
||||
public Period create(Object[] propertyValues) {
|
||||
return Period.of((Integer)propertyValues[0], (Integer)propertyValues[1], (Integer)propertyValues[2]);
|
||||
return Period.of((Integer) propertyValues[0], (Integer) propertyValues[1], (Integer) propertyValues[2]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,69 +1,67 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.CompoundTypeProperty;
|
||||
import com.avaje.ebeaninternal.server.query.SplitName;
|
||||
|
||||
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, 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;
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
|
||||
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,7 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Array;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class DecimalUtils {
|
||||
|
||||
public static BigDecimal toDecimal(Timestamp instant) {
|
||||
long millis = instant.getTime();
|
||||
long secs = millis/1000;
|
||||
long secs = millis / 1000;
|
||||
return new BigDecimal(toDecimal(secs, instant.getNanos()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
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;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Helper to create some default ScalarType objects for Booleans,
|
||||
* java.util.Date, java.util.Calendar etc.
|
||||
|
||||
@@ -377,7 +377,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
// fallback to JSON storage in VARCHAR column
|
||||
return new ScalarTypeJsonList.Varchar(getDocType(getValueType(genericType)));
|
||||
}
|
||||
throw new IllegalStateException("Type ["+type+"] not supported for @DbArray");
|
||||
throw new IllegalStateException("Type [" + type + "] not supported for @DbArray");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -411,11 +411,16 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
|
||||
if (type.equals(JsonNode.class)) {
|
||||
switch (dbType) {
|
||||
case Types.VARCHAR : return jsonNodeVarchar;
|
||||
case Types.BLOB: return jsonNodeBlob;
|
||||
case Types.CLOB : return jsonNodeClob;
|
||||
case DbType.JSONB: return jsonNodeJsonb;
|
||||
case DbType.JSON: return jsonNodeJson;
|
||||
case Types.VARCHAR:
|
||||
return jsonNodeVarchar;
|
||||
case Types.BLOB:
|
||||
return jsonNodeBlob;
|
||||
case Types.CLOB:
|
||||
return jsonNodeClob;
|
||||
case DbType.JSONB:
|
||||
return jsonNodeJsonb;
|
||||
case DbType.JSON:
|
||||
return jsonNodeJson;
|
||||
default:
|
||||
return jsonNodeJson;
|
||||
}
|
||||
@@ -520,11 +525,9 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
|
||||
/**
|
||||
* Convert the Object to the required datatype. The
|
||||
*
|
||||
* @param value
|
||||
* the Object value
|
||||
* @param toJdbcType
|
||||
* the type as per java.sql.Types.
|
||||
*
|
||||
* @param value the Object value
|
||||
* @param toJdbcType the type as per java.sql.Types.
|
||||
*/
|
||||
public Object convert(Object value, int toJdbcType) {
|
||||
if (value == null) {
|
||||
@@ -586,7 +589,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
|
||||
return createEnumScalarType(enumType, nameValueMap, integerType, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a ScalarType for an Enum that has additional mapping.
|
||||
* <p>
|
||||
@@ -599,7 +602,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
public ScalarType<?> createEnumScalarType(Class<? extends Enum<?>> enumType) {
|
||||
|
||||
Method[] methods = enumType.getMethods();
|
||||
for (int i = 0; i <methods.length; i++) {
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
DbEnumValue dbValue = methods[i].getAnnotation(DbEnumValue.class);
|
||||
if (dbValue != null) {
|
||||
boolean integerValues = DbEnumType.INTEGER == dbValue.storage();
|
||||
@@ -628,7 +631,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
Object value = method.invoke(enumConstants[i]);
|
||||
nameValueMap.put(enumConstants[i].name(), value.toString());
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("Error trying to invoke DbEnumValue method on "+enumConstants[i], e);
|
||||
throw new IllegalArgumentException("Error trying to invoke DbEnumValue method on " + enumConstants[i], e);
|
||||
}
|
||||
}
|
||||
if (nameValueMap.isEmpty()) {
|
||||
@@ -643,14 +646,14 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
* Given the name value mapping and integer/string type and explicit DB column
|
||||
* length create the ScalarType for the Enum.
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private ScalarType<?> createEnumScalarType(Class enumType, Map<String, String> nameValueMap, boolean integerType, int dbColumnLength) {
|
||||
|
||||
EnumToDbValueMap<?> beanDbMap = EnumToDbValueMap.create(integerType);
|
||||
|
||||
int maxValueLen = 0;
|
||||
|
||||
for (Map.Entry<String,String> entry : nameValueMap.entrySet()) {
|
||||
for (Map.Entry<String, String> entry : nameValueMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
|
||||
@@ -694,7 +697,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
try {
|
||||
// first try objectMapper constructor
|
||||
Constructor<?> constructor = cls.getConstructor(ObjectMapper.class);
|
||||
scalarType = (ScalarType<?>)constructor.newInstance((ObjectMapper)objectMapper);
|
||||
scalarType = (ScalarType<?>) constructor.newInstance((ObjectMapper) objectMapper);
|
||||
} catch (NoSuchMethodException e) {
|
||||
scalarType = (ScalarType<?>) cls.newInstance();
|
||||
}
|
||||
@@ -720,7 +723,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
protected void initialiseScalarConverters(BootupClasses bootupClasses) {
|
||||
|
||||
List<Class<?>> foundTypes = bootupClasses.getScalarConverters();
|
||||
@@ -782,7 +785,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
protected CtCompoundType createCompoundScalarDataReader(Class<?> compoundTypeClass, CompoundType<?> compoundType, String info) {
|
||||
|
||||
CtCompoundType<?> ctCompoundType = compoundTypeMap.get(compoundTypeClass);
|
||||
@@ -844,7 +847,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
|
||||
logger.trace("Registering JsonNode type support");
|
||||
|
||||
ObjectMapper mapper = (ObjectMapper)objectMapper;
|
||||
ObjectMapper mapper = (ObjectMapper) objectMapper;
|
||||
jsonNodeClob = new ScalarTypeJsonNode.Clob(mapper);
|
||||
jsonNodeBlob = new ScalarTypeJsonNode.Blob(mapper);
|
||||
jsonNodeVarchar = new ScalarTypeJsonNode.Varchar(mapper);
|
||||
@@ -887,10 +890,10 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
createCompoundScalarDataReader(Period.class, new CompoundTypePeriod(), "");
|
||||
|
||||
boolean localTimeNanos = config.isLocalTimeWithNanos();
|
||||
typeMap.put(java.time.LocalTime.class, (localTimeNanos)? new ScalarTypeLocalTimeWithNanos() : new ScalarTypeLocalTime());
|
||||
typeMap.put(java.time.LocalTime.class, (localTimeNanos) ? new ScalarTypeLocalTimeWithNanos() : new ScalarTypeLocalTime());
|
||||
|
||||
boolean durationNanos = config.isDurationWithNanos();
|
||||
typeMap.put(Duration.class, (durationNanos)? new ScalarTypeDurationWithNanos() : new ScalarTypeDuration());
|
||||
typeMap.put(Duration.class, (durationNanos) ? new ScalarTypeDurationWithNanos() : new ScalarTypeDuration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -921,7 +924,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register all the standard types supported. This is the standard JDBC types
|
||||
* plus some other common types such as java.util.Date and java.util.Calendar.
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
/**
|
||||
* Used to map enum values to database integer values.
|
||||
*/
|
||||
|
||||
+73
-76
@@ -10,89 +10,86 @@ import java.util.Map;
|
||||
* been collected then the immutable compound value object is created and
|
||||
* returned.
|
||||
* </p>
|
||||
*
|
||||
* @author rbygrave
|
||||
*
|
||||
*/
|
||||
public final class ImmutableCompoundTypeBuilder {
|
||||
|
||||
private static final ThreadLocal<ImmutableCompoundTypeBuilder> local = new ThreadLocal<ImmutableCompoundTypeBuilder>() {
|
||||
protected synchronized ImmutableCompoundTypeBuilder initialValue() {
|
||||
return new ImmutableCompoundTypeBuilder();
|
||||
}
|
||||
};
|
||||
private static final ThreadLocal<ImmutableCompoundTypeBuilder> local = new ThreadLocal<ImmutableCompoundTypeBuilder>() {
|
||||
protected synchronized ImmutableCompoundTypeBuilder initialValue() {
|
||||
return new ImmutableCompoundTypeBuilder();
|
||||
}
|
||||
};
|
||||
|
||||
private final Map<Class<?>, Entry> entryMap = new HashMap<Class<?>, Entry>();
|
||||
private final Map<Class<?>, Entry> entryMap = new HashMap<Class<?>, Entry>();
|
||||
|
||||
/**
|
||||
* Clear the cache of partial compound objects.
|
||||
*/
|
||||
public static void clear() {
|
||||
local.get().entryMap.clear();
|
||||
/**
|
||||
* 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>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 set(String propName, Object value) {
|
||||
// collect the values...
|
||||
valueMap.put(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);
|
||||
}
|
||||
// when got all the values this returns the
|
||||
// compound value, otherwise null
|
||||
return ct.create(valueMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class LongToTimestampConverter implements ScalarTypeConverter<Long, Timestamp> {
|
||||
|
||||
public Long getNullValue() {
|
||||
|
||||
@@ -167,7 +167,7 @@ public class ModifyAwareList<E> implements List<E>, ModifyAwareOwner {
|
||||
|
||||
@Override
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
return new ModifyAwareList<E>(owner,list.subList(fromIndex, toIndex));
|
||||
return new ModifyAwareList<E>(owner, list.subList(fromIndex, toIndex));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> {
|
||||
if (valueType.equals(String.class)) {
|
||||
return STRING;
|
||||
}
|
||||
throw new IllegalArgumentException("Type ["+valueType+"] not supported for @DbArray mapping");
|
||||
throw new IllegalArgumentException("Type [" + valueType + "] not supported for @DbArray mapping");
|
||||
}
|
||||
|
||||
private final String arrayType;
|
||||
@@ -67,7 +67,7 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> {
|
||||
* Return the DB column definition for DDL generation.
|
||||
*/
|
||||
public String getDbColumnDefn() {
|
||||
return arrayType+"[]";
|
||||
return arrayType + "[]";
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -86,7 +86,7 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> {
|
||||
@Override
|
||||
public List read(DataReader reader) throws SQLException {
|
||||
Array array = reader.getArray();
|
||||
return fromArray((Object[])array.getArray());
|
||||
return fromArray((Object[]) array.getArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,7 +112,7 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> {
|
||||
try {
|
||||
return EJson.parseList(value, false);
|
||||
} catch (IOException e) {
|
||||
throw new PersistenceException("Failed to parse JSON content as List: ["+value+"]", e);
|
||||
throw new PersistenceException("Failed to parse JSON content as List: [" + value + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -212,12 +212,12 @@ public class ScalarTypeBoolean {
|
||||
|
||||
@Override
|
||||
public String getDbFalseLiteral() {
|
||||
return "'"+falseValue+"'";
|
||||
return "'" + falseValue + "'";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDbTrueLiteral() {
|
||||
return "'"+trueValue+"'";
|
||||
return "'" + trueValue + "'";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInput;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for char.
|
||||
*/
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
/**
|
||||
* ScalarType for char[].
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for String.
|
||||
*/
|
||||
public class ScalarTypeClob extends ScalarTypeBaseVarchar<String> {
|
||||
|
||||
|
||||
protected ScalarTypeClob(boolean jdbcNative, int jdbcType) {
|
||||
super(String.class, jdbcNative, jdbcType);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
/**
|
||||
* ScalarType for java.sql.Date.
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ScalarTypeDayOfWeek extends ScalarTypeEnumWithMapping {
|
||||
b.setNull(Types.INTEGER);
|
||||
} else {
|
||||
// avoiding the map lookup
|
||||
b.setInt(((DayOfWeek)value).getValue());
|
||||
b.setInt(((DayOfWeek) value).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.avaje.ebean.text.TextException;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
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;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
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;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
/**
|
||||
* ScalarType for java.net.URI which converts to and from a VARCHAR database column.
|
||||
*/
|
||||
|
||||
@@ -47,13 +47,13 @@ public class ScalarTypeInstant extends ScalarTypeBaseDateTime<Instant> {
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Timestamp) return value;
|
||||
if (value instanceof Timestamp) return value;
|
||||
return convertToTimestamp((Instant) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant toBeanType(Object value) {
|
||||
if (value instanceof Instant) return (Instant) value;
|
||||
if (value instanceof Instant) return (Instant) value;
|
||||
return convertFromTimestamp((Timestamp) value);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import org.joda.time.DateMidnight;
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import org.joda.time.LocalDateTime;
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ abstract class ScalarTypeJsonCollection<T> extends ScalarTypeBase<T> {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public T toBeanType(Object value) {
|
||||
return (T)value;
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,15 +15,17 @@ import java.util.List;
|
||||
/**
|
||||
* Types for mapping List in JSON format to DB types VARCHAR, JSON and JSONB.
|
||||
*/
|
||||
public class ScalarTypeJsonList {
|
||||
public class ScalarTypeJsonList {
|
||||
/**
|
||||
* Return the appropriate ScalarType based requested dbType and if Postgres.
|
||||
*/
|
||||
public static ScalarType<?> typeFor(boolean postgres, int dbType, DocPropertyType docType) {
|
||||
if (postgres) {
|
||||
switch (dbType) {
|
||||
case DbType.JSONB: return new ScalarTypeJsonList.JsonB(docType);
|
||||
case DbType.JSON: return new ScalarTypeJsonList.Json(docType);
|
||||
case DbType.JSONB:
|
||||
return new ScalarTypeJsonList.JsonB(docType);
|
||||
case DbType.JSON:
|
||||
return new ScalarTypeJsonList.Json(docType);
|
||||
}
|
||||
}
|
||||
return new ScalarTypeJsonList.Varchar(docType);
|
||||
@@ -71,7 +73,7 @@ public class ScalarTypeJsonList {
|
||||
// parse JSON into modifyAware list
|
||||
return EJson.parseList(dataReader.getString(), true);
|
||||
} catch (IOException e) {
|
||||
throw new SQLException("Failed to parse JSON content as List: ["+ dataReader.getString() +"]", e);
|
||||
throw new SQLException("Failed to parse JSON content as List: [" + dataReader.getString() + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +107,7 @@ public class ScalarTypeJsonList {
|
||||
try {
|
||||
return EJson.parseList(value, false);
|
||||
} catch (IOException e) {
|
||||
throw new PersistenceException("Failed to parse JSON content as List: ["+value+"]", e);
|
||||
throw new PersistenceException("Failed to parse JSON content as List: [" + value + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,13 +35,18 @@ public abstract class ScalarTypeJsonMap extends ScalarTypeBase<Map> {
|
||||
public static ScalarTypeJsonMap typeFor(boolean postgres, int dbType) {
|
||||
|
||||
switch (dbType) {
|
||||
case Types.VARCHAR : return VARCHAR;
|
||||
case Types.BLOB: return BLOB;
|
||||
case Types.CLOB : return CLOB;
|
||||
case DbType.JSONB: return postgres ? JSONB : CLOB;
|
||||
case DbType.JSON: return postgres ? JSON : CLOB;
|
||||
case Types.VARCHAR:
|
||||
return VARCHAR;
|
||||
case Types.BLOB:
|
||||
return BLOB;
|
||||
case Types.CLOB:
|
||||
return CLOB;
|
||||
case DbType.JSONB:
|
||||
return postgres ? JSONB : CLOB;
|
||||
case DbType.JSON:
|
||||
return postgres ? JSON : CLOB;
|
||||
default:
|
||||
throw new IllegalStateException("Unknown dbType "+dbType);
|
||||
throw new IllegalStateException("Unknown dbType " + dbType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,8 +45,10 @@ public class ScalarTypeJsonObjectMapper {
|
||||
private static String getPostgresType(boolean postgres, int dbType) {
|
||||
if (postgres) {
|
||||
switch (dbType) {
|
||||
case DbType.JSON : return PostgresHelper.JSON_TYPE;
|
||||
case DbType.JSONB : return PostgresHelper.JSONB_TYPE;
|
||||
case DbType.JSON:
|
||||
return PostgresHelper.JSON_TYPE;
|
||||
case DbType.JSONB:
|
||||
return PostgresHelper.JSONB_TYPE;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -25,8 +25,10 @@ public class ScalarTypeJsonSet {
|
||||
public static ScalarType<?> typeFor(boolean postgres, int dbType, DocPropertyType docPropertyType) {
|
||||
if (postgres) {
|
||||
switch (dbType) {
|
||||
case DbType.JSONB: return new ScalarTypeJsonSet.JsonB(docPropertyType);
|
||||
case DbType.JSON: return new ScalarTypeJsonSet.Json(docPropertyType);
|
||||
case DbType.JSONB:
|
||||
return new ScalarTypeJsonSet.JsonB(docPropertyType);
|
||||
case DbType.JSON:
|
||||
return new ScalarTypeJsonSet.Json(docPropertyType);
|
||||
}
|
||||
}
|
||||
return new ScalarTypeJsonSet.Varchar(docPropertyType);
|
||||
@@ -74,7 +76,7 @@ public class ScalarTypeJsonSet {
|
||||
// parse JSON into modifyAware list
|
||||
return EJson.parseSet(dataReader.getString(), true);
|
||||
} catch (IOException e) {
|
||||
throw new SQLException("Failed to parse JSON content as List: ["+ dataReader.getString() +"]", e);
|
||||
throw new SQLException("Failed to parse JSON content as List: [" + dataReader.getString() + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +110,7 @@ public class ScalarTypeJsonSet {
|
||||
try {
|
||||
return convertList(EJson.parseList(value));
|
||||
} catch (IOException e) {
|
||||
throw new PersistenceException("Failed to parse JSON content as Set: ["+value+"]", e);
|
||||
throw new PersistenceException("Failed to parse JSON content as Set: [" + value + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,12 +49,12 @@ public class ScalarTypeLocalDateTime extends ScalarTypeBaseDateTime<LocalDateTim
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
if (value instanceof Timestamp) return value;
|
||||
return convertToTimestamp((LocalDateTime)value);
|
||||
return convertToTimestamp((LocalDateTime) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDateTime toBeanType(Object value) {
|
||||
if (value instanceof LocalDateTime) return (LocalDateTime)value;
|
||||
return convertFromTimestamp((Timestamp)value);
|
||||
if (value instanceof LocalDateTime) return (LocalDateTime) value;
|
||||
return convertFromTimestamp((Timestamp) value);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
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;
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.avaje.ebeaninternal.server.type;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
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;
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
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;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.text.TextException;
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebean.config.JsonConfig;
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
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;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.Encryptor;
|
||||
|
||||
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;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
* Simple AES based encryption and decryption.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
|
||||
<TITLE>Scalar Type support</TITLE>
|
||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
|
||||
<TITLE>Scalar Type support</TITLE>
|
||||
</HEAD>
|
||||
<Body BGCOLOR="#ffffff">
|
||||
Built in and custom Scalar types support.
|
||||
|
||||
Reference in new issue
Block a user