mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#946 - Treat primitive numbers (long, int, short, float, double) as NOT NULL wrt DDL generation
This commit is contained in:
@@ -176,7 +176,7 @@ public class PlatformDdl {
|
||||
buffer.append(" ");
|
||||
buffer.append(lowerColumnName(column.getName()), 29);
|
||||
buffer.append(platformType);
|
||||
if (!typeContainsDefault(platformType)) {
|
||||
if (!Boolean.TRUE.equals(column.isPrimaryKey()) && !typeContainsDefault(platformType)) {
|
||||
String defaultValue = convertDefaultValue(column.getDefaultValue());
|
||||
if (defaultValue != null) {
|
||||
buffer.append(" default ").append(defaultValue);
|
||||
|
||||
@@ -221,7 +221,6 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
// using non-strict mode to render the DB type such that we have a
|
||||
// "logical" type like jsonb(200) that can map to JSONB or VARCHAR(200)
|
||||
MColumn col = new MColumn(p.getDbColumn(), ctx.getColumnDefn(p, false));
|
||||
col.setDefaultValue(p.getDbColumnDefault());
|
||||
col.setComment(p.getDbComment());
|
||||
col.setDraftOnly(p.isDraftOnly());
|
||||
col.setHistoryExclude(p.isExcludedFromHistory());
|
||||
@@ -231,8 +230,11 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
if (p.getBeanDescriptor().isUseIdGenerator()) {
|
||||
col.setIdentity(true);
|
||||
}
|
||||
} else if (!p.isNullable() || p.isDDLNotNull()) {
|
||||
col.setNotnull(true);
|
||||
} else {
|
||||
col.setDefaultValue(p.getDbColumnDefault());
|
||||
if (!p.isNullable() || p.isDDLNotNull()) {
|
||||
col.setNotnull(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (p.isUnique() && !p.isId()) {
|
||||
|
||||
@@ -34,6 +34,8 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.sql.Types;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Description of a property of a bean. Includes its deployment information such
|
||||
@@ -45,6 +47,14 @@ public class DeployBeanProperty {
|
||||
private static final int UNIDIRECTIONAL_ORDER = 100000;
|
||||
private static final int AUDITCOLUMN_ORDER = -1000000;
|
||||
private static final int VERSIONCOLUMN_ORDER = -1000000;
|
||||
private static final Set<Class<?>> PRIMITIVE_NUMBER_TYPES = new HashSet<>();
|
||||
static {
|
||||
PRIMITIVE_NUMBER_TYPES.add(float.class);
|
||||
PRIMITIVE_NUMBER_TYPES.add(double.class);
|
||||
PRIMITIVE_NUMBER_TYPES.add(long.class);
|
||||
PRIMITIVE_NUMBER_TYPES.add(int.class);
|
||||
PRIMITIVE_NUMBER_TYPES.add(short.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag to mark this at part of the unique id.
|
||||
@@ -940,6 +950,9 @@ public class DeployBeanProperty {
|
||||
if (boolean.class.equals(propertyType) && !softDelete) {
|
||||
this.nullable = false;
|
||||
this.dbColumnDefault = DbDefaultValue.FALSE;
|
||||
|
||||
} else if (!id && !versionColumn && PRIMITIVE_NUMBER_TYPES.contains(propertyType)) {
|
||||
this.nullable = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user