Skip to content

Commit

Permalink
Fix for #164 - Incorrect join used when where expression has a many
Browse files Browse the repository at this point in the history
property and ends with a foreign key column
  • Loading branch information
rbygrave committed Jul 9, 2014
1 parent 17f7143 commit 1e3035c
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 182 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/avaje/ebeaninternal/api/ManyWhereJoins.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ public void add(ElPropertyDeploy elProp) {
String join = elProp.getElPrefix();
BeanProperty p = elProp.getBeanProperty();
if (p instanceof BeanPropertyAssocMany<?>){
join = addManyToJoin(join, p.getName());
join = addManyToJoin(join, p.getName());
}
if (join != null){
addJoin(join);
String secondaryTableJoinPrefix = p.getSecondaryTableJoinPrefix();
if (secondaryTableJoinPrefix != null) {
addJoin(join+"."+secondaryTableJoinPrefix);
if (p != null) {
String secondaryTableJoinPrefix = p.getSecondaryTableJoinPrefix();
if (secondaryTableJoinPrefix != null) {
addJoin(join+"."+secondaryTableJoinPrefix);
}
}
addParentJoins(join);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ protected ElPropertyValue buildElGetValue(String propName, ElPropertyChainBuilde
if (propertyDeploy && chain != null) {
BeanFkeyProperty fk = fkeyMap.get(propName);
if (fk != null) {
return fk.create(chain.getExpression());
return fk.create(chain.getExpression(), chain.isContainsMany());
}
}

Expand Down
360 changes: 183 additions & 177 deletions src/main/java/com/avaje/ebeaninternal/server/deploy/BeanFkeyProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,182 +10,188 @@
*/
public final class BeanFkeyProperty implements ElPropertyValue {

private final String placeHolder;
private final String prefix;
private final String name;
private final String dbColumn;

private int deployOrder;

public BeanFkeyProperty(String prefix, String name, String dbColumn, int deployOrder) {
this.prefix = prefix;
this.name = name;
this.dbColumn = dbColumn;
this.deployOrder = deployOrder;
this.placeHolder = calcPlaceHolder(prefix, dbColumn);
}

public int getDeployOrder() {
return deployOrder;
}

private String calcPlaceHolder(String prefix, String dbColumn) {
if (prefix != null) {
return "${" + prefix + "}" + dbColumn;
} else {
return ROOT_ELPREFIX + dbColumn;
}
}

public BeanFkeyProperty create(String expression) {
int len = expression.length() - name.length() - 1;
String prefix = expression.substring(0, len);

return new BeanFkeyProperty(prefix, name, dbColumn, deployOrder);
}

/**
* Returns false for keys.
*/
public boolean isDbEncrypted() {
return false;
}

/**
* Returns false for keys.
*/
public boolean isLocalEncrypted() {
return false;
}

/**
* Only usable as ElPropertyDeploy.
*/
public boolean isDeployOnly() {
return true;
}

@Override
public boolean containsFormulaWithJoin() {
return false;
}

/**
* Returns false.
*/
public boolean containsMany() {
return false;
}

public boolean containsManySince(String sinceProperty) {
return containsMany();
}

public String getDbColumn() {
return dbColumn;
}

public String getName() {
return name;
}

public String getElName() {
return name;
}

/**
* Returns null as not an AssocOne.
*/
public Object[] getAssocOneIdValues(EntityBean value) {
return null;
}

/**
* Returns null as not an AssocOne.
*/
public String getAssocOneIdExpr(String prefix, String operator) {
return null;
}

/**
* Returns null as not an AssocOne.
*/
public String getAssocIdInExpr(String prefix) {
return null;
}

/**
* Returns null as not an AssocOne.
*/
public String getAssocIdInValueExpr(int size) {
return null;
}

/**
* Returns false as not an AssocOne.
*/
public boolean isAssocId() {
return false;
}

public boolean isAssocProperty() {
return false;
}

public String getElPlaceholder(boolean encrypted) {
return placeHolder;
}

public String getElPrefix() {
return prefix;
}

public boolean isDateTimeCapable() {
return false;
}

public int getJdbcType() {
return 0;
}

public Object parseDateTime(long systemTimeMillis) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public StringFormatter getStringFormatter() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public StringParser getStringParser() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public void elSetReference(EntityBean bean) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public Object elConvertType(Object value) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public void elSetValue(EntityBean bean, Object value, boolean populate) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public Object elGetValue(EntityBean bean) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public Object elGetReference(EntityBean bean) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public BeanProperty getBeanProperty() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public String getDeployProperty() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}
private final String placeHolder;
private final String prefix;
private final String name;
private final String dbColumn;
private final boolean containsMany;

private int deployOrder;

public BeanFkeyProperty(String prefix, String name, String dbColumn, int deployOrder) {
this(prefix, name, dbColumn, deployOrder, false);
}

private BeanFkeyProperty(String prefix, String name, String dbColumn, int deployOrder, boolean containsMany) {
this.prefix = prefix;
this.name = name;
this.dbColumn = dbColumn;
this.deployOrder = deployOrder;
this.containsMany = containsMany;
this.placeHolder = calcPlaceHolder(prefix, dbColumn);
}

public int getDeployOrder() {
return deployOrder;
}

private String calcPlaceHolder(String prefix, String dbColumn) {
if (prefix != null) {
return "${" + prefix + "}" + dbColumn;
} else {
return ROOT_ELPREFIX + dbColumn;
}
}

public BeanFkeyProperty create(String expression, boolean containsMany) {
int len = expression.length() - name.length() - 1;
String prefix = expression.substring(0, len);

return new BeanFkeyProperty(prefix, name, dbColumn, deployOrder, containsMany);
}

/**
* Returns false for keys.
*/
public boolean isDbEncrypted() {
return false;
}

/**
* Returns false for keys.
*/
public boolean isLocalEncrypted() {
return false;
}

/**
* Only usable as ElPropertyDeploy.
*/
public boolean isDeployOnly() {
return true;
}

@Override
public boolean containsFormulaWithJoin() {
return false;
}

/**
* Returns false.
*/
public boolean containsMany() {
return containsMany;
}

public boolean containsManySince(String sinceProperty) {
return containsMany();
}

public String getDbColumn() {
return dbColumn;
}

public String getName() {
return name;
}

public String getElName() {
return name;
}

/**
* Returns null as not an AssocOne.
*/
public Object[] getAssocOneIdValues(EntityBean value) {
return null;
}

/**
* Returns null as not an AssocOne.
*/
public String getAssocOneIdExpr(String prefix, String operator) {
return null;
}

/**
* Returns null as not an AssocOne.
*/
public String getAssocIdInExpr(String prefix) {
return null;
}

/**
* Returns null as not an AssocOne.
*/
public String getAssocIdInValueExpr(int size) {
return null;
}

/**
* Returns false as not an AssocOne.
*/
public boolean isAssocId() {
return false;
}

public boolean isAssocProperty() {
return false;
}

public String getElPlaceholder(boolean encrypted) {
return placeHolder;
}

public String getElPrefix() {
return prefix;
}

public boolean isDateTimeCapable() {
return false;
}

public int getJdbcType() {
return 0;
}

public BeanProperty getBeanProperty() {
return null;
}

public Object parseDateTime(long systemTimeMillis) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public StringFormatter getStringFormatter() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public StringParser getStringParser() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public void elSetReference(EntityBean bean) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public Object elConvertType(Object value) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public void elSetValue(EntityBean bean, Object value, boolean populate) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public Object elGetValue(EntityBean bean) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public Object elGetReference(EntityBean bean) {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

public String getDeployProperty() {
throw new RuntimeException("ElPropertyDeploy only - not implemented");
}

}
Loading

0 comments on commit 1e3035c

Please sign in to comment.