#897 - Remove @EmbeddedColumns ... replace with @Embedded(prefix="...")

This commit is contained in:
Rob Bygrave
2016-11-24 22:05:27 +13:00
parent 7f31104439
commit cc6469851b
8 changed files with 31 additions and 64 deletions
@@ -28,19 +28,21 @@ public class BeanEmbeddedMetaFactory {
}
// deployment override information (column names)
String columnPrefix = prop.getColumnPrefix();
Map<String, String> propColMap = prop.getDeployEmbedded().getPropertyColumnMap();
BeanProperty[] sourceProperties = targetDesc.propertiesBaseScalar();
BeanProperty[] embeddedProperties = new BeanProperty[sourceProperties.length];
for (int i = 0; i < sourceProperties.length; i++) {
String propertyName = sourceProperties[i].getName();
String dbColumn = propColMap.get(propertyName);
if (dbColumn == null) {
// dbColumn not overridden so take original
dbColumn = sourceProperties[i].getDbColumn();
if (columnPrefix != null) {
dbColumn = columnPrefix + dbColumn;
}
}
BeanPropertyOverride overrides = new BeanPropertyOverride(dbColumn);
@@ -13,6 +13,8 @@ public class DeployBeanPropertyAssocOne<T> extends DeployBeanPropertyAssoc<T> {
private DeployBeanEmbedded deployEmbedded;
private String columnPrefix;
/**
* Create the property.
*/
@@ -96,7 +98,7 @@ public class DeployBeanPropertyAssocOne<T> extends DeployBeanPropertyAssoc<T> {
tableJoin.setLocalColumn(dbColumn);
}
}
@Override
public void setSqlFormula(String formulaSelect, String formulaJoin) {
super.setSqlFormula(formulaSelect, formulaJoin);
@@ -105,4 +107,12 @@ public class DeployBeanPropertyAssocOne<T> extends DeployBeanPropertyAssoc<T> {
columns[0].setLocalSqlFormula(formulaSelect);
}
}
public void setColumnPrefix(String columnPrefix) {
this.columnPrefix = columnPrefix;
}
public String getColumnPrefix() {
return columnPrefix;
}
}
@@ -1,7 +1,12 @@
package com.avaje.ebeaninternal.server.deploy.parse;
import java.util.Map;
import java.util.Set;
import com.avaje.ebean.annotation.Where;
import com.avaje.ebean.config.NamingConvention;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
import com.avaje.ebeaninternal.server.deploy.BeanTable;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.query.SqlJoinType;
import javax.persistence.Column;
import javax.persistence.Embedded;
@@ -13,16 +18,6 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import com.avaje.ebean.annotation.EmbeddedColumns;
import com.avaje.ebean.annotation.Where;
import com.avaje.ebean.config.NamingConvention;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
import com.avaje.ebeaninternal.server.deploy.BeanTable;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanProperty;
import com.avaje.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssocOne;
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
import com.avaje.ebeaninternal.server.query.SqlJoinType;
/**
* Read the deployment annotations for Associated One beans.
*/
@@ -62,7 +57,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
}
Embedded embedded = get(prop, Embedded.class);
if (embedded != null) {
readEmbedded(prop);
readEmbedded(prop, embedded);
}
EmbeddedId emId = get(prop, EmbeddedId.class);
if (emId != null) {
@@ -195,7 +190,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
prop.setBeanTable(assoc);
}
private void readEmbedded(DeployBeanPropertyAssocOne<?> prop) {
private void readEmbedded(DeployBeanPropertyAssocOne<?> prop, Embedded embedded) {
if (descriptor.isDocStoreOnly() && prop.getDocStoreDoc() == null) {
prop.setDocStoreEmbedded("");
@@ -203,16 +198,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
prop.setEmbedded();
prop.setDbInsertable(true);
prop.setDbUpdateable(true);
EmbeddedColumns columns = get(prop, EmbeddedColumns.class);
if (columns != null) {
// convert into a Map
String propColumns = columns.columns();
Map<String, String> propMap = StringHelper.delimitedToMap(propColumns, ",", "=");
prop.getDeployEmbedded().putAll(propMap);
}
prop.setColumnPrefix(embedded.prefix());
readEmbeddedAttributeOverrides(prop);
}
@@ -288,27 +288,6 @@ public class AnnotationFields extends AnnotationParser {
}
}
EmbeddedColumns columns = get(prop, EmbeddedColumns.class);
if (columns != null) {
if (prop instanceof DeployBeanPropertyCompound) {
DeployBeanPropertyCompound p = (DeployBeanPropertyCompound) prop;
// convert into a Map
String propColumns = columns.columns();
Map<String, String> propMap = StringHelper.delimitedToMap(propColumns, ",", "=");
p.getDeployEmbedded().putAll(propMap);
CtCompoundType<?> compoundType = p.getCompoundType();
if (compoundType == null) {
throw new RuntimeException("No registered CtCompoundType for " + p.getPropertyType());
}
} else {
throw new RuntimeException("Can't use EmbeddedColumns on ScalarType " + prop.getFullBeanName());
}
}
// Want to process last so we can use with @Formula
Transient t = get(prop, Transient.class);
if (t != null) {