mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 15:55:55 +00:00
#586 - Refactor the UUID ScalarTypes (Native, Varchar and Binary) to have a common base
This commit is contained in:
@@ -84,9 +84,4 @@ public class ScalarTypeEnumWithMapping extends ScalarTypeEnumStandard.EnumBase i
|
||||
return beanDbMap.getDbValue(beanValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocPropertyType getDocType() {
|
||||
return DocPropertyType.STRING;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
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;
|
||||
@@ -48,6 +49,16 @@ public abstract class ScalarTypeUUIDBase extends ScalarTypeBase<UUID> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUUID(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.convert(value, jdbcType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID readData(DataInput dataInput) throws IOException {
|
||||
if (!dataInput.readBoolean()) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
import com.avaje.ebeaninternal.server.core.BasicTypeConverter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
@@ -27,7 +29,11 @@ public class ScalarTypeUUIDBinary extends ScalarTypeUUIDBase {
|
||||
|
||||
@Override
|
||||
public UUID toBeanType(Object value) {
|
||||
return convertFromBytes((byte[]) value);
|
||||
if (value instanceof byte[]) {
|
||||
return convertFromBytes((byte[]) value);
|
||||
} else {
|
||||
return BasicTypeConverter.toUUID(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,9 +33,4 @@ public class ScalarTypeUUIDNative extends ScalarTypeUUIDBase {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID toBeanType(Object value) {
|
||||
return (UUID) value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
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.
|
||||
*/
|
||||
@@ -20,16 +18,6 @@ public class ScalarTypeUUIDVarchar extends ScalarTypeUUIDBase {
|
||||
return 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID toBeanType(Object value) {
|
||||
return BasicTypeConverter.toUUID(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object toJdbcType(Object value) {
|
||||
return BasicTypeConverter.convert(value, jdbcType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(DataBind b, UUID value) throws SQLException {
|
||||
if (value == null) {
|
||||
|
||||
Reference in New Issue
Block a user