Fixes in Relation.java:
* Make renderConstraints() do the right thing in regard to logicalOperator, extracting the code from buildQuery() * Make checkConstraints() do the right thing in regard to logicalOperator. * Make setConstraints() do the right thin in regard to logicalOperator, i.e. don't touch if logicalOperator is OR or XOR.
This commit is contained in:
parent
dd4be4b6b6
commit
3670bafb9f
2 changed files with 48 additions and 34 deletions
|
@ -1212,7 +1212,7 @@ public final class NodeManager {
|
||||||
dbm.addJoinConstraints(q, " AND ");
|
dbm.addJoinConstraints(q, " AND ");
|
||||||
|
|
||||||
if (rel.groupby != null) {
|
if (rel.groupby != null) {
|
||||||
q.append(rel.renderConstraints(home, home.getNonVirtualParent()));
|
rel.renderConstraints(q, home, home.getNonVirtualParent(), " AND ");
|
||||||
|
|
||||||
if (rel.order != null) {
|
if (rel.order != null) {
|
||||||
q.append(" ORDER BY ");
|
q.append(" ORDER BY ");
|
||||||
|
|
|
@ -779,29 +779,13 @@ public final class Relation {
|
||||||
prefix = " AND ";
|
prefix = " AND ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constraints.length > 1 && logicalOperator != AND) {
|
// render the constraints and filter
|
||||||
q.append(prefix);
|
renderConstraints(q, home, nonvirtual, prefix);
|
||||||
q.append("(");
|
|
||||||
prefix = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < constraints.length; i++) {
|
|
||||||
q.append(prefix);
|
|
||||||
constraints[i].addToQuery(q, home, nonvirtual);
|
|
||||||
prefix = logicalOperator;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (constraints.length > 1 && logicalOperator != AND) {
|
|
||||||
q.append(")");
|
|
||||||
prefix = " AND ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter != null) {
|
|
||||||
appendFilter(q, nonvirtual, prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// add joined fetch constraints
|
||||||
ownType.addJoinConstraints(q, prefix);
|
ownType.addJoinConstraints(q, prefix);
|
||||||
|
|
||||||
|
// add group and order clauses
|
||||||
if (groupby != null) {
|
if (groupby != null) {
|
||||||
q.append(" GROUP BY " + groupby);
|
q.append(" GROUP BY " + groupby);
|
||||||
|
|
||||||
|
@ -885,30 +869,39 @@ public final class Relation {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Render contraints and filter conditions to an SQL query string buffer
|
||||||
*
|
*
|
||||||
*
|
* @param q the query string
|
||||||
* @param home ...
|
* @param home our home node
|
||||||
* @param nonvirtual ...
|
* @param nonvirtual our non-virtual home node
|
||||||
*
|
* @param prefix the prefix to use to append to the existing query (e.g. " AND ")
|
||||||
* @return ...
|
|
||||||
*
|
*
|
||||||
* @throws SQLException ...
|
* @throws SQLException ...
|
||||||
*/
|
*/
|
||||||
public String renderConstraints(INode home, INode nonvirtual)
|
public void renderConstraints(StringBuffer q, INode home,
|
||||||
|
INode nonvirtual, String prefix)
|
||||||
throws SQLException {
|
throws SQLException {
|
||||||
StringBuffer q = new StringBuffer();
|
|
||||||
String prefix = " AND ";
|
if (constraints.length > 1 && logicalOperator != AND) {
|
||||||
|
q.append(prefix);
|
||||||
|
q.append("(");
|
||||||
|
prefix = "";
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < constraints.length; i++) {
|
for (int i = 0; i < constraints.length; i++) {
|
||||||
q.append(prefix);
|
q.append(prefix);
|
||||||
constraints[i].addToQuery(q, home, nonvirtual);
|
constraints[i].addToQuery(q, home, nonvirtual);
|
||||||
|
prefix = logicalOperator;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (constraints.length > 1 && logicalOperator != AND) {
|
||||||
|
q.append(")");
|
||||||
|
prefix = " AND ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
appendFilter(q, nonvirtual, prefix);
|
appendFilter(q, nonvirtual, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
return q.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -982,6 +975,10 @@ public final class Relation {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// counter for constraints and satisfied constraints
|
||||||
|
int count = 0;
|
||||||
|
int satisfied = 0;
|
||||||
|
|
||||||
INode nonvirtual = parent.getNonVirtualParent();
|
INode nonvirtual = parent.getNonVirtualParent();
|
||||||
|
|
||||||
for (int i = 0; i < constraints.length; i++) {
|
for (int i = 0; i < constraints.length; i++) {
|
||||||
|
@ -1000,13 +997,22 @@ public final class Relation {
|
||||||
value = home.getString(constraints[i].localName);
|
value = home.getString(constraints[i].localName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((value != null) && !value.equals(child.getString(propname))) {
|
count++;
|
||||||
return false;
|
|
||||||
|
if (value != null && value.equals(child.getString(propname))) {
|
||||||
|
satisfied++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
// check if enough constraints are met depending on logical operator
|
||||||
|
if (logicalOperator == OR) {
|
||||||
|
return satisfied > 0;
|
||||||
|
} else if (logicalOperator == XOR) {
|
||||||
|
return satisfied == 1;
|
||||||
|
} else {
|
||||||
|
return satisfied == count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1014,7 +1020,15 @@ public final class Relation {
|
||||||
* appropriate properties
|
* appropriate properties
|
||||||
*/
|
*/
|
||||||
public void setConstraints(Node parent, Node child) {
|
public void setConstraints(Node parent, Node child) {
|
||||||
|
|
||||||
|
// if logical operator is OR or XOR we just return because we
|
||||||
|
// wouldn't know what to do anyway
|
||||||
|
if (logicalOperator != AND) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Node home = parent.getNonVirtualParent();
|
Node home = parent.getNonVirtualParent();
|
||||||
|
|
||||||
for (int i = 0; i < constraints.length; i++) {
|
for (int i = 0; i < constraints.length; i++) {
|
||||||
// don't set groupby constraints since we don't know if the
|
// don't set groupby constraints since we don't know if the
|
||||||
// parent node is the base node or a group node
|
// parent node is the base node or a group node
|
||||||
|
|
Loading…
Add table
Reference in a new issue