OPENJPA-1024: subquery support of nullif and coalesce for enum literals

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@766204 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fay Wang 2009-04-18 02:54:35 +00:00
parent ff29a053dd
commit 8bbf149781
5 changed files with 58 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import org.apache.openjpa.jdbc.sql.SQLBuffer;
import org.apache.openjpa.jdbc.sql.Select;
import org.apache.openjpa.kernel.Filters;
import org.apache.openjpa.kernel.exps.ExpressionVisitor;
import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.meta.ClassMetaData;
/**
@ -41,6 +42,8 @@ public class CoalesceExpression
private final Val[] _vals;
private ClassMetaData _meta = null;
private Class _cast = null;
private Value other = null;
private ExpState otherState = null;
/**
* Constructor.
@ -171,5 +174,21 @@ public class CoalesceExpression
public void setMetaData(ClassMetaData meta) {
_meta = meta;
}
public void setOtherPath(Value other) {
this.other = other;
}
public Value getOtherPath() {
return other;
}
public void setOtherState(ExpState otherState) {
this.otherState = otherState;
}
public ExpState getOtherState() {
return otherState;
}
}

View File

@ -27,6 +27,7 @@ import org.apache.openjpa.jdbc.sql.SQLBuffer;
import org.apache.openjpa.jdbc.sql.Select;
import org.apache.openjpa.kernel.Filters;
import org.apache.openjpa.kernel.exps.ExpressionVisitor;
import org.apache.openjpa.kernel.exps.Value;
import org.apache.openjpa.meta.ClassMetaData;
/**
@ -41,6 +42,8 @@ public class NullIfExpression
private final Val _val2;
private ClassMetaData _meta = null;
private Class _cast = null;
private Value other = null;
private ExpState otherState = null;
/**
* Constructor.
@ -155,5 +158,22 @@ public class NullIfExpression
public void setMetaData(ClassMetaData meta) {
_meta = meta;
}
public void setOtherPath(Value other) {
this.other = other;
}
public Value getOtherPath() {
return other;
}
public void setOtherState(ExpState otherState) {
this.otherState = otherState;
}
public ExpState getOtherState() {
return otherState;
}
}

View File

@ -158,6 +158,12 @@ class SubQ
} else if (projs[i] instanceof SimpleCaseExpression) {
((SimpleCaseExpression)projs[i]).setOtherPath(other);
((SimpleCaseExpression)projs[i]).setOtherState(otherState);
} else if (projs[i] instanceof NullIfExpression) {
((NullIfExpression)projs[i]).setOtherPath(other);
((NullIfExpression)projs[i]).setOtherState(otherState);
} else if (projs[i] instanceof CoalesceExpression) {
((CoalesceExpression)projs[i]).setOtherPath(other);
((CoalesceExpression)projs[i]).setOtherState(otherState);
}
}
}

View File

@ -67,7 +67,7 @@ public class Customer {
@Column(length=30)
@Basic
String name;
@Enumerated
@Enumerated(EnumType.STRING)
@Basic
CreditRating creditRating;
@Version

View File

@ -114,7 +114,8 @@ public class TestSubquery
"select o.oid from Order o where o.customer.name in" +
" (select CONCAT(o.customer.name, 'XX') from Order o" +
" where o.amount > 10)",
" where o.amount > 10)",
"select c from Customer c where c.creditRating =" +
" (select " +
" CASE WHEN o2.amount > 10 THEN " +
@ -126,6 +127,16 @@ public class TestSubquery
" END " +
" from Order o2" +
" where c.cid.id = o2.customer.cid.id)",
"select c from Customer c " +
"where c.creditRating = (select COALESCE (c1.creditRating, " +
"org.apache.openjpa.persistence.query.Customer$CreditRating.POOR) " +
"from Customer c1 where c1.name = 'Famzy') order by c.name DESC",
"select c from Customer c " +
"where c.creditRating = (select NULLIF (c1.creditRating, " +
"org.apache.openjpa.persistence.query.Customer$CreditRating.POOR) " +
"from Customer c1 where c1.name = 'Famzy') order by c.name DESC",
};
static String[] updates = new String[] {