#1818 - Cannot auto-generate UUID

This commit is contained in:
rob bygrave
2019-09-12 22:02:22 +12:00
parent a2b418df8b
commit c12ea28ea9
5 changed files with 126 additions and 5 deletions
@@ -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.
*/
@@ -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();