You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by an...@apache.org on 2010/03/09 15:16:09 UTC
svn commit: r920884 [3/4] - in /cayenne/sandbox/cayenne-gwt/src:
main/java/org/apache/cayenne/gwt/ main/java/org/apache/cayenne/gwt/client/
main/java/org/apache/cayenne/gwt/server/
main/java/org/apache/cayenne/query/ main/resources/org/apache/cayenne/ ...
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNamedParameter.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNamedParameter.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNamedParameter.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNamedParameter.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,74 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionException;
+import org.apache.cayenne.exp.ExpressionParameter;
+
+/**
+ * A named expression parameter.
+ *
+ * @since 1.1
+ */
+public class ASTNamedParameter extends ASTScalar {
+ ASTNamedParameter(int id) {
+ super(id);
+ }
+
+ public ASTNamedParameter() {
+ super(ExpressionParserTreeConstants.JJTNAMEDPARAMETER);
+ }
+
+ public ASTNamedParameter(Object value) {
+ super(ExpressionParserTreeConstants.JJTNAMEDPARAMETER);
+ setValue(value);
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ throw new ExpressionException(
+ "Uninitialized parameter: " + value + ", call 'expWithParameters' first.");
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ ASTNamedParameter copy = new ASTNamedParameter(id);
+ copy.value = value;
+ return copy;
+ }
+
+ @Override
+ public void setValue(Object value) {
+ if (value == null) {
+ throw new ExpressionException("Null Parameter value");
+ }
+
+ String name = value.toString().trim();
+ if (name.length() == 0) {
+ throw new ExpressionException("Empty Parameter value");
+ }
+
+ super.setValue(new ExpressionParameter(name));
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNegate.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNegate.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNegate.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNegate.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,85 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+
+/**
+ * "Negate" expression.
+ *
+ * @since 1.1
+ */
+public class ASTNegate extends SimpleNode {
+
+ ASTNegate(int id) {
+ super(id);
+ }
+
+ public ASTNegate() {
+ super(ExpressionParserTreeConstants.JJTNEGATE);
+ }
+
+ public ASTNegate(Object node) {
+ super(ExpressionParserTreeConstants.JJTNEGATE);
+ jjtAddChild(wrapChild(node), 0);
+ connectChildren();
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTNegate(id);
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ int len = jjtGetNumChildren();
+ if (len == 0) {
+ return null;
+ }
+
+ Number val = (Number) evaluateChild(0, o);
+
+ if (val == null) {
+ return null;
+ }
+
+ return -val.doubleValue();
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ throw new UnsupportedOperationException("No operator for '"
+ + ExpressionParserTreeConstants.jjtNodeName[id]
+ + "'");
+ }
+
+ @Override
+ public int getType() {
+ return Expression.NEGATIVE;
+ }
+
+ @Override
+ public int getOperandCount() {
+ return 1;
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNot.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNot.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNot.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNot.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,77 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.util.ConversionUtil;
+
+/**
+ * "Not" expression.
+ *
+ * @since 1.1
+ */
+public class ASTNot extends AggregateConditionNode {
+
+ ASTNot(int id) {
+ super(id);
+ }
+
+ public ASTNot() {
+ super(ExpressionParserTreeConstants.JJTNOT);
+ }
+
+ public ASTNot(Node expression) {
+ super(ExpressionParserTreeConstants.JJTNOT);
+ jjtAddChild(expression, 0);
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ int len = jjtGetNumChildren();
+ if (len == 0) {
+ return Boolean.FALSE;
+ }
+
+ return ConversionUtil.toBoolean(evaluateChild(0, o))
+ ? Boolean.FALSE
+ : Boolean.TRUE;
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTNot(id);
+ }
+
+ @Override
+ public int getType() {
+ return Expression.NOT;
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ throw new UnsupportedOperationException("No operator for '"
+ + ExpressionParserTreeConstants.jjtNodeName[id]
+ + "'");
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotBetween.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotBetween.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotBetween.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotBetween.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,92 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.util.ConversionUtil;
+
+/**
+ * "Not Between" expression.
+ *
+ */
+public class ASTNotBetween extends ConditionNode {
+ ASTNotBetween(int id) {
+ super(id);
+ }
+
+ public ASTNotBetween() {
+ super(ExpressionParserTreeConstants.JJTNOTBETWEEN);
+ }
+
+ public ASTNotBetween(ASTPath path, Object value1, Object value2) {
+ super(ExpressionParserTreeConstants.JJTNOTBETWEEN);
+ jjtAddChild(path, 0);
+ jjtAddChild(new ASTScalar(value1), 1);
+ jjtAddChild(new ASTScalar(value2), 2);
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ int len = jjtGetNumChildren();
+ if (len != 3) {
+ return Boolean.FALSE;
+ }
+
+ Comparable c1 = ConversionUtil.toComparable(evaluateChild(0, o));
+
+ if (c1 == null) {
+ return Boolean.FALSE;
+ }
+
+ Comparable c2 = ConversionUtil.toComparable(evaluateChild(1, o));
+ if (c2 == null) {
+ return Boolean.FALSE;
+ }
+
+ Comparable c3 = ConversionUtil.toComparable(evaluateChild(2, o));
+ if (c3 == null) {
+ return Boolean.FALSE;
+ }
+
+ return c1.compareTo(c2) >= 0
+ && c1.compareTo(c3) <= 0 ? Boolean.FALSE : Boolean.TRUE;
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTNotBetween(id);
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ return (index == 2) ? "and" : "not between";
+ }
+
+ @Override
+ public int getType() {
+ return Expression.NOT_BETWEEN;
+ }
+
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotEqual.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotEqual.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotEqual.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotEqual.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,86 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+
+/**
+ * "Not equal to" expression.
+ *
+ */
+public class ASTNotEqual extends ConditionNode {
+ ASTNotEqual(int id) {
+ super(id);
+ }
+
+ public ASTNotEqual() {
+ super(ExpressionParserTreeConstants.JJTNOTEQUAL);
+ }
+
+ /**
+ * Creates "Not Equal To" expression.
+ */
+ public ASTNotEqual(ASTPath path, Object value) {
+ super(ExpressionParserTreeConstants.JJTNOTEQUAL);
+ jjtAddChild(path, 0);
+ jjtAddChild(new ASTScalar(value), 1);
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ int len = jjtGetNumChildren();
+ if (len != 2) {
+ return Boolean.FALSE;
+ }
+
+ Object o1 = evaluateChild(0, o);
+ Object o2 = evaluateChild(1, o);
+ return !ASTEqual.evaluateImpl(o1, o2);
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTNotEqual(id);
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ return "!=";
+ }
+
+ @Override
+ protected String getEJBQLExpressionOperator(int index) {
+ if (jjtGetChild(1) instanceof ASTScalar && ((ASTScalar) jjtGetChild(1)).getValue() == null) {
+ //for ejbql, we need "is not null" instead of "!= null"
+ return "is not";
+ }
+ return getExpressionOperator(index);
+ }
+
+ @Override
+ public int getType() {
+ return Expression.NOT_EQUAL_TO;
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotIn.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotIn.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotIn.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotIn.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,110 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.commons.collections.Transformer;
+
+/**
+ * "Not In" expression.
+ *
+ */
+public class ASTNotIn extends ConditionNode {
+ ASTNotIn(int id) {
+ super(id);
+ }
+
+ public ASTNotIn() {
+ super(ExpressionParserTreeConstants.JJTNOTIN);
+ }
+
+ public ASTNotIn(ASTPath path, ASTList list) {
+ super(ExpressionParserTreeConstants.JJTNOTIN);
+ jjtAddChild(path, 0);
+ jjtAddChild(list, 1);
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ int len = jjtGetNumChildren();
+ if (len != 2) {
+ return Boolean.FALSE;
+ }
+
+ Object o1 = evaluateChild(0, o);
+ if (o1 == null) {
+ return Boolean.FALSE;
+ }
+
+ Object[] objects = (Object[]) evaluateChild(1, o);
+ if (objects == null) {
+ return Boolean.FALSE;
+ }
+
+ int size = objects.length;
+ for (int i = 0; i < size; i++) {
+ if (objects[i] != null && ASTEqual.evaluateAtomic(o1, objects[i])) {
+ return Boolean.FALSE;
+ }
+ }
+
+ return Boolean.TRUE;
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTNotIn(id);
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ return "not in";
+ }
+
+ @Override
+ public int getType() {
+ return Expression.NOT_IN;
+ }
+
+ @Override
+ protected Object transformExpression(Transformer transformer) {
+ Object transformed = super.transformExpression(transformer);
+
+ // transform empty ASTNotIn to ASTTrue
+ if (transformed instanceof ASTNotIn) {
+ ASTNotIn exp = (ASTNotIn) transformed;
+ if (exp.jjtGetNumChildren() == 2) {
+ ASTList list = (ASTList) exp.jjtGetChild(1);
+ Object[] objects = (Object[]) list.evaluate(null);
+ if (objects.length == 0) {
+ transformed = new ASTTrue();
+ }
+ }
+ }
+
+ return transformed;
+ }
+
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLike.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLike.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLike.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLike.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,69 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionException;
+
+/**
+ * "Not Like" expression.
+ *
+ */
+public class ASTNotLike extends PatternMatchNode {
+
+ ASTNotLike(int id) {
+ super(id, false);
+ }
+
+ public ASTNotLike() {
+ super(ExpressionParserTreeConstants.JJTNOTLIKE, false);
+ }
+
+ public ASTNotLike(ASTPath path, Object value) {
+ super(ExpressionParserTreeConstants.JJTNOTLIKE, false);
+ jjtAddChild(path, 0);
+ jjtAddChild(new ASTScalar(value), 1);
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ throw new ExpressionException("Cannot evaluate LIKE on GWT client side");
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTNotLike(id);
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ return "not like";
+ }
+
+ @Override
+ public int getType() {
+ return Expression.NOT_LIKE;
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLikeIgnoreCase.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLikeIgnoreCase.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLikeIgnoreCase.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTNotLikeIgnoreCase.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,73 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionException;
+
+/**
+ * "Not like, ignore case" expression.
+ *
+ */
+public class ASTNotLikeIgnoreCase extends IgnoreCaseNode {
+ ASTNotLikeIgnoreCase(int id) {
+ super(id, true);
+ }
+
+ public ASTNotLikeIgnoreCase() {
+ super(ExpressionParserTreeConstants.JJTNOTLIKEIGNORECASE, true);
+ }
+
+ public ASTNotLikeIgnoreCase(ASTPath path, Object value) {
+ super(ExpressionParserTreeConstants.JJTNOTLIKEIGNORECASE, true);
+ jjtAddChild(path, 0);
+ jjtAddChild(new ASTScalar(value), 1);
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ throw new ExpressionException("Cannot evaluate LIKE on GWT client side");
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTNotLikeIgnoreCase(id);
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ return "not likeIgnoreCase";
+ }
+
+ @Override
+ protected String getEJBQLExpressionOperator(int index) {
+ return "not like";
+ }
+
+ @Override
+ public int getType() {
+ return Expression.NOT_LIKE_IGNORE_CASE;
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTObjPath.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTObjPath.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTObjPath.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTObjPath.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,61 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionException;
+
+public class ASTObjPath extends ASTPath {
+ /**
+ * Constructor used by expression parser. Do not invoke directly.
+ */
+ ASTObjPath(int id) {
+ super(id);
+ }
+
+ public ASTObjPath() {
+ super(ExpressionParserTreeConstants.JJTOBJPATH);
+ }
+
+ public ASTObjPath(Object value) {
+ super(ExpressionParserTreeConstants.JJTOBJPATH);
+ setPath(value);
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ throw new ExpressionException("Cannot evaluate ObjPath on GWT client");
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ ASTObjPath copy = new ASTObjPath(id);
+ copy.path = path;
+ return copy;
+ }
+
+ @Override
+ public int getType() {
+ return Expression.OBJ_PATH;
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTOr.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTOr.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTOr.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTOr.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,100 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.util.ConversionUtil;
+
+/**
+ * "Or" expression.
+ *
+ * @since 1.1
+ */
+public class ASTOr extends AggregateConditionNode {
+ ASTOr(int id) {
+ super(id);
+ }
+
+ public ASTOr() {
+ super(ExpressionParserTreeConstants.JJTOR);
+ }
+
+ public ASTOr(Object[] nodes) {
+ super(ExpressionParserTreeConstants.JJTOR);
+ int len = nodes.length;
+ for (int i = 0; i < len; i++) {
+ jjtAddChild((Node) nodes[i], i);
+ }
+ connectChildren();
+ }
+
+ public ASTOr(Collection<? extends Node> nodes) {
+ super(ExpressionParserTreeConstants.JJTOR);
+ int len = nodes.size();
+ Iterator<? extends Node> it = nodes.iterator();
+ for (int i = 0; i < len; i++) {
+ jjtAddChild(it.next(), i);
+ }
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ int len = jjtGetNumChildren();
+ if (len == 0) {
+ return Boolean.FALSE;
+ }
+
+ for (int i = 0; i < len; i++) {
+ if (ConversionUtil.toBoolean(evaluateChild(i, o))) {
+ return Boolean.TRUE;
+ }
+ }
+
+ return Boolean.FALSE;
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTOr(id);
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ return "or";
+ }
+
+ @Override
+ public int getType() {
+ return Expression.OR;
+ }
+
+ @Override
+ public void jjtClose() {
+ super.jjtClose();
+ flattenTree();
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTPath.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTPath.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTPath.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTPath.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,90 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import java.util.Map;
+
+/**
+ * Generic path expression.
+ *
+ * @since 1.1
+ */
+public abstract class ASTPath extends SimpleNode {
+
+ protected String path;
+ protected Map<String, String> pathAliases;
+
+ ASTPath(int i) {
+ super(i);
+ }
+
+ @Override
+ public int getOperandCount() {
+ return 1;
+ }
+
+ @Override
+ public Object getOperand(int index) {
+ if (index == 0) {
+ return path;
+ }
+
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
+
+ @Override
+ public void setOperand(int index, Object value) {
+ if (index != 0) {
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
+
+ setPath(value);
+ }
+
+ protected void setPath(Object path) {
+ this.path = (path != null) ? path.toString() : null;
+ }
+
+ protected String getPath() {
+ return path;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public Map<String, String> getPathAliases() {
+ return pathAliases != null ? pathAliases : super.getPathAliases();
+ }
+
+ /**
+ * @since 3.0
+ */
+ public void setPathAliases(Map<String, String> pathAliases) {
+ this.pathAliases = pathAliases;
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ throw new UnsupportedOperationException("No operator for '"
+ + ExpressionParserTreeConstants.jjtNodeName[id]
+ + "'");
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTScalar.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTScalar.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTScalar.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTScalar.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,76 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+
+/**
+ * A scalar value wrapper expression.
+ *
+ * @since 1.1
+ */
+public class ASTScalar<T> extends SimpleNode {
+ protected T value;
+
+ /**
+ * Constructor used by expression parser. Do not invoke directly.
+ */
+ ASTScalar(int id) {
+ super(id);
+ }
+
+ public ASTScalar() {
+ super(ExpressionParserTreeConstants.JJTSCALAR);
+ }
+
+ public ASTScalar(Object value) {
+ super(ExpressionParserTreeConstants.JJTSCALAR);
+ setValue(value);
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ return value;
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ ASTScalar copy = new ASTScalar(id);
+ copy.value = value;
+ return copy;
+ }
+
+ public void setValue(Object value) {
+ this.value = (T) value;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ throw new UnsupportedOperationException(
+ "No operator for '" + ExpressionParserTreeConstants.jjtNodeName[id] + "'");
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTSubtract.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTSubtract.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTSubtract.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTSubtract.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,105 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.cayenne.exp.Expression;
+
+/**
+ * "Subtract" expression.
+ *
+ * @since 1.1
+ */
+public class ASTSubtract extends SimpleNode {
+ ASTSubtract(int id) {
+ super(id);
+ }
+
+ public ASTSubtract() {
+ super(ExpressionParserTreeConstants.JJTSUBTRACT);
+ }
+
+ public ASTSubtract(Object[] nodes) {
+ super(ExpressionParserTreeConstants.JJTSUBTRACT);
+ int len = nodes.length;
+ for (int i = 0; i < len; i++) {
+ jjtAddChild(wrapChild(nodes[i]), i);
+ }
+ connectChildren();
+ }
+
+ public ASTSubtract(Collection<?> nodes) {
+ super(ExpressionParserTreeConstants.JJTSUBTRACT);
+ int len = nodes.size();
+ Iterator<?> it = nodes.iterator();
+ for (int i = 0; i < len; i++) {
+ jjtAddChild(wrapChild(it.next()), i);
+ }
+ connectChildren();
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ int len = jjtGetNumChildren();
+ if (len == 0) {
+ return null;
+ }
+
+ Double result = null;
+ for (int i = 0; i < len; i++) {
+ Number val = (Number) evaluateChild(i, o);
+
+ if (val == null) {
+ return null;
+ }
+
+ result = (i == 0) ? val.doubleValue() : result - val.doubleValue();
+ }
+
+ return result;
+ }
+
+ /**
+ * Creates a copy of this expression node, without copying children.
+ */
+ @Override
+ public Expression shallowCopy() {
+ return new ASTSubtract(id);
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ return "-";
+ }
+
+ @Override
+ public int getType() {
+ return Expression.SUBTRACT;
+ }
+
+ @Override
+ public void jjtClose() {
+ super.jjtClose();
+ flattenTree();
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTTrue.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTTrue.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTTrue.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ASTTrue.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,66 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.Expression;
+
+/**
+ * Boolean true expression element Notice that there is one ASTTrue and one ASTFalse
+ * instead of a ASTBoolean with a Boolean value. The main reason for doing this is that a
+ * common ASTBoolean will have operand count of 1 and that will default to a prepared
+ * statmenet like " where ? and (...)", but we only need " where true and (...)".
+ *
+ * @see ASTFalse
+ * @since 3.0
+ */
+public class ASTTrue extends ConditionNode {
+
+ /**
+ * Constructor used by expression parser. Do not invoke directly.
+ */
+ ASTTrue(int id) {
+ super(id);
+ }
+
+ public ASTTrue() {
+ super(ExpressionParserTreeConstants.JJTTRUE);
+ }
+
+ @Override
+ protected Object evaluateNode(Object o) throws Exception {
+ return Boolean.TRUE;
+ }
+
+ @Override
+ protected String getExpressionOperator(int index) {
+ throw new UnsupportedOperationException("No operator for '"
+ + ExpressionParserTreeConstants.jjtNodeName[id]
+ + "'");
+ }
+
+ @Override
+ public Expression shallowCopy() {
+ return new ASTTrue(id);
+ }
+
+ @Override
+ public int getType() {
+ return Expression.TRUE;
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/AggregateConditionNode.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/AggregateConditionNode.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/AggregateConditionNode.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/AggregateConditionNode.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,102 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.ExpressionException;
+import org.apache.commons.collections.Transformer;
+
+/**
+ * Superclass of aggregated conditional nodes such as NOT, AND, OR. Performs
+ * extra checks on parent and child expressions to validate conditions that
+ * are not addressed in the Cayenne expressions grammar.
+ *
+ * @since 1.1
+ */
+public abstract class AggregateConditionNode extends SimpleNode {
+ AggregateConditionNode(int i) {
+ super(i);
+ }
+
+ @Override
+ protected boolean pruneNodeForPrunedChild(Object prunedChild) {
+ return false;
+ }
+
+ @Override
+ protected Object transformExpression(Transformer transformer) {
+ Object transformed = super.transformExpression(transformer);
+
+ if (!(transformed instanceof AggregateConditionNode)) {
+ return transformed;
+ }
+
+ AggregateConditionNode condition = (AggregateConditionNode) transformed;
+
+ // prune itself if the transformation resulted in
+ // no children or a single child
+ switch (condition.getOperandCount()) {
+ case 1 :
+ if (condition instanceof ASTNot) {
+ return condition;
+ }
+ else {
+ return condition.getOperand(0);
+ }
+ case 0 :
+ return PRUNED_NODE;
+ default :
+ return condition;
+ }
+ }
+
+ @Override
+ public void jjtSetParent(Node n) {
+ // this is a check that we can't handle properly
+ // in the grammar... do it here...
+
+ // disallow non-aggregated condition parents...
+ if (!(n instanceof AggregateConditionNode)) {
+ String label =
+ (n instanceof SimpleNode)
+ ? ((SimpleNode) n).expName()
+ : String.valueOf(n);
+ throw new ExpressionException(expName() + ": invalid parent - " + label);
+ }
+
+ super.jjtSetParent(n);
+ }
+
+ @Override
+ public void jjtAddChild(Node n, int i) {
+ // this is a check that we can't handle properly
+ // in the grammar... do it here...
+
+ // only allow conditional nodes...no scalars
+ if (!(n instanceof ConditionNode) && !(n instanceof AggregateConditionNode)) {
+ String label =
+ (n instanceof SimpleNode)
+ ? ((SimpleNode) n).expName()
+ : String.valueOf(n);
+ throw new ExpressionException(expName() + ": invalid child - " + label);
+ }
+
+ super.jjtAddChild(n, i);
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ConditionNode.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ConditionNode.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ConditionNode.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ConditionNode.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,49 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import org.apache.cayenne.exp.ExpressionException;
+
+/**
+ * Superclass of conditional expressions.
+ *
+ * @since 1.1
+ */
+public abstract class ConditionNode extends SimpleNode {
+
+ public ConditionNode(int i) {
+ super(i);
+ }
+
+ @Override
+ public void jjtSetParent(Node n) {
+ // this is a check that we can't handle properly
+ // in the grammar... do it here...
+
+ // disallow non-aggregated condition parents...
+ if (!(n instanceof AggregateConditionNode)) {
+ String label = (n instanceof SimpleNode) ? ((SimpleNode)n).expName() : String.valueOf(n);
+ throw new ExpressionException(expName() + ": invalid parent - " + label);
+ }
+
+ super.jjtSetParent(n);
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ExpressionParserTreeConstants.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ExpressionParserTreeConstants.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ExpressionParserTreeConstants.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/ExpressionParserTreeConstants.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,71 @@
+/* Generated By:JJTree: Do not edit this line. ./ExpressionParserTreeConstants.java */
+
+package org.apache.cayenne.exp.parser;
+
+public interface ExpressionParserTreeConstants
+{
+ public int JJTVOID = 0;
+ public int JJTOR = 1;
+ public int JJTAND = 2;
+ public int JJTNOT = 3;
+ public int JJTTRUE = 4;
+ public int JJTFALSE = 5;
+ public int JJTEQUAL = 6;
+ public int JJTNOTEQUAL = 7;
+ public int JJTLESSOREQUAL = 8;
+ public int JJTLESS = 9;
+ public int JJTGREATER = 10;
+ public int JJTGREATEROREQUAL = 11;
+ public int JJTLIKE = 12;
+ public int JJTLIKEIGNORECASE = 13;
+ public int JJTIN = 14;
+ public int JJTBETWEEN = 15;
+ public int JJTNOTLIKE = 16;
+ public int JJTNOTLIKEIGNORECASE = 17;
+ public int JJTNOTIN = 18;
+ public int JJTNOTBETWEEN = 19;
+ public int JJTLIST = 20;
+ public int JJTSCALAR = 21;
+ public int JJTADD = 22;
+ public int JJTSUBTRACT = 23;
+ public int JJTMULTIPLY = 24;
+ public int JJTDIVIDE = 25;
+ public int JJTNEGATE = 26;
+ public int JJTNAMEDPARAMETER = 27;
+ public int JJTOBJPATH = 28;
+ public int JJTDBPATH = 29;
+
+
+ public String[] jjtNodeName = {
+ "void",
+ "Or",
+ "And",
+ "Not",
+ "True",
+ "False",
+ "Equal",
+ "NotEqual",
+ "LessOrEqual",
+ "Less",
+ "Greater",
+ "GreaterOrEqual",
+ "Like",
+ "LikeIgnoreCase",
+ "In",
+ "Between",
+ "NotLike",
+ "NotLikeIgnoreCase",
+ "NotIn",
+ "NotBetween",
+ "List",
+ "Scalar",
+ "Add",
+ "Subtract",
+ "Multiply",
+ "Divide",
+ "Negate",
+ "NamedParameter",
+ "ObjPath",
+ "DbPath",
+ };
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/IgnoreCaseNode.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/IgnoreCaseNode.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/IgnoreCaseNode.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/IgnoreCaseNode.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,29 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+
+/**
+ * Common node for likeIgnoreCase and notLikeIgnoreCase
+ */
+abstract class IgnoreCaseNode extends PatternMatchNode {
+ IgnoreCaseNode(int i, boolean ignoringCase) {
+ super(i, ignoringCase);
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/Node.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/Node.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/Node.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/Node.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,55 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+/**
+ * Provides basic machinery for constructing the parent and child relationships
+ * between nodes. All AST nodes must implement this interface.
+ *
+ * <p>Generated by JJTree</p>
+ *
+ * @since 1.1
+ */
+public interface Node {
+
+ /** Called after the node has been made the current
+ node. It indicates that child nodes can now be added to it. */
+ public void jjtOpen();
+
+ /** Called after all the child nodes have been
+ added. */
+ public void jjtClose();
+
+ /** This pair of methods are used to inform the node of its
+ parent. */
+ public void jjtSetParent(Node n);
+ public Node jjtGetParent();
+
+ /** This method tells the node to add its argument to the node's
+ list of children. */
+ public void jjtAddChild(Node n, int i);
+
+ /** This method returns a child node. The children are numbered
+ from zero, left to right. */
+ public Node jjtGetChild(int i);
+
+ /** Return the number of children the node has. */
+ public int jjtGetNumChildren();
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/PatternMatchNode.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/PatternMatchNode.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/PatternMatchNode.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/PatternMatchNode.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,48 @@
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+
+/**
+ * Superclass of pattern matching nodes. Assumes that subclass is a binary expression with
+ * the second operand being a pattern.
+ *
+ * @since 1.1
+ */
+public abstract class PatternMatchNode extends ConditionNode {
+
+ protected boolean patternCompiled;
+ protected boolean ignoringCase;
+
+ PatternMatchNode(int i, boolean ignoringCase) {
+ super(i);
+ this.ignoringCase = ignoringCase;
+ }
+
+ @Override
+ public void jjtAddChild(Node n, int i) {
+ // reset pattern if the node is modified
+ if (i == 1) {
+ patternCompiled = false;
+ }
+
+ super.jjtAddChild(n, i);
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/SimpleNode.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/SimpleNode.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/SimpleNode.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/exp/parser/SimpleNode.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,246 @@
+/* Generated By:JJTree: Do not edit this line. SimpleNode.java */
+
+/*****************************************************************
+ * 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.cayenne.exp.parser;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionException;
+
+/**
+ * Superclass of AST* expressions that implements Node interface defined by JavaCC
+ * framework.
+ * <p>
+ * Some parts of the parser are based on OGNL parser, copyright (c) 2002, Drew Davidson
+ * and Luke Blanshard.
+ * </p>
+ *
+ * @since 1.1
+ */
+public abstract class SimpleNode extends Expression implements Node {
+
+ protected Node parent;
+ protected Node[] children;
+ protected int id;
+
+ protected SimpleNode(int i) {
+ id = i;
+ }
+
+ /**
+ * Always returns empty map.
+ *
+ * @since 3.0
+ */
+ @Override
+ public Map<String, String> getPathAliases() {
+ return Collections.emptyMap();
+ }
+
+ protected abstract String getExpressionOperator(int index);
+
+ /**
+ * Returns operator for ebjql statements, which can differ for Cayenne expression operator
+ */
+ protected String getEJBQLExpressionOperator(int index) {
+ return getExpressionOperator(index);
+ }
+
+ @Override
+ protected boolean pruneNodeForPrunedChild(Object prunedChild) {
+ return true;
+ }
+
+ /**
+ * Implemented for backwards compatibility with exp package.
+ */
+ @Override
+ public String expName() {
+ return ExpressionParserTreeConstants.jjtNodeName[id];
+ }
+
+ /**
+ * Flattens the tree under this node by eliminating any children that are of the same
+ * class as this node and copying their children to this node.
+ */
+ @Override
+ protected void flattenTree() {
+ boolean shouldFlatten = false;
+ int newSize = 0;
+
+ for (Node child : children) {
+ if (child.getClass() == getClass()) {
+ shouldFlatten = true;
+ newSize += child.jjtGetNumChildren();
+ }
+ else {
+ newSize++;
+ }
+ }
+
+ if (shouldFlatten) {
+ Node[] newChildren = new Node[newSize];
+ int j = 0;
+
+ for (Node c : children) {
+ if (c.getClass() == getClass()) {
+ for (int k = 0; k < c.jjtGetNumChildren(); ++k) {
+ newChildren[j++] = c.jjtGetChild(k);
+ }
+ }
+ else {
+ newChildren[j++] = c;
+ }
+ }
+
+ if (j != newSize) {
+ throw new ExpressionException("Assertion error: " + j + " != " + newSize);
+ }
+
+ this.children = newChildren;
+ }
+ }
+
+ @Override
+ public Object getOperand(int index) {
+ Node child = jjtGetChild(index);
+
+ // unwrap ASTScalar nodes - this is likely a temporary thing to keep it compatible
+ // with QualifierTranslator. In the future we might want to keep scalar nodes
+ // for the purpose of expression evaluation.
+ return unwrapChild(child);
+ }
+
+ protected Node wrapChild(Object child) {
+ // when child is null, there's no way of telling whether this is a scalar or
+ // not... fuzzy... maybe we should stop using this method - it is too generic
+ return (child instanceof Node || child == null) ? (Node) child : new ASTScalar(
+ child);
+ }
+
+ protected Object unwrapChild(Node child) {
+ return (child instanceof ASTScalar) ? ((ASTScalar) child).getValue() : child;
+ }
+
+ @Override
+ public int getOperandCount() {
+ return jjtGetNumChildren();
+ }
+
+ @Override
+ public void setOperand(int index, Object value) {
+ Node node = (value == null || value instanceof Node)
+ ? (Node) value
+ : new ASTScalar(value);
+ jjtAddChild(node, index);
+
+ // set the parent, as jjtAddChild doesn't do it...
+ if (node != null) {
+ node.jjtSetParent(this);
+ }
+ }
+
+ public void jjtOpen() {
+
+ }
+
+ public void jjtClose() {
+
+ }
+
+ public void jjtSetParent(Node n) {
+ parent = n;
+ }
+
+ public Node jjtGetParent() {
+ return parent;
+ }
+
+ public void jjtAddChild(Node n, int i) {
+ if (children == null) {
+ children = new Node[i + 1];
+ }
+ else if (i >= children.length) {
+ Node c[] = new Node[i + 1];
+ System.arraycopy(children, 0, c, 0, children.length);
+ children = c;
+ }
+ children[i] = n;
+ }
+
+ public Node jjtGetChild(int i) {
+ return children[i];
+ }
+
+ public final int jjtGetNumChildren() {
+ return (children == null) ? 0 : children.length;
+ }
+
+ /**
+ * Evaluates itself with object, pushing result on the stack.
+ */
+ protected abstract Object evaluateNode(Object o) throws Exception;
+
+ /**
+ * Sets the parent to this for all children.
+ *
+ * @since 3.0
+ */
+ protected void connectChildren() {
+ if (children != null) {
+ for (Node child : children) {
+ // although nulls are expected to be wrapped in scalar, still doing a
+ // check here to make it more robust
+ if (child != null) {
+ child.jjtSetParent(this);
+ }
+ }
+ }
+ }
+
+ protected Object evaluateChild(int index, Object o) throws Exception {
+ SimpleNode node = (SimpleNode) jjtGetChild(index);
+ return node != null ? node.evaluate(o) : null;
+ }
+
+ @Override
+ public Expression notExp() {
+ return new ASTNot(this);
+ }
+
+ @Override
+ public Object evaluate(Object o) {
+ // wrap in try/catch to provide unified exception processing
+ try {
+ return evaluateNode(o);
+ }
+ catch (Throwable th) {
+ String string = this.toString();
+ throw new ExpressionException(
+ "Error evaluating expression '" + string + "'",
+ string,
+ th);
+ }
+ }
+
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,90 @@
+/*****************************************************************
+ * 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.cayenne.query;
+
+import java.io.Serializable;
+
+
+/**
+ * A common superclass of Cayenne queries.
+ *
+ */
+public abstract class AbstractQuery<T> implements Query, Serializable {
+
+ /**
+ * The root object this query. May be an entity name, Java class, ObjEntity or
+ * DbEntity, depending on the specific query and how it was constructed.
+ */
+ protected T root;
+ protected String name;
+
+ /**
+ * Returns a symbolic name of the query.
+ *
+ * @since 1.1
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets a symbolic name of the query.
+ *
+ * @since 1.1
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the root of this query.
+ */
+ public Object getRoot() {
+ return root;
+ }
+
+ /**
+ * Sets the root of the query
+ *
+ * @param value The new root
+ * @throws IllegalArgumentException if value is not a String, ObjEntity, DbEntity,
+ * Procedure, DataMap, Class or null.
+ */
+ public void setRoot(Object value) {
+ if (value == null) {
+ this.root = null;
+ }
+
+ // sanity check
+ if (!((value instanceof String) || (value instanceof Class))) {
+
+ String rootClass = (value != null) ? value.getClass().getName() : "null";
+
+ throw new IllegalArgumentException(
+ getClass().getName()
+ + ": \"setRoot(..)\" takes a String "
+ + "or Class. It was passed a "
+ + rootClass);
+ }
+
+ this.root = (T) value;
+ }
+
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery_CustomFieldSerializer.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery_CustomFieldSerializer.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery_CustomFieldSerializer.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/AbstractQuery_CustomFieldSerializer.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,38 @@
+/*****************************************************************
+ * 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.cayenne.query;
+
+import com.google.gwt.user.client.rpc.SerializationException;
+import com.google.gwt.user.client.rpc.SerializationStreamReader;
+import com.google.gwt.user.client.rpc.SerializationStreamWriter;
+
+public class AbstractQuery_CustomFieldSerializer {
+ public static void serialize(SerializationStreamWriter streamWriter, AbstractQuery instance)
+ throws SerializationException {
+
+ streamWriter.writeString(instance.getName());
+ streamWriter.writeObject(instance.getRoot());
+ }
+
+ public static void deserialize(SerializationStreamReader streamReader, AbstractQuery instance)
+ throws SerializationException {
+ instance.setName(streamReader.readString());
+ instance.setRoot(streamReader.readObject());
+ }
+}
Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/BaseQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/BaseQueryMetadata.java?rev=920884&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/BaseQueryMetadata.java (added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/BaseQueryMetadata.java Tue Mar 9 14:16:07 2010
@@ -0,0 +1,367 @@
+/*****************************************************************
+ * 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.cayenne.query;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+/**
+ * Default mutable implementation of {@link QueryMetadata}.
+ *
+ * @since 1.1
+ */
+class BaseQueryMetadata implements QueryMetadata, Serializable {
+
+ int fetchLimit = QueryMetadata.FETCH_LIMIT_DEFAULT;
+ int fetchOffset = QueryMetadata.FETCH_OFFSET_DEFAULT;
+
+ int statementFetchSize = QueryMetadata.FETCH_OFFSET_DEFAULT;
+
+ int pageSize = QueryMetadata.PAGE_SIZE_DEFAULT;
+ boolean fetchingDataRows = QueryMetadata.FETCHING_DATA_ROWS_DEFAULT;
+ QueryCacheStrategy cacheStrategy = QueryCacheStrategy.getDefaultStrategy();
+
+ PrefetchTreeNode prefetchTree;
+ String cacheKey;
+ String[] cacheGroups;
+
+ transient List<Object> resultSetMapping;
+ transient Object lastRoot;
+
+ /**
+ * Copies values of another QueryMetadata object to this object.
+ */
+ void copyFromInfo(QueryMetadata info) {
+ this.lastRoot = null;
+
+ this.fetchingDataRows = info.isFetchingDataRows();
+ this.fetchLimit = info.getFetchLimit();
+ this.pageSize = info.getPageSize();
+ this.cacheStrategy = info.getCacheStrategy();
+ this.cacheKey = info.getCacheKey();
+ this.resultSetMapping = info.getResultSetMapping();
+
+ setPrefetchTree(info.getPrefetchTree());
+ }
+
+ void initWithProperties(Map<String, ?> properties) {
+ // must init defaults even if properties are empty
+ if (properties == null) {
+ properties = Collections.EMPTY_MAP;
+ }
+
+ Object fetchOffset = properties.get(QueryMetadata.FETCH_OFFSET_PROPERTY);
+ Object fetchLimit = properties.get(QueryMetadata.FETCH_LIMIT_PROPERTY);
+ Object pageSize = properties.get(QueryMetadata.PAGE_SIZE_PROPERTY);
+ Object statementFetchSize = properties.get(QueryMetadata.STATEMENT_FETCH_SIZE_PROPERTY);
+ Object fetchingDataRows = properties
+ .get(QueryMetadata.FETCHING_DATA_ROWS_PROPERTY);
+
+ // deprecated cache policy... handle it for backwards compatibility.
+ Object cachePolicy = properties.get(QueryMetadata.CACHE_POLICY_PROPERTY);
+ Object cacheStrategy = properties.get(QueryMetadata.CACHE_STRATEGY_PROPERTY);
+
+ Object cacheGroups = properties.get(QueryMetadata.CACHE_GROUPS_PROPERTY);
+
+ // init ivars from properties
+ this.fetchOffset = (fetchOffset != null) ? Integer.parseInt(fetchOffset
+ .toString()) : QueryMetadata.FETCH_OFFSET_DEFAULT;
+
+ this.fetchLimit = (fetchLimit != null)
+ ? Integer.parseInt(fetchLimit.toString())
+ : QueryMetadata.FETCH_LIMIT_DEFAULT;
+
+ this.pageSize = (pageSize != null)
+ ? Integer.parseInt(pageSize.toString())
+ : QueryMetadata.PAGE_SIZE_DEFAULT;
+
+ this.statementFetchSize = (statementFetchSize != null)
+ ? Integer.parseInt(statementFetchSize.toString())
+ : QueryMetadata.STATEMENT_FETCH_SIZE_DEFAULT;
+
+ this.fetchingDataRows = (fetchingDataRows != null)
+ ? "true".equalsIgnoreCase(fetchingDataRows.toString())
+ : QueryMetadata.FETCHING_DATA_ROWS_DEFAULT;
+
+ this.cacheStrategy = (cacheStrategy != null) ? QueryCacheStrategy
+ .safeValueOf(cacheStrategy.toString()) : QueryCacheStrategy
+ .getDefaultStrategy();
+
+ // use legacy cachePolicy if it is provided and no strategy is set...
+ if (cacheStrategy == null && cachePolicy != null) {
+ setCachePolicy(cachePolicy.toString());
+ }
+
+ this.cacheGroups = null;
+ if (cacheGroups instanceof String[]) {
+ this.cacheGroups = (String[]) cacheGroups;
+ }
+ else if (cacheGroups instanceof String) {
+ StringTokenizer toks = new StringTokenizer(cacheGroups.toString(), ",");
+ this.cacheGroups = new String[toks.countTokens()];
+ for (int i = 0; i < this.cacheGroups.length; i++) {
+ this.cacheGroups[i] = toks.nextToken();
+ }
+ }
+ }
+
+ /**
+ * @since 1.2
+ */
+ public String getCacheKey() {
+ return cacheKey;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public Map<String, String> getPathSplitAliases() {
+ return Collections.emptyMap();
+ }
+
+ /**
+ * @since 3.0
+ */
+ public List<Object> getResultSetMapping() {
+ return resultSetMapping;
+ }
+
+ /**
+ * @since 1.2
+ */
+ public PrefetchTreeNode getPrefetchTree() {
+ return prefetchTree;
+ }
+
+ void setPrefetchTree(PrefetchTreeNode prefetchTree) {
+ this.prefetchTree = prefetchTree;
+ }
+
+ /**
+ * @deprecated since 3.0 {@link #getCacheStrategy()} replaces this method.
+ */
+ @Deprecated
+ public String getCachePolicy() {
+ if (cacheStrategy == null) {
+ return QueryMetadata.CACHE_POLICY_DEFAULT;
+ }
+
+ switch (cacheStrategy) {
+ case NO_CACHE:
+ return QueryMetadata.NO_CACHE;
+ case LOCAL_CACHE:
+ return QueryMetadata.LOCAL_CACHE;
+ case LOCAL_CACHE_REFRESH:
+ return QueryMetadata.LOCAL_CACHE_REFRESH;
+ case SHARED_CACHE:
+ return QueryMetadata.SHARED_CACHE;
+ case SHARED_CACHE_REFRESH:
+ return QueryMetadata.SHARED_CACHE_REFRESH;
+
+ default:
+ return QueryMetadata.CACHE_POLICY_DEFAULT;
+ }
+ }
+
+ /**
+ * @deprecated since 3.0 {@link #setCacheStrategy(QueryCacheStrategy)} replaces this
+ * method.
+ */
+ @Deprecated
+ void setCachePolicy(String policy) {
+ if (policy == null) {
+ cacheStrategy = null;
+ }
+ else if (QueryMetadata.NO_CACHE.equals(policy)) {
+ cacheStrategy = QueryCacheStrategy.NO_CACHE;
+ }
+ else if (QueryMetadata.LOCAL_CACHE.equals(policy)) {
+ cacheStrategy = QueryCacheStrategy.LOCAL_CACHE;
+ }
+ else if (QueryMetadata.LOCAL_CACHE_REFRESH.equals(policy)) {
+ cacheStrategy = QueryCacheStrategy.LOCAL_CACHE_REFRESH;
+ }
+ else if (QueryMetadata.SHARED_CACHE.equals(policy)) {
+ cacheStrategy = QueryCacheStrategy.SHARED_CACHE;
+ }
+ else if (QueryMetadata.SHARED_CACHE_REFRESH.equals(policy)) {
+ cacheStrategy = QueryCacheStrategy.SHARED_CACHE_REFRESH;
+ }
+ else {
+ cacheStrategy = QueryCacheStrategy.NO_CACHE;
+ }
+ }
+
+ /**
+ * @since 3.0
+ */
+ public QueryCacheStrategy getCacheStrategy() {
+ return cacheStrategy;
+ }
+
+ /**
+ * @since 3.0
+ */
+ void setCacheStrategy(QueryCacheStrategy cacheStrategy) {
+ this.cacheStrategy = cacheStrategy;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public String[] getCacheGroups() {
+ return cacheGroups;
+ }
+
+ /**
+ * @since 3.0
+ */
+ void setCacheGroups(String... groups) {
+ this.cacheGroups = groups;
+ }
+
+ public boolean isFetchingDataRows() {
+ return fetchingDataRows;
+ }
+
+ public int getFetchLimit() {
+ return fetchLimit;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public Query getOrginatingQuery() {
+ return null;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public int getFetchOffset() {
+ return fetchOffset;
+ }
+
+ /**
+ * @deprecated since 3.0
+ */
+ @Deprecated
+ public int getFetchStartIndex() {
+ return getFetchOffset();
+ }
+
+ public boolean isRefreshingObjects() {
+ return true;
+ }
+
+ /**
+ * @deprecated since 3.0. Inheritance resolving is not optional anymore.
+ */
+ @Deprecated
+ public boolean isResolvingInherited() {
+ return true;
+ }
+
+ void setFetchingDataRows(boolean b) {
+ fetchingDataRows = b;
+ }
+
+ void setFetchLimit(int i) {
+ fetchLimit = i;
+ }
+
+ void setFetchOffset(int i) {
+ fetchOffset = i;
+ }
+
+ void setPageSize(int i) {
+ pageSize = i;
+ }
+
+ /**
+ * Sets statement's fetch size (0 for no default size)
+ * @since 3.0
+ */
+ void setStatementFetchSize(int size) {
+ this.statementFetchSize = size;
+ }
+
+ /**
+ * @return statement's fetch size
+ * @since 3.0
+ */
+ public int getStatementFetchSize() {
+ return statementFetchSize;
+ }
+
+ /**
+ * Adds a joint prefetch.
+ *
+ * @since 1.2
+ */
+ PrefetchTreeNode addPrefetch(String path, int semantics) {
+ if (prefetchTree == null) {
+ prefetchTree = new PrefetchTreeNode();
+ }
+
+ PrefetchTreeNode node = prefetchTree.addPath(path);
+ node.setSemantics(semantics);
+ node.setPhantom(false);
+ return node;
+ }
+
+ /**
+ * Adds all prefetches from a provided collection.
+ *
+ * @since 1.2
+ */
+ void addPrefetches(Collection<String> prefetches, int semantics) {
+ if (prefetches != null) {
+ for (String prefetch : prefetches) {
+ addPrefetch(prefetch, semantics);
+ }
+ }
+ }
+
+ /**
+ * Clears all joint prefetches.
+ *
+ * @since 1.2
+ */
+ void clearPrefetches() {
+ prefetchTree = null;
+ }
+
+ /**
+ * Removes joint prefetch.
+ *
+ * @since 1.2
+ */
+ void removePrefetch(String prefetch) {
+ if (prefetchTree != null) {
+ prefetchTree.removePath(prefetch);
+ }
+ }
+}