mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Fix for #128 - UUID stored as binary(16) rather than varchar(40)
This commit is contained in:
@@ -204,6 +204,12 @@ public class ServerConfig {
|
||||
* Default behaviour for updates when cascade save on a O2M or M2M to delete any missing children.
|
||||
*/
|
||||
private boolean updatesDeleteMissingChildren = true;
|
||||
|
||||
/**
|
||||
* Setting to indicate if UUID should be stored as binary(16) or varchar(40).
|
||||
*/
|
||||
private boolean uuidStoreAsBinary;
|
||||
|
||||
|
||||
private List<BeanPersistController> persistControllers = new ArrayList<BeanPersistController>();
|
||||
private List<BeanPersistListener<?>> persistListeners = new ArrayList<BeanPersistListener<?>>();
|
||||
@@ -796,6 +802,21 @@ public class ServerConfig {
|
||||
this.dbEncrypt = dbEncrypt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if UUID should be stored as binary(16) (as opposed to varchar(40)).
|
||||
*/
|
||||
public boolean isUuidStoreAsBinary() {
|
||||
return uuidStoreAsBinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true if UUID should be stored as binary(16) (as opposed to varchar(40)).
|
||||
*/
|
||||
public void setUuidStoreAsBinary(boolean uuidStoreAsBinary) {
|
||||
this.uuidStoreAsBinary = uuidStoreAsBinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to run the DDL generation on startup.
|
||||
*/
|
||||
@@ -1282,7 +1303,7 @@ public class ServerConfig {
|
||||
|
||||
collectQueryStatsByNode = p.getBoolean("collectQueryStatsByNode", true);
|
||||
collectQueryOrigins = p.getBoolean("collectQueryOrigins", true);
|
||||
|
||||
|
||||
updateChangesOnly = p.getBoolean("updateChangesOnly", true);
|
||||
|
||||
boolean defaultDeleteMissingChildren = p.getBoolean("defaultDeleteMissingChildren", true);
|
||||
@@ -1299,6 +1320,7 @@ public class ServerConfig {
|
||||
databaseBooleanTrue = p.get("databaseBooleanTrue", null);
|
||||
databaseBooleanFalse = p.get("databaseBooleanFalse", null);
|
||||
databasePlatformName = p.get("databasePlatformName", null);
|
||||
uuidStoreAsBinary = p.getBoolean("uuidStoreAsBinary", false);
|
||||
|
||||
lazyLoadBatchSize = p.getInt("lazyLoadBatchSize", 1);
|
||||
queryBatchSize = p.getInt("queryBatchSize", DEFAULT_QUERY_BATCH_SIZE);
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.sql.Types;
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.avaje.ebeaninternal.server.type.ScalarTypeUUIDBinary;
|
||||
|
||||
/**
|
||||
* Default implementation of TypeConverter.
|
||||
@@ -192,6 +193,9 @@ public final class BasicTypeConverter implements Serializable {
|
||||
if (value instanceof String) {
|
||||
return UUID.fromString((String) value);
|
||||
}
|
||||
if (value instanceof byte[]) {
|
||||
return ScalarTypeUUIDBinary.convertFromBytes((byte[])value);
|
||||
}
|
||||
return (UUID) value;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,6 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
|
||||
private final ScalarType<?> timestampType = new ScalarTypeTimestamp();
|
||||
|
||||
private final ScalarType<?> uuidType = new ScalarTypeUUID();
|
||||
private final ScalarType<?> urlType = new ScalarTypeURL();
|
||||
private final ScalarType<?> uriType = new ScalarTypeURI();
|
||||
private final ScalarType<?> localeType = new ScalarTypeLocale();
|
||||
@@ -140,7 +139,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
|
||||
this.extraTypeFactory = new DefaultTypeFactory(config);
|
||||
|
||||
initialiseStandard(clobType, blobType);
|
||||
initialiseStandard(clobType, blobType, config.isUuidStoreAsBinary());
|
||||
initialiseJodaTypes();
|
||||
|
||||
if (bootupClasses != null) {
|
||||
@@ -613,7 +612,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.
|
||||
*/
|
||||
protected void initialiseStandard(int platformClobType, int platformBlobType) {
|
||||
protected void initialiseStandard(int platformClobType, int platformBlobType, boolean binaryUUID) {
|
||||
|
||||
ScalarType<?> utilDateType = extraTypeFactory.createUtilDate();
|
||||
typeMap.put(java.util.Date.class, utilDateType);
|
||||
@@ -637,13 +636,13 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
// boolean mapping to Types.Integer, Types.VARCHAR or Types.Boolean
|
||||
}
|
||||
|
||||
// ScalarTypeScalaDouble scalaDoubleType = new ScalarTypeScalaDouble();
|
||||
// typeMap.put(scala.Double.class, scalaDoubleType);
|
||||
// Store UUID as binary(16) or varchar(40)
|
||||
ScalarType<?> uuidType = (binaryUUID) ? new ScalarTypeUUIDBinary() : new ScalarTypeUUIDVarchar();
|
||||
typeMap.put(UUID.class, uuidType);
|
||||
|
||||
typeMap.put(Locale.class, localeType);
|
||||
typeMap.put(Currency.class, currencyType);
|
||||
typeMap.put(TimeZone.class, timeZoneType);
|
||||
typeMap.put(UUID.class, uuidType);
|
||||
typeMap.put(URL.class, urlType);
|
||||
typeMap.put(URI.class, uriType);
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
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 ScalarTypeUUID extends ScalarTypeBaseVarchar<UUID> {
|
||||
|
||||
public ScalarTypeUUID() {
|
||||
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);
|
||||
}
|
||||
|
||||
public UUID toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUUID(value);
|
||||
}
|
||||
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.convert(value, jdbcType);
|
||||
}
|
||||
|
||||
public String formatValue(UUID v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
public UUID parse(String value) {
|
||||
return UUID.fromString(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
|
||||
public UUID toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUUID(value);
|
||||
}
|
||||
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.convert(value, jdbcType);
|
||||
}
|
||||
|
||||
public String formatValue(UUID v) {
|
||||
return v.toString();
|
||||
}
|
||||
|
||||
public UUID parse(String value) {
|
||||
return UUID.fromString(value);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user