Fix for #227 - Many2Many cache bug, incorrect query plan hash calculation

This commit is contained in:
rbygrave committed 2015-01-11 20:45:07 +13:00
1 parent a998c0be55
commit 961b219e3e
3 files changed
+44 -4

No files matched your search

@@ -50,6 +50,11 @@ public final class TableJoin {
*/
private final TableJoinColumn[] columns;
/**
* A hash that can be used with the query plan.
*/
private final int queryHash;
/**
* Create a TableJoin.
*/
@@ -77,7 +82,26 @@ public final class TableJoin {
BeanProperty prop = propMap.get(deployProps[i].getName());
this.properties[i] = prop;
}
this.queryHash = calcQueryHash();
}
/**
* Calculate a hash value for adding to a query plan.
*/
private int calcQueryHash() {
int hc = type.hashCode();
hc = hc * 31 + (table == null ? 0 : table.hashCode());
for (int i = 0; i < columns.length; i++) {
hc = hc * 31 + columns[i].queryHash();
}
return hc;
}
/**
* Return a hash value for adding to a query plan.
*/
public int queryHash() {
return queryHash;
}
public String toString() {
@@ -21,7 +21,12 @@ public class TableJoinColumn {
private final boolean insertable;
private final boolean updateable;
/**
* Hash for including in a query plan
*/
private final int queryHash;
/**
* Create the pair.
*/
@@ -30,12 +35,23 @@ public class TableJoinColumn {
this.foreignDbColumn = InternString.intern(deploy.getForeignDbColumn());
this.insertable = deploy.isInsertable();
this.updateable = deploy.isUpdateable();
this.queryHash = hashOf(localDbColumn) * 31 + hashOf(foreignDbColumn);
}
private int hashOf(String value) {
return (value == null) ? 0 : value.hashCode();
}
public String toString() {
return localDbColumn+" = "+foreignDbColumn;
}
/**
* Return a hash for including in a query plan.
*/
public int queryHash() {
return queryHash;
}
/**
* Return the foreign database column name.