mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
#513 - Column Constraint for Enum types should cover all Enum values in an inheritance hierachy
This commit is contained in:
1 parent
4606c7c99f
commit
db8dd48e53
9 files changed
+133
-70
No files matched your search
@@ -6,11 +6,9 @@ import com.avaje.ebean.bean.PersistenceContext;
|
||||
import com.avaje.ebean.config.EncryptKey;
|
||||
import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
|
||||
import com.avaje.ebean.config.dbplatform.DbType;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocMappingBuilder;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyMapping;
|
||||
import com.avaje.ebean.plugin.Property;
|
||||
import com.avaje.ebean.text.StringParser;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedProperty;
|
||||
import com.avaje.ebeaninternal.server.deploy.generatedproperty.GeneratedWhenCreated;
|
||||
@@ -28,7 +26,10 @@ import com.avaje.ebeaninternal.server.text.json.WriteJson;
|
||||
import com.avaje.ebeaninternal.server.type.DataBind;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarType;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarTypeBoolean;
|
||||
import com.avaje.ebeaninternal.server.type.ScalarTypeEnum;
|
||||
import com.avaje.ebeaninternal.util.ValueUtil;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocMappingBuilder;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyMapping;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyOptions;
|
||||
import com.avaje.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.avaje.ebeanservice.docstore.api.support.DocStructure;
|
||||
@@ -45,6 +46,7 @@ import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Description of a property of a bean. Includes its deployment information such
|
||||
@@ -231,11 +233,6 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
*/
|
||||
final String dbComment;
|
||||
|
||||
/**
|
||||
* DB Constraint (typically check constraint on enum)
|
||||
*/
|
||||
final String dbConstraintExpression;
|
||||
|
||||
final DbEncryptFunction dbEncryptFunction;
|
||||
|
||||
int deployOrder;
|
||||
@@ -304,7 +301,6 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
this.dbLength = deploy.getDbLength();
|
||||
this.dbScale = deploy.getDbScale();
|
||||
this.dbColumnDefn = InternString.intern(deploy.getDbColumnDefn());
|
||||
this.dbConstraintExpression = InternString.intern(deploy.getDbConstraintExpression());
|
||||
this.dbColumnDefault = deploy.getDbColumnDefault();
|
||||
|
||||
this.inherited = false;// deploy.isInherited();
|
||||
@@ -414,7 +410,6 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
this.dbLength = source.getDbLength();
|
||||
this.dbScale = source.getDbScale();
|
||||
this.dbColumnDefn = InternString.intern(source.getDbColumnDefn());
|
||||
this.dbConstraintExpression = InternString.intern(source.getDbConstraintExpression());
|
||||
this.dbColumnDefault = source.dbColumnDefault;
|
||||
|
||||
this.inherited = source.isInherited();
|
||||
@@ -977,8 +972,11 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
* For an Enum returns IN expression for the set of Enum values.
|
||||
* </p>
|
||||
*/
|
||||
public String getDbConstraintExpression() {
|
||||
return dbConstraintExpression;
|
||||
public Set<String> getDbCheckConstraintValues() {
|
||||
if (scalarType instanceof ScalarTypeEnum) {
|
||||
return ((ScalarTypeEnum) scalarType).getDbCheckConstraintValues();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
@@ -88,6 +89,25 @@ public class InheritInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append check constraint values for the entire inheritance hierarchy.
|
||||
*/
|
||||
public void appendCheckConstraintValues(final String propertyName, final Set<String> checkConstraintValues) {
|
||||
|
||||
visitChildren(new InheritInfoVisitor() {
|
||||
@Override
|
||||
public void visit(InheritInfo inheritInfo) {
|
||||
BeanProperty prop = inheritInfo.desc().getBeanProperty(propertyName);
|
||||
if (prop != null) {
|
||||
Set<String> values = prop.getDbCheckConstraintValues();
|
||||
if (values != null) {
|
||||
checkConstraintValues.addAll(values);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* return true if anything in the inheritance hierarchy has a relationship with a save cascade on
|
||||
* it.
|
||||
|
||||
@@ -393,17 +393,6 @@ public class DeployBeanProperty {
|
||||
}
|
||||
}
|
||||
|
||||
public String getDbConstraintExpression() {
|
||||
if (scalarType instanceof ScalarTypeEnum) {
|
||||
// create a check constraint for the enum
|
||||
ScalarTypeEnum etype = (ScalarTypeEnum) scalarType;
|
||||
|
||||
// check dbColName IN ('A', 'I', 'D')
|
||||
return "check (" + dbColumn + " in " + etype.getConstraintInValues() + ")";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scalarType. This returns null for native JDBC types, otherwise
|
||||
* it is used to convert between logical types and jdbc types.
|
||||
|
||||
Reference in new issue
Block a user