mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
#2220 - DDL generation of nullable columns expected with nullable Embedded containing non null properties
This commit is contained in:
1 parent
2d719c5b37
commit
bb6ff866c7
7 files changed
+19
-13
No files matched your search
+1
-1
@@ -72,7 +72,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.ebean</groupId>
|
<groupId>io.ebean</groupId>
|
||||||
<artifactId>ebean-ddl-generator</artifactId>
|
<artifactId>ebean-ddl-generator</artifactId>
|
||||||
<version>12.6.1</version>
|
<version>12.8.4a</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -81,18 +81,18 @@ class BeanPropertyAssocManySqlHelp<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitOneImported(BeanPropertyAssocOne<?> p) {
|
public void visitOneImported(BeanPropertyAssocOne<?> p) {
|
||||||
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitScalar(BeanProperty p) {
|
public void visitScalar(BeanProperty p, boolean allowNonNull) {
|
||||||
sb.append(",").append(p.getDbColumn());
|
sb.append(",").append(p.getDbColumn());
|
||||||
colCount++;
|
colCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitEnd() {
|
public void visitEnd() {
|
||||||
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -44,9 +44,11 @@ public abstract class BaseTablePropertyVisitor implements BeanPropertyVisitor {
|
|||||||
public abstract void visitOneImported(BeanPropertyAssocOne<?> p);
|
public abstract void visitOneImported(BeanPropertyAssocOne<?> p);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this method for normal scalar property.
|
* Override this method for normal scalar property. With allowNonNull
|
||||||
|
* used with properties of Embedded beans that can only be Nonnull when
|
||||||
|
* the Embedded bean is Nonnull.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public abstract void visitScalar(BeanProperty p);
|
public abstract void visitScalar(BeanProperty p, boolean allowNonNull);
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-2
@@ -40,8 +40,8 @@ public interface BeanPropertyVisitor {
|
|||||||
void visitEmbeddedScalar(BeanProperty p, BeanPropertyAssocOne<?> embedded);
|
void visitEmbeddedScalar(BeanProperty p, BeanPropertyAssocOne<?> embedded);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visit a scalar property.
|
* Visit a scalar property specify allowing non-null (e.g. embedded bean scalar properties).
|
||||||
*/
|
*/
|
||||||
void visitScalar(BeanProperty p);
|
void visitScalar(BeanProperty p, boolean allowNonNull);
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -72,7 +72,7 @@ public class VisitProperties {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// simple scalar type
|
// simple scalar type
|
||||||
pv.visitScalar(p);
|
pv.visitScalar(p, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
package org.tests.model.embedded;
|
package org.tests.model.embedded;
|
||||||
|
|
||||||
|
import io.ebean.annotation.NotNull;
|
||||||
|
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public class EEmbDatePeriod {
|
public class EEmbDatePeriod {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
Date date1;
|
Date date1;
|
||||||
|
@NotNull
|
||||||
Date date2;
|
Date date2;
|
||||||
|
|
||||||
public Date getDate1() {
|
public Date getDate1() {
|
||||||
|
|||||||
+4
-4
@@ -175,7 +175,8 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
|||||||
if (p instanceof BeanPropertyAssocOne) {
|
if (p instanceof BeanPropertyAssocOne) {
|
||||||
visitOneImported((BeanPropertyAssocOne<?>)p);
|
visitOneImported((BeanPropertyAssocOne<?>)p);
|
||||||
} else {
|
} else {
|
||||||
visitScalar(p);
|
// only allow Nonnull if embedded is Nonnull
|
||||||
|
visitScalar(p, !embedded.isNullable());
|
||||||
}
|
}
|
||||||
if (embedded.isId()) {
|
if (embedded.isId()) {
|
||||||
// compound primary key
|
// compound primary key
|
||||||
@@ -259,8 +260,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitScalar(BeanProperty p) {
|
public void visitScalar(BeanProperty p, boolean allowNonNull) {
|
||||||
|
|
||||||
if (p.isSecondaryTable()) {
|
if (p.isSecondaryTable()) {
|
||||||
lastColumn = null;
|
lastColumn = null;
|
||||||
return;
|
return;
|
||||||
@@ -292,7 +292,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
col.setDefaultValue(p.getDbColumnDefault());
|
col.setDefaultValue(p.getDbColumnDefault());
|
||||||
if (!p.isNullable() || p.isDDLNotNull()) {
|
if (allowNonNull && (!p.isNullable() || p.isDDLNotNull())) {
|
||||||
col.setNotnull(true);
|
col.setNotnull(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user