You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2008/12/05 02:37:16 UTC
svn commit: r723553 [2/3] - in /openjpa/trunk:
openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/
openjpa-persistence/src/main/java/org/apache/openjpa/persistence/
openjpa-persistence/src/main/java/org/apache/openjpa/persis...
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryExpressionPredicate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryExpressionPredicate.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryExpressionPredicate.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryExpressionPredicate.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+import javax.persistence.Predicate;
+
+/**
+ * Binary predicate combines two expressions with an operator.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+class BinaryExpressionPredicate implements Predicate, Visitable {
+ protected final Expression _e1;
+ protected final Expression _e2;
+ protected final BinaryConditionalOperator _op;
+ private final BinaryConditionalOperator _nop;
+
+ BinaryExpressionPredicate(Expression e1, BinaryConditionalOperator op,
+ BinaryConditionalOperator nop, Expression e2) {
+ _e1 = e1;
+ _e2 = e2;
+ _op = op;
+ _nop = nop;
+ }
+
+ public final Expression getOperand() {
+ return _e1;
+ }
+
+ public final Expression getOperand2() {
+ return _e2;
+ }
+
+ public final BinaryConditionalOperator getOperator() {
+ return _op;
+ }
+
+ public Predicate and(Predicate predicate) {
+ return new AndPredicate(this, predicate);
+ }
+
+ public Predicate or(Predicate predicate) {
+ return new OrPredicate(this, predicate);
+ }
+
+ public Predicate not() {
+ if ( _nop == null)
+ throw new UnsupportedOperationException(this.toString());
+ return new BinaryExpressionPredicate(_e1, _nop, _op, _e2);
+ }
+
+ public String asExpression(AliasContext ctx) {
+ return ((Visitable)_e1).asExpression(ctx)
+ + " " + _op + " "
+ + ((Visitable)_e2).asExpression(ctx);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryFunctionalOperator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryFunctionalOperator.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryFunctionalOperator.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryFunctionalOperator.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Enumeration of functional operator that operates on ordered pair of
+ * expression to generate another expression.
+ *
+ * @see BinaryOperatorExpression
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public enum BinaryFunctionalOperator {
+ DIVIDE("/"),
+ LOCATE("LOCATE"),
+ MINUS("-"),
+ MOD("MOD"),
+ PLUS("+"),
+ RANGE(","),
+ SUBSTR("SUBSTR"),
+ TIMES("*"),
+ TRIM("TRIM");
+
+ private final String _symbol;
+
+ BinaryFunctionalOperator(String symbol) {
+ _symbol = symbol;
+ }
+
+ public String toString() {
+ return _symbol;
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryOperatorExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryOperatorExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryOperatorExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/BinaryOperatorExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * An expression resulting from a binary operation on two expressions.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class BinaryOperatorExpression extends ExpressionImpl {
+ protected final Expression _e1;
+ protected final Expression _e2;
+ protected final BinaryFunctionalOperator _op;
+
+ public BinaryOperatorExpression(Expression e1, BinaryFunctionalOperator op,
+ Expression e2) {
+ _e1 = e1;
+ _e2 = e2;
+ _op = op;
+ }
+
+ public Expression getOperand1() {
+ return _e1;
+ }
+
+ public Expression getOperand2() {
+ return _e2;
+ }
+
+ public BinaryFunctionalOperator getOperator() {
+ return _op;
+ }
+
+ public String asExpression(AliasContext ctx) {
+ return ((Visitable)_e1).asExpression(ctx) + _op
+ + ((Visitable)_e2).asExpression(ctx);
+ }
+
+ public String asProjection(AliasContext ctx) {
+ return ((Selectable)_e1).asProjection(ctx) + _op
+ + ((Selectable)_e2).asProjection(ctx);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CaseExpressionImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CaseExpressionImpl.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CaseExpressionImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CaseExpressionImpl.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.LinkedList;
+
+import javax.persistence.CaseExpression;
+import javax.persistence.Expression;
+import javax.persistence.Predicate;
+
+public class CaseExpressionImpl implements CaseExpression {
+ private LinkedList<WhenClause> _whens = new LinkedList<WhenClause>();
+ private final Object _caseOperand;
+
+ public CaseExpressionImpl() {
+ this(null);
+ }
+
+ public CaseExpressionImpl(Object caseOperand) {
+ _caseOperand = caseOperand;
+ }
+
+ public Expression elseCase(Expression arg) {
+ return new ElseExpression(this, arg);
+ }
+
+ public Expression elseCase(String arg) {
+ return new ElseExpression(this, arg);
+ }
+
+ public Expression elseCase(Number arg) {
+ return new ElseExpression(this, arg);
+ }
+
+ public Expression elseCase(Date arg) {
+ return new ElseExpression(this, arg);
+ }
+
+ public Expression elseCase(Calendar arg) {
+ return new ElseExpression(this, arg);
+ }
+
+ public Expression elseCase(Class arg) {
+ return new ElseExpression(this, arg);
+ }
+
+ public Expression elseCase(Enum<?> arg) {
+ return new ElseExpression(this, arg);
+ }
+
+ public CaseExpression then(Expression then) {
+ assertThenState();
+ _whens.getLast().setThen(then);
+ return this;
+ }
+
+ public CaseExpression then(Number then) {
+ assertThenState();
+ _whens.getLast().setThen(then);
+ return this;
+ }
+
+ public CaseExpression then(String then) {
+ assertThenState();
+ _whens.getLast().setThen(then);
+ return this;
+ }
+
+ public CaseExpression then(Date then) {
+ assertThenState();
+ _whens.getLast().setThen(then);
+ return this;
+ }
+
+ public CaseExpression then(Calendar then) {
+ assertThenState();
+ _whens.getLast().setThen(then);
+ return this;
+ }
+
+ public CaseExpression then(Class then) {
+ assertThenState();
+ _whens.getLast().setThen(then);
+ return this;
+ }
+
+ public CaseExpression then(Enum<?> then) {
+ assertThenState();
+ _whens.getLast().setThen(then);
+ return this;
+ }
+
+ public CaseExpression when(Predicate when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ public CaseExpression when(Expression when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ public CaseExpression when(Number when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ public CaseExpression when(String when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ public CaseExpression when(Date when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ public CaseExpression when(Calendar when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ public CaseExpression when(Class when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ public CaseExpression when(Enum<?> when) {
+ assertWhenState();
+ WhenClause clause = new WhenClause(when);
+ _whens.add(clause);
+ return this;
+ }
+
+ void assertWhenState() {
+ boolean ok = _whens.isEmpty() || _whens.getLast().hasThen();
+ if (!ok)
+ throw new IllegalStateException("when() can not be called now");
+ }
+
+ void assertThenState() {
+ boolean ok = !_whens.isEmpty() && !_whens.getLast().hasThen();
+ if (!ok)
+ throw new IllegalStateException("then() can not be called now");
+ }
+
+ public String toJPQL(AliasContext ctx) {
+ StringBuffer tmp = new StringBuffer("CASE ");
+ if (_caseOperand != null) {
+ tmp.append(toJPQL(ctx, _caseOperand));
+ }
+ for (WhenClause when : _whens) {
+ tmp.append(when.toJPQL(ctx));
+ }
+ return tmp.toString();
+ }
+
+
+ String toJPQL(AliasContext ctx, Object o) {
+ if (o instanceof Visitable) {
+ return ((Visitable)o).asExpression(ctx);
+ }
+ return o.toString();
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConditionalOperator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConditionalOperator.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConditionalOperator.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConditionalOperator.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Enumerates conditional operator that operates on two predicates to generate
+ * another predicate.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public enum ConditionalOperator {
+ AND,
+ OR;
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConstantExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConstantExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConstantExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ConstantExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import java.util.Arrays;
+
+/**
+ * Denotes a Value based expression such as Number, String or Date.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+class ConstantExpression extends ExpressionImpl {
+ private final Object _value;
+
+ public ConstantExpression(Object value) {
+ _value = value;
+ }
+
+ public Object getValue() {
+ return _value;
+ }
+
+ @Override
+ public String asExpression(AliasContext ctx) {
+ if (_value.getClass().isArray()) {
+ return Arrays.asList((Object[])_value).toString();
+ }
+ return quoted(_value);
+ }
+
+ @Override
+ public String asProjection(AliasContext ctx) {
+ return asExpression(ctx);
+ }
+
+ String quoted(Object o) {
+ if (o instanceof String)
+ return "'" + o + "'";
+ if (o instanceof Class)
+ return ((Class)o).getSimpleName();
+ return o.toString();
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CountExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CountExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CountExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CountExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes COUNT(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class CountExpression extends UnaryOperatorExpression {
+ public CountExpression(Expression op) {
+ super(op, UnaryFunctionalOperator.COUNT);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CurrentTimeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CurrentTimeExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CurrentTimeExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/CurrentTimeExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import java.sql.Time;
+import java.util.Date;
+
+/**
+ * Denotes CURRENT_TIME(), CURRENT_DATE() and CURRENT_TIMESTAMP() expressions.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class CurrentTimeExpression extends ExpressionImpl {
+ private static enum Now {
+ CURRENT_DATE,
+ CURRENT_TIME,
+ CURRENT_TIMESTAMP
+ }
+
+ private final Class _type;
+
+ public CurrentTimeExpression(Class operand) {
+ _type = operand;
+ }
+
+ @Override
+ public String asExpression(AliasContext ctx) {
+ Now now = (_type == Date.class
+ ? Now.CURRENT_DATE
+ : (_type == Time.class
+ ? Now.CURRENT_TIME : Now.CURRENT_TIMESTAMP));
+ return now.toString();
+ }
+
+ @Override
+ public String asProjection(AliasContext ctx) {
+ throw new UnsupportedOperationException();
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DistinctExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DistinctExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DistinctExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DistinctExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes DISTINCT(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class DistinctExpression extends UnaryOperatorExpression {
+
+ public DistinctExpression(Expression expr) {
+ super(expr, UnaryFunctionalOperator.DISTINCT);
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DividedByExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DividedByExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DividedByExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/DividedByExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1/e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class DividedByExpression extends BinaryOperatorExpression {
+ public DividedByExpression(Expression op1, Expression op2) {
+ super(op1, BinaryFunctionalOperator.DIVIDE, op2);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ElseExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ElseExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ElseExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ElseExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Else clause in a Case Statement.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class ElseExpression extends ExpressionImpl {
+ private final CaseExpressionImpl _caseClause;
+ private final Object _elseClause;
+
+ public ElseExpression(CaseExpressionImpl owner, Object op) {
+ _caseClause = owner;
+ _elseClause = op;
+ }
+
+ @Override
+ public String asExpression(AliasContext ctx) {
+ return _caseClause.toJPQL(ctx)
+ + " ELSE " + toJPQL(ctx, _elseClause)
+ + " END ";
+ }
+
+ @Override
+ public String asProjection(AliasContext ctx) {
+ return _caseClause.toJPQL(ctx)
+ + " ELSE " + toJPQL(ctx, _elseClause)
+ + " END ";
+ }
+
+ String toJPQL(AliasContext ctx, Object o) {
+ if (o instanceof Visitable) {
+ return ((Visitable)o).asExpression(ctx);
+ }
+ return o.toString();
+ }
+
+ String asProjection(AliasContext ctx, Object o) {
+ if (o instanceof Selectable) {
+ return ((Selectable)o).asProjection(ctx);
+ }
+ return o.toString();
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EntryExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EntryExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EntryExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EntryExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Denotes ENTRY(e) on a path.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class EntryExpression extends OperatorPath {
+ public EntryExpression(AbstractDomainObject expr) {
+ super(expr, PathOperator.ENTRY);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EqualExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EqualExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EqualExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/EqualExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 = e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class EqualExpression extends BinaryExpressionPredicate {
+ public EqualExpression(Expression op1, Expression op2) {
+ super(op1, BinaryConditionalOperator.EQUAL, BinaryConditionalOperator.EQUAL_NOT, op2);
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExistsExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExistsExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExistsExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExistsExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Denotes EXISTS(SubQuery) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class ExistsExpression extends UnaryExpressionPredicate {
+ public ExistsExpression(QueryDefinitionImpl op) {
+ super(op, UnaryConditionalOperator.EXISTS, UnaryConditionalOperator.EXISTS_NOT);
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExpressionImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExpressionImpl.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExpressionImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ExpressionImpl.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,477 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import javax.persistence.Expression;
+import javax.persistence.OrderByItem;
+import javax.persistence.PathExpression;
+import javax.persistence.Predicate;
+import javax.persistence.PredicateOperand;
+import javax.persistence.Subquery;
+import javax.persistence.TrimSpec;
+
+/**
+ * An abstract expression acts as a factory for concrete unary or binary
+ * expressions such as ABS() or PLUS().
+ *
+ * @author Pinaki Poddar
+ *
+ */
+abstract class ExpressionImpl implements Expression, Selectable, Visitable {
+
+ public Expression abs() {
+ return new AbsExpression(this);
+ }
+
+ public Expression concat(String... str) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Expression concat(Expression... str) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Expression dividedBy(Number num) {
+ return new DividedByExpression(this, new ConstantExpression(num));
+ }
+
+ public Expression dividedBy(Expression expr) {
+ return new DividedByExpression(this, expr);
+ }
+
+ public Predicate in(String... strings) {
+ return new InExpression(this, new ConstantExpression(strings));
+ }
+
+ public Predicate in(Number... nums) {
+ return new InExpression(this,
+ new ConstantExpression(nums));
+ }
+
+ public Predicate in(Enum<?>... enums) {
+ return new InExpression(this,
+ new ConstantExpression(enums));
+ }
+
+ public Predicate in(Class... classes) {
+ return new InExpression(this,
+ new ConstantExpression(classes));
+ }
+
+ public Predicate in(Expression... params) {
+ return new InExpression(this,
+ new ConstantExpression(params));
+ }
+
+ public Predicate in(Subquery subquery) {
+ return new InExpression(this, (Expression)subquery);
+ }
+
+ public Predicate isNull() {
+ return new IsNullExpression(this);
+ }
+
+ public Expression length() {
+ return new LengthExpression(this);
+ }
+
+ public Expression locate(String str) {
+ return locate(str, 0);
+ }
+
+ public Expression locate(Expression expr) {
+ return new LocateExpression(this, expr, 1);
+ }
+
+ public Expression locate(String str, int position) {
+ return new LocateExpression(this, new ConstantExpression(str), position);
+ }
+
+ public Expression locate(String str, Expression position) {
+ return new LocateExpression(this, new ConstantExpression(str), position);
+ }
+
+ public Expression locate(Expression str, int position) {
+ return new LocateExpression(this, str, position);
+ }
+
+ public Expression locate(Expression str, Expression position) {
+ return new LocateExpression(this, str, position);
+ }
+
+ public Expression lower() {
+ return new LowerExpression(this);
+ }
+
+ public Predicate member(PathExpression arg) {
+ return new MemberOfExpression(this, arg);
+ }
+
+ public Expression minus() {
+ return new UnaryMinusExpression(this);
+ }
+
+ public Expression minus(Number num) {
+ return new MinusExpression(this, new ConstantExpression(num));
+ }
+
+ public Expression minus(Expression expr) {
+ return new MinusExpression(this, expr);
+ }
+
+ public Expression mod(int num) {
+ return new ModExpression(this, new ConstantExpression(num));
+ }
+
+ public Expression mod(Expression expr) {
+ return new MinusExpression(this, expr);
+ }
+
+ public Expression plus(Number num) {
+ return new PlusExpression(this, new ConstantExpression(num));
+ }
+
+ public Expression plus(Expression expr) {
+ return new PlusExpression(this, expr);
+ }
+
+ public Expression sqrt() {
+ return new SquareRootExpression(this);
+ }
+
+ public Expression substring(int start) {
+ return new SubStringExpression(this, start);
+ }
+
+ public Expression substring(Expression start) {
+ return new SubStringExpression(this, start);
+ }
+
+ public Expression substring(int start, int len) {
+ return new SubStringExpression(this, start, len);
+ }
+
+ public Expression substring(int start, Expression len) {
+ return new SubStringExpression(this, new ConstantExpression(start), len);
+ }
+
+ public Expression substring(Expression start, int len) {
+ return new SubStringExpression(this, start, new ConstantExpression(len));
+ }
+
+ public Expression substring(Expression start, Expression len) {
+ return new SubStringExpression(this, start, len);
+ }
+
+ public Expression times(Number num) {
+ return new TimesExpression(this, new ConstantExpression(num));
+ }
+
+ public Expression times(Expression expr) {
+ return new TimesExpression(this, expr);
+ }
+
+ public Expression trim() {
+ return new TrimExpression(this, null, null);
+ }
+
+ public Expression trim(TrimSpec spec) {
+ return new TrimExpression(this, null, spec);
+ }
+
+ public Expression trim(char c) {
+ return new TrimExpression(this, c, null);
+ }
+
+ public Expression trim(char c, TrimSpec spec) {
+ return new TrimExpression(this, c, spec);
+ }
+
+ public Expression trim(Expression expr) {
+ return new TrimExpression(this, expr, null);
+ }
+
+ public Expression trim(Expression expr, TrimSpec spec) {
+ return new TrimExpression(this, expr, spec);
+ }
+
+ public Expression upper() {
+ return new ToUpperExpression(this);
+ }
+
+ public OrderByItem asc() {
+ throw new UnsupportedOperationException(this.toString());
+ }
+
+ public OrderByItem desc() {
+ throw new UnsupportedOperationException(this.toString());
+ }
+
+ public Predicate between(PredicateOperand arg1, PredicateOperand arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ (Expression)arg1, (Expression)arg2));
+ }
+
+ public Predicate between(PredicateOperand arg1, Number arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ (Expression)arg1, new ConstantExpression(arg2)));
+ }
+
+ public Predicate between(Number arg1, PredicateOperand arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), (Expression)arg2));
+ }
+
+ public Predicate between(Number arg1, Number arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), new ConstantExpression(arg2)));
+ }
+
+ public Predicate between(PredicateOperand arg1, String arg2) {
+ return new BetweenExpression(this, new RangeExpression((Expression)arg1,
+ new ConstantExpression(arg2)));
+ }
+
+ public Predicate between(String arg1, PredicateOperand arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), (Expression)arg2));
+ }
+
+ public Predicate between(String arg1, String arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), new ConstantExpression(arg2)));
+ }
+
+ public Predicate between(PredicateOperand arg1, Date arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ (Expression)arg1, new ConstantExpression(arg2)));
+ }
+
+ public Predicate between(Date arg1, PredicateOperand arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), (Expression)arg2));
+ }
+
+ public Predicate between(Date arg1, Date arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), new ConstantExpression(arg2)));
+ }
+
+ public Predicate between(PredicateOperand arg1, Calendar arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ (Expression)arg1, new ConstantExpression(arg2)));
+ }
+
+ public Predicate between(Calendar arg1, PredicateOperand arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), (Expression)arg2));
+ }
+
+ public Predicate between(Calendar arg1, Calendar arg2) {
+ return new BetweenExpression(this, new RangeExpression(
+ new ConstantExpression(arg1), new ConstantExpression(arg2)));
+ }
+
+ public Predicate equal(PredicateOperand arg) {
+ return new EqualExpression(this, (Expression)arg);
+ }
+
+ public Predicate equal(Class cls) {
+ return new EqualExpression(this, new ConstantExpression(cls));
+ }
+
+ public Predicate equal(Number arg) {
+ return new EqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate equal(String arg) {
+ return new EqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate equal(boolean arg) {
+ return new EqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate equal(Date arg) {
+ return new EqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate equal(Calendar arg) {
+ return new EqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate equal(Enum<?> e) {
+ return new EqualExpression(this, new ConstantExpression(e));
+ }
+
+ public Predicate greaterEqual(PredicateOperand arg) {
+ return new GreaterEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterEqual(Number arg) {
+ return new GreaterEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterEqual(String arg) {
+ return new GreaterEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterEqual(Date arg) {
+ return new GreaterEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterEqual(Calendar arg) {
+ return new GreaterEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterThan(PredicateOperand arg) {
+ return new GreaterThanExpression(this, (Expression)arg);
+ }
+
+ public Predicate greaterThan(Number arg) {
+ return new GreaterThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterThan(String arg) {
+ return new GreaterThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterThan(Date arg) {
+ return new GreaterThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate greaterThan(Calendar arg) {
+ return new GreaterThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessEqual(PredicateOperand arg) {
+ return new LessEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessEqual(Number arg) {
+ return new LessEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessEqual(String arg) {
+ return new LessEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessEqual(Date arg) {
+ return new LessEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessEqual(Calendar arg) {
+ return new LessEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessThan(PredicateOperand arg) {
+ return new LessThanExpression(this, (Expression)arg);
+ }
+
+ public Predicate lessThan(Number arg) {
+ return new LessThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessThan(String arg) {
+ return new LessThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessThan(Date arg) {
+ return new LessThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate lessThan(Calendar arg) {
+ return new LessThanExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate like(PredicateOperand pattern) {
+ return new LikeExpression(this, (Expression)pattern, null);
+ }
+
+ public Predicate like(PredicateOperand pattern, PredicateOperand escChar) {
+ return new LikeExpression(this, (Expression)pattern, escChar);
+ }
+
+ public Predicate like(PredicateOperand pattern, char escapeChar) {
+ return new LikeExpression(this, (Expression)pattern, escapeChar);
+ }
+
+ public Predicate like(String pattern) {
+ return new LikeExpression(this, new ConstantExpression(pattern), null);
+ }
+
+ public Predicate like(String pattern, PredicateOperand escapeChar) {
+ return new LikeExpression(this, new ConstantExpression(pattern),
+ escapeChar);
+ }
+
+ public Predicate like(String pattern, char escChar) {
+ return new LikeExpression(this, new ConstantExpression(pattern),
+ escChar);
+ }
+
+ public Predicate notEqual(PredicateOperand arg) {
+ return new NotEqualExpression(this, (Expression)arg);
+ }
+
+ public Predicate notEqual(Class cls) {
+ return new NotEqualExpression(this, new ConstantExpression(cls));
+ }
+
+ public Predicate notEqual(Number arg) {
+ return new NotEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate notEqual(String arg) {
+ return new NotEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate notEqual(boolean arg) {
+ return new NotEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate notEqual(Date arg) {
+ return new NotEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate notEqual(Calendar arg) {
+ return new NotEqualExpression(this, new ConstantExpression(arg));
+ }
+
+ public Predicate notEqual(Enum<?> e) {
+ return new NotEqualExpression(this, new ConstantExpression(e));
+ }
+
+ //
+ // Visitable/Selectable implementation
+ //
+ public void setAlias(AliasContext ctx) {
+ ctx.getAlias(this);
+ }
+
+ public String getAliasHint() {
+ return "o";
+ }
+
+ public abstract String asExpression(AliasContext ctx);
+ public abstract String asProjection(AliasContext ctx);
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/FetchPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/FetchPath.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/FetchPath.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/FetchPath.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.FetchJoinObject;
+
+/**
+ * Denotes a path used in fetch join. Simply wraps a Navigation Path.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class FetchPath implements FetchJoinObject, Visitable {
+ private NavigationPath _path;
+ private PathOperator _joinType;
+
+
+ FetchPath(NavigationPath path, PathOperator joinType) {
+ _path = path;
+ _joinType = joinType;
+ }
+
+ public String asExpression(AliasContext ctx) {
+ return _joinType + " " + _path.asExpression(ctx);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterEqualExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterEqualExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterEqualExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterEqualExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 >= e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class GreaterEqualExpression extends BinaryExpressionPredicate {
+ public GreaterEqualExpression(Expression op1, Expression op2) {
+ super(op1, BinaryConditionalOperator.GREATEREQUAL, BinaryConditionalOperator.LESS, op2);
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterThanExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterThanExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterThanExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/GreaterThanExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 > e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class GreaterThanExpression extends BinaryExpressionPredicate {
+ public GreaterThanExpression(Expression op1, Expression op2) {
+ super(op1, BinaryConditionalOperator.GREATER, BinaryConditionalOperator.LESSEQUAL, op2);
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/InExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/InExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/InExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/InExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,15 @@
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 IN (e2) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class InExpression extends BinaryExpressionPredicate {
+ public InExpression(Expression op, Expression op2) {
+ super(op, BinaryConditionalOperator.IN, BinaryConditionalOperator.IN_NOT, op2);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IndexExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IndexExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IndexExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IndexExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes INDEX(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class IndexExpression extends UnaryOperatorExpression {
+ public IndexExpression(Expression op) {
+ super(op, UnaryFunctionalOperator.INDEX);
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsEmptyExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsEmptyExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsEmptyExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsEmptyExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,16 @@
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+
+public class IsEmptyExpression extends UnaryExpressionPredicate {
+ public IsEmptyExpression(Expression op) {
+ super(op, UnaryConditionalOperator.ISEMPTY,
+ UnaryConditionalOperator.ISEMPTY_NOT);
+ }
+
+ @Override
+ public String asExpression(AliasContext ctx) {
+ return ((Visitable)_e).asExpression(ctx) + " " + _op;
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsNullExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsNullExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsNullExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/IsNullExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e IS NULL Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class IsNullExpression extends UnaryExpressionPredicate {
+ public IsNullExpression(Expression op) {
+ super(op, UnaryConditionalOperator.ISNULL,
+ UnaryConditionalOperator.ISNULL_NOT);
+ }
+
+ @Override
+ public String asExpression(AliasContext ctx) {
+ return ((Visitable)_e).asExpression(ctx) + " " + _op;
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JPQLHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JPQLHelper.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JPQLHelper.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JPQLHelper.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Utility for converting elements to JPQL string fragments.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class JPQLHelper {
+ static String toJPQL(AliasContext ctx, Object o) {
+ if (o instanceof Visitable)
+ return ((Visitable)o).asExpression(ctx);
+ return o.toString();
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JoinPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JoinPath.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JoinPath.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/JoinPath.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.DomainObject;
+import static org.apache.openjpa.persistence.query.PathOperator.NAVIGATION;
+
+/**
+ * Path resulting by joining from a parent path via an attribute.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class JoinPath extends AbstractDomainObject implements DomainObject {
+ public JoinPath(AbstractDomainObject parent, PathOperator join, String attr) {
+ super(parent.getOwner(), parent, join, attr);
+ }
+
+ @Override
+ public String getAliasHint() {
+ return getLastSegment();
+ }
+
+ @Override
+ public String getLastSegment() {
+ return super.getLastSegment().toString();
+ }
+
+ @Override
+ public AbstractDomainObject getParent() {
+ return (AbstractDomainObject)super.getParent();
+ }
+
+// @Override
+ public String asJoinable(AliasContext ctx) {
+ StringBuffer tmp = new StringBuffer(getOperator().toString());
+ tmp.append(getParent().asProjection(ctx))
+ .append(NAVIGATION)
+ .append(getLastSegment())
+ .append(" ")
+ .append(ctx.getAlias(this));
+
+ if (getJoins() != null)
+ for (JoinPath join : getJoins())
+ tmp.append(join.asJoinable(ctx));
+ return tmp.toString();
+ }
+
+ @Override
+ public String asExpression(AliasContext ctx) {
+ if (ctx.hasAlias(this))
+ return ctx.getAlias(this);
+ return getParent().asExpression(ctx) + NAVIGATION + getLastSegment();
+ }
+
+ @Override
+ public String asProjection(AliasContext ctx) {
+ if (ctx.hasAlias(this))
+ return ctx.getAlias(this);
+ return getParent().asProjection(ctx) + NAVIGATION + getLastSegment();
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/KeyExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/KeyExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/KeyExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/KeyExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Denotes KEY(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class KeyExpression extends OperatorPath {
+ public KeyExpression(AbstractDomainObject expr) {
+ super(expr, PathOperator.KEY);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LengthExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LengthExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LengthExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LengthExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes LENGTH(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LengthExpression extends UnaryOperatorExpression {
+ public LengthExpression(Expression op) {
+ super(op, UnaryFunctionalOperator.LENGTH);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessEqualExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessEqualExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessEqualExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessEqualExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 <= e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LessEqualExpression extends BinaryExpressionPredicate {
+ public LessEqualExpression(Expression op1, Expression op2) {
+ super(op1, BinaryConditionalOperator.LESSEQUAL,
+ BinaryConditionalOperator.GREATER, op2);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessThanExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessThanExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessThanExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LessThanExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 < e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LessThanExpression extends BinaryExpressionPredicate {
+ public LessThanExpression(Expression op1, Expression op2) {
+ super(op1, BinaryConditionalOperator.LESS,
+ BinaryConditionalOperator.GREATEREQUAL, op2);
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LikeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LikeExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LikeExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LikeExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 LIKE e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LikeExpression extends BinaryExpressionPredicate {
+ public LikeExpression(Expression op1, Expression op2, Object echar) {
+ super(escape(op1, echar), BinaryConditionalOperator.LIKE,
+ BinaryConditionalOperator.LIKE_NOT, escape(op2, echar));
+ }
+
+ static Expression escape(Expression o, Object echar) {
+ if (echar != null && o instanceof ConstantExpression
+ && ((ConstantExpression)o).getValue() instanceof String) {
+ String escapeChar = echar.toString();
+ return new ConstantExpression(escapeChar + o.toString() + escapeChar);
+ }
+ return o;
+ }
+
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LiteralExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LiteralExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LiteralExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LiteralExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+/**
+ * Denotes a Literal Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LiteralExpression extends ConstantExpression {
+ public LiteralExpression(Object literal) {
+ super(literal);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LocateExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LocateExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LocateExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LocateExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes LOCATE(e)
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LocateExpression extends BinaryOperatorExpression {
+ public LocateExpression(Expression op, Expression op2, Object pos) {
+ super(op, BinaryFunctionalOperator.LOCATE, op2);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LogicalPredicate.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Predicate;
+
+/**
+ * Logical Predicate combines two predicates with a logical operator.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LogicalPredicate implements Predicate, Visitable {
+ private final Predicate _p1;
+ private final Predicate _p2;
+ private final ConditionalOperator _op;
+ private final ConditionalOperator _nop;
+
+ public LogicalPredicate(Predicate p1, ConditionalOperator op,
+ ConditionalOperator nop, Predicate p2) {
+ _p1 = p1;
+ _p2 = p2;
+ _op = op;
+ _nop = nop;
+ }
+
+ public Predicate and(Predicate predicate) {
+ return new AndPredicate(this, predicate);
+ }
+
+ public Predicate or(Predicate predicate) {
+ return new OrPredicate(this, predicate);
+ }
+
+ public Predicate not() {
+ return new LogicalPredicate(_p1.not(), _nop, _op, _p2.not());
+ }
+
+ public String asExpression(AliasContext ctx) {
+ return ((Visitable)_p1).asExpression(ctx) + " " + _op + " "
+ + ((Visitable)_p2).asExpression(ctx);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LowerExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LowerExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LowerExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/LowerExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes LOWER(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class LowerExpression extends UnaryOperatorExpression {
+ public LowerExpression(Expression op) {
+ super(op, UnaryFunctionalOperator.LOWER);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MaxExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MaxExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MaxExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MaxExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes MAX(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class MaxExpression extends UnaryOperatorExpression {
+ public MaxExpression(Expression op) {
+ super(op, UnaryFunctionalOperator.MAX);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MemberOfExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MemberOfExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MemberOfExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MemberOfExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes e1 MEMBER OF e2 Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class MemberOfExpression extends BinaryExpressionPredicate {
+ public MemberOfExpression(Expression op, Expression op2) {
+ super(op, BinaryConditionalOperator.MEMBER,
+ BinaryConditionalOperator.MEMBER_NOT, op2);
+ }
+}
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinExpression.java Thu Dec 4 17:37:13 2008
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.Expression;
+
+/**
+ * Denotes MIN(e) Expression.
+ *
+ * @author Pinaki Poddar
+ *
+ */
+public class MinExpression extends UnaryOperatorExpression {
+ public MinExpression(Expression op) {
+ super(op, UnaryFunctionalOperator.MIN);
+ }
+}