diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java index 427f498c9..f244ccd2d 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/CoalesceExpression.java @@ -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; + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NullIfExpression.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NullIfExpression.java index aff99410b..38f681803 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NullIfExpression.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/NullIfExpression.java @@ -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; + } + } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java index 0697fd3a6..81f825033 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/SubQ.java @@ -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); } } } diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Customer.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Customer.java index ade696253..fc2006665 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Customer.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/Customer.java @@ -67,7 +67,7 @@ public class Customer { @Column(length=30) @Basic String name; - @Enumerated + @Enumerated(EnumType.STRING) @Basic CreditRating creditRating; @Version diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java index 7e4357aae..81bcca95a 100644 --- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java +++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestSubquery.java @@ -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[] {