mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-24 03:57:45 +00:00
#999 - @DiscriminatorColumn columnDefinition is ignored for DDL generation
This commit is contained in:
@@ -53,10 +53,12 @@ public class ModelBuildBeanVisitor implements BeanVisitor {
|
||||
if (inheritInfo != null && inheritInfo.isRoot()) {
|
||||
// add the discriminator column
|
||||
String discColumn = inheritInfo.getDiscriminatorColumn();
|
||||
DbPlatformType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType());
|
||||
String discDbType = dbType.renderType(inheritInfo.getDiscriminatorLength(), 0);
|
||||
|
||||
table.addColumn(new MColumn(discColumn, discDbType, true));
|
||||
String columnDefn = inheritInfo.getColumnDefn();
|
||||
if (columnDefn == null || columnDefn.isEmpty()) {
|
||||
DbPlatformType dbType = ctx.getDbTypeMap().get(inheritInfo.getDiscriminatorType());
|
||||
columnDefn = dbType.renderType(inheritInfo.getDiscriminatorLength(), 0);
|
||||
}
|
||||
table.addColumn(new MColumn(discColumn, columnDefn, true));
|
||||
}
|
||||
|
||||
return new ModelBuildPropertyVisitor(ctx, table, descriptor);
|
||||
|
||||
@@ -26,6 +26,8 @@ public class InheritInfo {
|
||||
|
||||
private final int discriminatorLength;
|
||||
|
||||
private final String columnDefn;
|
||||
|
||||
private final String where;
|
||||
|
||||
private final Class<?> type;
|
||||
@@ -58,6 +60,7 @@ public class InheritInfo {
|
||||
|
||||
this.discriminatorType = deploy.getDiscriminatorType(parent);
|
||||
this.discriminatorLength = deploy.getDiscriminatorLength(parent);
|
||||
this.columnDefn = deploy.getColumnDefn();
|
||||
this.where = InternString.intern(deploy.getWhere());
|
||||
|
||||
if (r == null) {
|
||||
@@ -164,14 +167,14 @@ public class InheritInfo {
|
||||
public BeanProperty[] localProperties() {
|
||||
return descriptor.propertiesLocal();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the children.
|
||||
*/
|
||||
public ArrayList<InheritInfo> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the bean property additionally looking in the sub types.
|
||||
*/
|
||||
@@ -342,6 +345,13 @@ public class InheritInfo {
|
||||
return discriminatorLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the explicit column definition.
|
||||
*/
|
||||
public String getColumnDefn() {
|
||||
return columnDefn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the discriminator value for this node.
|
||||
*/
|
||||
|
||||
@@ -126,6 +126,7 @@ public class DeployInherit {
|
||||
info.setDiscriminatorType(Types.VARCHAR);
|
||||
}
|
||||
info.setDiscriminatorLength(da.length());
|
||||
info.setColumnDefn(da.columnDefinition());
|
||||
}
|
||||
|
||||
DiscriminatorValue dv = AnnotationBase.findAnnotation(cls, DiscriminatorValue.class);
|
||||
|
||||
@@ -26,6 +26,8 @@ public class DeployInheritInfo {
|
||||
|
||||
private String discriminatorColumn;
|
||||
|
||||
private String columnDefn;
|
||||
|
||||
private String discriminatorWhere;
|
||||
|
||||
private final Class<?> type;
|
||||
@@ -157,6 +159,20 @@ public class DeployInheritInfo {
|
||||
this.discriminatorType = discriminatorType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set explicit column definition (ddl).
|
||||
*/
|
||||
public void setColumnDefn(String columnDefn) {
|
||||
this.columnDefn = columnDefn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the explicit column definition.
|
||||
*/
|
||||
public String getColumnDefn() {
|
||||
return columnDefn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the length of the discriminator column.
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.config.DbConstraintNaming;
|
||||
import io.ebean.dbmigration.ddlgeneration.platform.DefaultConstraintMaxLength;
|
||||
import io.ebean.dbmigration.model.MColumn;
|
||||
import io.ebean.dbmigration.model.MTable;
|
||||
import io.ebean.dbmigration.model.ModelContainer;
|
||||
import io.ebean.dbmigration.model.visitor.VisitAllUsing;
|
||||
@@ -31,12 +32,41 @@ public class ModelBuildBeanVisitorTest extends BaseTestCase {
|
||||
|
||||
new VisitAllUsing(addTable, defaultServer).visitAllBeans();
|
||||
|
||||
assert_compound_pk(model);
|
||||
|
||||
assert_discriminatorColumn_explicit(model);
|
||||
assert_discriminatorColumn_implied(model);
|
||||
assert_discriminatorColumn_length(model);
|
||||
}
|
||||
|
||||
private void assert_compound_pk(ModelContainer model) {
|
||||
MTable item = model.getTable("item");
|
||||
|
||||
assertThat(item).isNotNull();
|
||||
assertThat(item.primaryKeyColumns()).hasSize(2);
|
||||
}
|
||||
|
||||
MTable customer = model.getTable("o_customer");
|
||||
assertThat(customer).isNotNull();
|
||||
private void assert_discriminatorColumn_explicit(ModelContainer model) {
|
||||
|
||||
MTable configuration = model.getTable("configuration");
|
||||
MColumn discTypeColumn = configuration.getColumn("type");
|
||||
assertThat(discTypeColumn.getType()).isEqualTo("varchar(21)");
|
||||
assertThat(discTypeColumn.isNotnull()).isTrue();
|
||||
}
|
||||
|
||||
private void assert_discriminatorColumn_implied(ModelContainer model) {
|
||||
|
||||
MTable configuration = model.getTable("bar");
|
||||
MColumn discTypeColumn = configuration.getColumn("bar_type");
|
||||
assertThat(discTypeColumn.getType()).isEqualTo("varchar(31)");
|
||||
assertThat(discTypeColumn.isNotnull()).isTrue();
|
||||
}
|
||||
|
||||
private void assert_discriminatorColumn_length(ModelContainer model) {
|
||||
|
||||
MTable configuration = model.getTable("vehicle");
|
||||
MColumn discTypeColumn = configuration.getColumn("dtype");
|
||||
assertThat(discTypeColumn.getType()).isEqualTo("varchar(3)");
|
||||
assertThat(discTypeColumn.isNotnull()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@ import javax.persistence.*;
|
||||
@Entity
|
||||
@Cache(enableQueryCache = true)
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, columnDefinition = "varchar(21)")
|
||||
public class Configuration extends AbstractBaseClass {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
Reference in New Issue
Block a user