mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#897 - Remove @EmbeddedColumns ... replace with @Embedded(prefix="...")
This commit is contained in:
@@ -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);
|
||||
|
||||
+11
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-24
@@ -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) {
|
||||
|
||||
@@ -29,6 +29,8 @@ public class TestDPersonEl {
|
||||
p.setSalary(new Money("12200"));
|
||||
p.setCmoney(new CMoney(new Money("12"), NZD));
|
||||
|
||||
Ebean.save(p);
|
||||
|
||||
SpiServer server = Ebean.getDefaultServer().getPluginApi();
|
||||
|
||||
BeanType<DPerson> descriptor = server.getBeanType(DPerson.class);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.avaje.tests.model.ddd;
|
||||
|
||||
import com.avaje.ebean.annotation.EmbeddedColumns;
|
||||
import com.avaje.tests.model.ivo.CMoney;
|
||||
import com.avaje.tests.model.ivo.Money;
|
||||
import com.avaje.tests.model.ivo.Oid;
|
||||
@@ -21,10 +20,8 @@ public class DPerson {
|
||||
|
||||
Money salary;
|
||||
|
||||
@EmbeddedColumns(columns = "amount=a_amt, currency=a_curr")
|
||||
CMoney cmoney;
|
||||
|
||||
@EmbeddedColumns(columns = "startMillis=i_start, endMillis=i_end")
|
||||
Interval interval;
|
||||
|
||||
public String toString() {
|
||||
|
||||
@@ -2,9 +2,6 @@ package com.avaje.tests.model.embedded;
|
||||
|
||||
import com.avaje.ebean.annotation.Cache;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
@@ -33,16 +30,10 @@ public class EInvoice {
|
||||
@ManyToOne
|
||||
EPerson person;
|
||||
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "street", column = @Column(name = "ship_street")),
|
||||
@AttributeOverride(name = "suburb", column = @Column(name = "ship_suburb")),
|
||||
@AttributeOverride(name = "city", column = @Column(name = "ship_city")),
|
||||
@AttributeOverride(name = "status", column = @Column(name = "ship_status"))
|
||||
})
|
||||
@Embedded(prefix = "ship_")
|
||||
EAddress shipAddress;
|
||||
|
||||
@Embedded
|
||||
@Embedded(prefix = "bill_")
|
||||
EAddress billAddress;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
Reference in New Issue
Block a user