mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#615 - ENH: Change DDL generation with @SoftDelete to add 'default false' to column definition
This commit is contained in:
@@ -219,6 +219,11 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
*/
|
||||
final String dbColumnDefn;
|
||||
|
||||
/**
|
||||
* DB Column default value for DDL definition (FALSE, NOW etc).
|
||||
*/
|
||||
final String dbColumnDefault;
|
||||
|
||||
/**
|
||||
* Database DDL column comment.
|
||||
*/
|
||||
@@ -298,6 +303,7 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
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();
|
||||
this.owningType = deploy.getOwningType();
|
||||
@@ -407,6 +413,7 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
this.dbScale = source.getDbScale();
|
||||
this.dbColumnDefn = InternString.intern(source.getDbColumnDefn());
|
||||
this.dbConstraintExpression = InternString.intern(source.getDbConstraintExpression());
|
||||
this.dbColumnDefault = source.dbColumnDefault;
|
||||
|
||||
this.inherited = source.isInherited();
|
||||
this.owningType = source.owningType;
|
||||
@@ -945,6 +952,13 @@ public class BeanProperty implements ElPropertyValue, Property {
|
||||
return dbType.renderType(dbLength, dbScale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB column default to use for DDL.
|
||||
*/
|
||||
public String getDbColumnDefault() {
|
||||
return dbColumnDefn != null ? null : dbColumnDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bean Field associated with this property.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.avaje.ebean.annotation.WhenModified;
|
||||
import com.avaje.ebean.annotation.WhoCreated;
|
||||
import com.avaje.ebean.annotation.WhoModified;
|
||||
import com.avaje.ebean.config.ScalarTypeConverter;
|
||||
import com.avaje.ebean.config.dbplatform.DbDefaultValue;
|
||||
import com.avaje.ebean.config.dbplatform.DbEncrypt;
|
||||
import com.avaje.ebean.config.dbplatform.DbEncryptFunction;
|
||||
import com.avaje.ebeaninternal.server.core.InternString;
|
||||
@@ -202,6 +203,8 @@ public class DeployBeanProperty {
|
||||
|
||||
private String dbComment;
|
||||
|
||||
private String dbColumnDefault;
|
||||
|
||||
public DeployBeanProperty(DeployBeanDescriptor<?> desc, Class<?> propertyType, ScalarType<?> scalarType, ScalarTypeConverter<?, ?> typeConverter) {
|
||||
this.desc = desc;
|
||||
this.propertyType = propertyType;
|
||||
@@ -902,6 +905,7 @@ public class DeployBeanProperty {
|
||||
public void setSoftDelete() {
|
||||
this.softDelete = true;
|
||||
this.nullable = false;
|
||||
this.dbColumnDefault = DbDefaultValue.FALSE;
|
||||
}
|
||||
|
||||
public boolean isSoftDelete() {
|
||||
@@ -932,4 +936,7 @@ public class DeployBeanProperty {
|
||||
return docMapping.create();
|
||||
}
|
||||
|
||||
public String getDbColumnDefault() {
|
||||
return dbColumnDefault;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class DefaultTypeFactory {
|
||||
this.serverConfig = serverConfig;
|
||||
}
|
||||
|
||||
protected ScalarType<Boolean> createBoolean(String trueValue, String falseValue) {
|
||||
protected ScalarTypeBool createBoolean(String trueValue, String falseValue) {
|
||||
|
||||
try {
|
||||
// first try Integer based boolean
|
||||
@@ -40,7 +40,7 @@ public class DefaultTypeFactory {
|
||||
* native data type and for others Booleans will be converted to Y/N or 0/1
|
||||
* etc.
|
||||
*/
|
||||
public ScalarType<Boolean> createBoolean() {
|
||||
public ScalarTypeBool createBoolean() {
|
||||
|
||||
if (serverConfig == null) {
|
||||
return new ScalarTypeBoolean.Native();
|
||||
|
||||
@@ -848,10 +848,14 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
|
||||
ScalarType<?> mathBigIntType = extraTypeFactory.createMathBigInteger();
|
||||
typeMap.put(BigInteger.class, mathBigIntType);
|
||||
|
||||
ScalarType<?> booleanType = extraTypeFactory.createBoolean();
|
||||
ScalarTypeBool booleanType = extraTypeFactory.createBoolean();
|
||||
typeMap.put(Boolean.class, booleanType);
|
||||
typeMap.put(boolean.class, booleanType);
|
||||
|
||||
// register the boolean literals to the platform for DDL default values
|
||||
databasePlatform.setDbTrueLiteral(booleanType.getDbTrueLiteral());
|
||||
databasePlatform.setDbFalseLiteral(booleanType.getDbFalseLiteral());
|
||||
|
||||
// always register Types.BOOLEAN to our boolean type
|
||||
nativeMap.put(Types.BOOLEAN, booleanType);
|
||||
if (booleanType.getJdbcType() == Types.BIT) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.avaje.ebeaninternal.server.type;
|
||||
|
||||
/**
|
||||
* Boolean ScalarType's must implement to support DDL default values etc.
|
||||
*/
|
||||
public interface ScalarTypeBool extends ScalarType<Boolean> {
|
||||
|
||||
/**
|
||||
* Return the DB literal value for FALSE.
|
||||
*/
|
||||
String getDbFalseLiteral();
|
||||
|
||||
/**
|
||||
* Return the DB literal value for TRUE.
|
||||
*/
|
||||
String getDbTrueLiteral();
|
||||
}
|
||||
@@ -70,12 +70,12 @@ public class ScalarTypeBoolean {
|
||||
* type.boolean.dbtype="bit" in the ebean configuration
|
||||
* </p>
|
||||
*/
|
||||
public static class BitBoolean extends BooleanBase {
|
||||
static class BitBoolean extends BooleanBase {
|
||||
|
||||
/**
|
||||
* Native Boolean database type.
|
||||
*/
|
||||
public BitBoolean() {
|
||||
BitBoolean() {
|
||||
super(true, Types.BIT);
|
||||
}
|
||||
|
||||
@@ -116,12 +116,12 @@ public class ScalarTypeBoolean {
|
||||
/**
|
||||
* Converted to/from an Integer in the Database.
|
||||
*/
|
||||
public static class IntBoolean extends BooleanBase {
|
||||
static class IntBoolean extends BooleanBase {
|
||||
|
||||
private final Integer trueValue;
|
||||
private final Integer falseValue;
|
||||
|
||||
public IntBoolean(Integer trueValue, Integer falseValue) {
|
||||
IntBoolean(Integer trueValue, Integer falseValue) {
|
||||
super(false, Types.INTEGER);
|
||||
this.trueValue = trueValue;
|
||||
this.falseValue = falseValue;
|
||||
@@ -169,7 +169,7 @@ public class ScalarTypeBoolean {
|
||||
/**
|
||||
* Convert the Boolean value to the db value.
|
||||
*/
|
||||
public Integer toInteger(Object value) {
|
||||
Integer toInteger(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -199,12 +199,12 @@ public class ScalarTypeBoolean {
|
||||
/**
|
||||
* Converted to/from an Integer in the Database.
|
||||
*/
|
||||
public static class StringBoolean extends BooleanBase {
|
||||
static class StringBoolean extends BooleanBase {
|
||||
|
||||
private final String trueValue;
|
||||
private final String falseValue;
|
||||
|
||||
public StringBoolean(String trueValue, String falseValue) {
|
||||
StringBoolean(String trueValue, String falseValue) {
|
||||
super(false, Types.VARCHAR);
|
||||
this.trueValue = trueValue;
|
||||
this.falseValue = falseValue;
|
||||
@@ -280,9 +280,9 @@ public class ScalarTypeBoolean {
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class BooleanBase extends ScalarTypeBase<Boolean> {
|
||||
public static abstract class BooleanBase extends ScalarTypeBase<Boolean> implements ScalarTypeBool {
|
||||
|
||||
public BooleanBase(boolean jdbcNative, int jdbcType) {
|
||||
BooleanBase(boolean jdbcNative, int jdbcType) {
|
||||
super(Boolean.class, jdbcNative, jdbcType);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user