mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1818 - Cannot auto-generate UUID
This commit is contained in:
+6
@@ -27,6 +27,8 @@ public class GeneratedPropertyFactory {
|
||||
|
||||
private final HashSet<String> numberTypes = new HashSet<>();
|
||||
|
||||
private final UuidGeneratedProperty generatedUuid = new UuidGeneratedProperty();
|
||||
|
||||
private final GeneratedWhoModified generatedWhoModified;
|
||||
|
||||
private final GeneratedWhoCreated generatedWhoCreated;
|
||||
@@ -123,6 +125,10 @@ public class GeneratedPropertyFactory {
|
||||
return idGeneratorMap.get(generatorName);
|
||||
}
|
||||
|
||||
public void setUuid(DeployBeanProperty prop) {
|
||||
prop.setGeneratedProperty(generatedUuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the custom IdGenerator to implement PlatformIdGenerator.
|
||||
*/
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package io.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class UuidGeneratedProperty implements GeneratedProperty {
|
||||
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getUpdateValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInInsert() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDDLNotNullable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean includeInAllUpdates() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -202,12 +202,11 @@ public class AnnotationFields extends AnnotationParser {
|
||||
prop.setDbColumn(dbColumn);
|
||||
}
|
||||
|
||||
Id id = get(prop, Id.class);
|
||||
GeneratedValue gen = get(prop, GeneratedValue.class);
|
||||
if (gen != null) {
|
||||
readGenValue(gen, prop);
|
||||
readGenValue(gen, id, prop);
|
||||
}
|
||||
|
||||
Id id = get(prop, Id.class);
|
||||
if (id != null) {
|
||||
readIdScalar(prop);
|
||||
}
|
||||
@@ -519,8 +518,13 @@ public class AnnotationFields extends AnnotationParser {
|
||||
return util.createDataEncryptSupport(table, column);
|
||||
}
|
||||
|
||||
private void readGenValue(GeneratedValue gen, DeployBeanProperty prop) {
|
||||
|
||||
private void readGenValue(GeneratedValue gen, Id id, DeployBeanProperty prop) {
|
||||
if (id == null) {
|
||||
if (UUID.class.equals(prop.getPropertyType())) {
|
||||
generatedPropFactory.setUuid(prop);
|
||||
return;
|
||||
}
|
||||
}
|
||||
descriptor.setIdGeneratedValue();
|
||||
String genName = gen.generator();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user