mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add fix and test for BUG 408 from Eddie
This commit is contained in:
@@ -610,6 +610,11 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
secondaryPropsJoins(info);
|
||||
}
|
||||
|
||||
// Set inheritance info
|
||||
for (DeployBeanInfo<?> info : deplyInfoMap.values()) {
|
||||
setInheritanceInfo(info);
|
||||
}
|
||||
|
||||
for (DeployBeanInfo<?> info : deplyInfoMap.values()) {
|
||||
DeployBeanDescriptor<?> deployBeanDescriptor = info.getDescriptor();
|
||||
Integer key = getUniqueHash(deployBeanDescriptor);
|
||||
@@ -617,6 +622,33 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the inheritance info. ~EMG fix for join problem
|
||||
*
|
||||
* @param info the new inheritance info
|
||||
*/
|
||||
private void setInheritanceInfo(DeployBeanInfo<?> info) {
|
||||
for (DeployBeanPropertyAssocOne<?> oneProp : info.getDescriptor().propertiesAssocOne()) {
|
||||
if (!oneProp.isTransient()) {
|
||||
DeployBeanInfo<?> assoc = deplyInfoMap.get(oneProp.getTargetType());
|
||||
|
||||
if (assoc != null){
|
||||
oneProp.getTableJoin().setInheritInfo(assoc.getDescriptor().getInheritInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (DeployBeanPropertyAssocMany<?> manyProp : info.getDescriptor().propertiesAssocMany()) {
|
||||
if (!manyProp.isTransient()) {
|
||||
DeployBeanInfo<?> assoc = deplyInfoMap.get(manyProp.getTargetType());
|
||||
|
||||
if (assoc != null){
|
||||
manyProp.getTableJoin().setInheritInfo(assoc.getDescriptor().getInheritInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getUniqueHash(DeployBeanDescriptor<?> deployBeanDescriptor) {
|
||||
|
||||
int hashCode = deployBeanDescriptor.getFullName().hashCode();
|
||||
|
||||
@@ -8,7 +8,7 @@ public interface DbSqlContext {
|
||||
/**
|
||||
* Add a join to the sql query.
|
||||
*/
|
||||
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2);
|
||||
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2, String inheritance);
|
||||
|
||||
public void pushSecondaryTableAlias(String alias);
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ public final class TableJoin {
|
||||
*/
|
||||
private final BeanCascadeInfo cascadeInfo;
|
||||
|
||||
private final InheritInfo inheritInfo;
|
||||
|
||||
/**
|
||||
* Properties as an array.
|
||||
*/
|
||||
@@ -59,6 +61,7 @@ public final class TableJoin {
|
||||
this.table = InternString.intern(deploy.getTable());
|
||||
this.type = InternString.intern(deploy.getType());
|
||||
this.cascadeInfo = deploy.getCascadeInfo();
|
||||
this.inheritInfo = deploy.getInheritInfo();
|
||||
|
||||
DeployTableJoinColumn[] deployCols = deploy.columns();
|
||||
this.columns = new TableJoinColumn[deployCols.length];
|
||||
@@ -167,8 +170,10 @@ public final class TableJoin {
|
||||
|
||||
public boolean addJoin(boolean forceOuterJoin, String a1, String a2, DbSqlContext ctx) {
|
||||
|
||||
ctx.addJoin(forceOuterJoin ? LEFT_OUTER : type, table, columns(), a1, a2);
|
||||
String inheritance = inheritInfo != null ? inheritInfo.getWhere() : null;
|
||||
|
||||
ctx.addJoin(forceOuterJoin?LEFT_OUTER:type, table, columns(), a1, a2, inheritance);
|
||||
|
||||
return forceOuterJoin || LEFT_OUTER.equals(type);
|
||||
}
|
||||
|
||||
@@ -176,6 +181,7 @@ public final class TableJoin {
|
||||
* Explicitly add a (non-outer) join.
|
||||
*/
|
||||
public void addInnerJoin(String a1, String a2, DbSqlContext ctx) {
|
||||
ctx.addJoin(JOIN, table, columns(), a1, a2);
|
||||
String inheritance = inheritInfo != null ? inheritInfo.getWhere() : null;
|
||||
ctx.addJoin(JOIN, table, columns(), a1, a2, inheritance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.persistence.JoinColumn;
|
||||
import com.avaje.ebeaninternal.server.core.Message;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanCascadeInfo;
|
||||
import com.avaje.ebeaninternal.server.deploy.BeanTable;
|
||||
import com.avaje.ebeaninternal.server.deploy.InheritInfo;
|
||||
import com.avaje.ebeaninternal.server.deploy.TableJoin;
|
||||
|
||||
/**
|
||||
@@ -48,6 +49,7 @@ public class DeployTableJoin {
|
||||
*/
|
||||
private BeanCascadeInfo cascadeInfo = new BeanCascadeInfo();
|
||||
|
||||
private InheritInfo inheritInfo;
|
||||
|
||||
/**
|
||||
* Create a DeployTableJoin.
|
||||
@@ -205,4 +207,12 @@ public class DeployTableJoin {
|
||||
|
||||
return destJoin;
|
||||
}
|
||||
|
||||
public InheritInfo getInheritInfo() {
|
||||
return inheritInfo;
|
||||
}
|
||||
|
||||
public void setInheritInfo(InheritInfo inheritInfo) {
|
||||
this.inheritInfo = inheritInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class DefaultDbSqlContext implements DbSqlContext {
|
||||
joinStack.push(node);
|
||||
}
|
||||
|
||||
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2) {
|
||||
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2, String inheritance) {
|
||||
|
||||
if (tableJoins == null) {
|
||||
tableJoins = new HashSet<String>();
|
||||
@@ -125,6 +125,15 @@ public class DefaultDbSqlContext implements DbSqlContext {
|
||||
sb.append(".").append(pair.getLocalDbColumn());
|
||||
}
|
||||
|
||||
|
||||
// add on any inheritance where clause
|
||||
if (inheritance != null && inheritance.length() > 0){
|
||||
sb.append(" and ");
|
||||
sb.append(a2);
|
||||
sb.append(".");
|
||||
sb.append(inheritance);
|
||||
}
|
||||
|
||||
sb.append(" ");
|
||||
}
|
||||
|
||||
|
||||
@@ -423,7 +423,8 @@ public class SqlTreeNodeBean implements SqlTreeNode {
|
||||
|
||||
public void appendWhere(DbSqlContext ctx) {
|
||||
|
||||
if (inheritInfo != null) {
|
||||
// Only apply inheritance to root node as any join will alreay have the inheritance join include - see TableJoin
|
||||
if (inheritInfo != null && nodeBeanProp == null) {
|
||||
if (inheritInfo.isRoot()) {
|
||||
// at root of hierarchy so don't bother
|
||||
// adding a where clause because we want
|
||||
|
||||
Reference in New Issue
Block a user