openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r723553 [3/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...
Date Fri, 05 Dec 2008 01:37:16 GMT
Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinusExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinusExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinusExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/MinusExpression.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 MinusExpression extends BinaryOperatorExpression {
+	public MinusExpression(Expression op, Expression op2) {
+		super(op, BinaryFunctionalOperator.MINUS, op2);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ModExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ModExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ModExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ModExpression.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,37 @@
+/*
+ * 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 MOD(e1, e2) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+class ModExpression extends BinaryOperatorExpression {
+	public ModExpression(ExpressionImpl op, ExpressionImpl op2) {
+		super(op, BinaryFunctionalOperator.MOD, op2);
+	}
+	
+	@Override
+	public String asExpression(AliasContext ctx) {
+		return _op + "(" + ((Visitable)_e1).asExpression(ctx)
+		     + "," + ((Visitable)_e2).asExpression(ctx);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NavigationPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NavigationPath.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NavigationPath.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NavigationPath.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.PathExpression;
+import static org.apache.openjpa.persistence.query.PathOperator.NAVIGATION;
+/**
+ * Represents a path resulted by navigation.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+class NavigationPath extends AbstractDomainObject implements PathExpression {
+	protected NavigationPath(QueryDefinitionImpl owner, AbstractPath parent, 
+		String attr) {
+		super(owner, parent, NAVIGATION, attr);
+	}
+	
+	@Override
+	public String getLastSegment() {
+		return (String)super.getLastSegment();
+	}
+	
+	@Override
+	public String asProjection(AliasContext ctx) {
+		AbstractPath parent = getParent();
+		if (ctx.hasAlias(parent))
+			return ctx.getAlias(parent) + NAVIGATION + getLastSegment();
+		return getParent().asProjection(ctx) + NAVIGATION + getLastSegment();
+	}
+		
+	@Override
+	public String asExpression(AliasContext ctx) {
+		return getParent().asExpression(ctx) + NAVIGATION + getLastSegment();
+	}
+	
+	/**
+	 * A navigation path is joinable only when it represents domain of a  
+	 * subquery.
+	 * @see QueryDefinitionImpl#addSubqueryRoot(PathExpression)
+	 */
+	@Override
+	public String asJoinable(AliasContext ctx) {
+		return asProjection(ctx) + " " + ctx.getAlias(this);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NewInstance.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NewInstance.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NewInstance.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NewInstance.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.persistence.OrderByItem;
+import javax.persistence.SelectItem;
+
+/**
+ * Denotes NEW fully.qualified.class.name(arg1, arg2,...) 
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class NewInstance implements Selectable {
+	private final Class _cls;
+	private List<SelectItem> _args;
+	NewInstance(Class cls, SelectItem...args) {
+		_cls = cls;
+		if (args != null) {
+			_args = Arrays.asList(args);
+		}
+	}
+	
+	public OrderByItem asc() {
+		throw new UnsupportedOperationException();
+	}
+
+	public OrderByItem desc() {
+		throw new UnsupportedOperationException();
+	}
+	
+	
+	public String asProjection(AliasContext ctx) {
+		StringBuffer tmp = new StringBuffer("NEW ").append(_cls.getName())
+		    .append("(");
+		if (_args == null || _args.isEmpty())
+			return tmp.append(")").toString();
+		int i = 0;
+		int N = _args.size();
+		for (SelectItem arg : _args) {
+			i++;
+			tmp.append(((Selectable)arg).asProjection(ctx))
+			   .append(i == N ? ")" : ",");
+		}
+		return tmp.toString();
+	}
+	
+	public void setAlias(AliasContext ctx) {
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NotEqualExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NotEqualExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NotEqualExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/NotEqualExpression.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 NotEqualExpression extends BinaryExpressionPredicate {
+	public NotEqualExpression(Expression op1, Expression op2) {
+		super(op1, BinaryConditionalOperator.EQUAL_NOT, 
+			BinaryConditionalOperator.EQUAL, op2);
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OperatorPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OperatorPath.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OperatorPath.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OperatorPath.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,58 @@
+/*
+ * 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 org.apache.openjpa.util.InternalException;
+
+/**
+ * A path resulting from KEY() or VALUE() operation on an existing path.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class OperatorPath extends AbstractDomainObject {
+	public OperatorPath(AbstractDomainObject operand, PathOperator operator) {
+		super(operand.getOwner(), operand, operator, null);
+	}
+		
+	@Override
+	public Class getLastSegment() {
+		throw new InternalException();
+	}
+
+	@Override
+	public String getAliasHint() {
+		return getParent().getAliasHint();
+	}
+	
+	@Override
+	public String asProjection(AliasContext ctx) {
+		return getOperator() + "(" + getParent().asProjection(ctx) + ")";
+	}
+	
+	@Override
+	public String asExpression(AliasContext ctx) {
+		return getOperator() + "(" + getParent().asExpression(ctx) + ")";
+	}
+		
+	@Override
+	public String asJoinable(AliasContext ctx) {
+		throw new UnsupportedOperationException();
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrPredicate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrPredicate.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrPredicate.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrPredicate.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.Predicate;
+import static org.apache.openjpa.persistence.query.ConditionalOperator.*;
+
+/**
+ * Denotes (e1 OR e2) predicate.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class OrPredicate extends LogicalPredicate {
+
+	public OrPredicate(Predicate p1, Predicate p2) {
+		super(p1, OR, AND, p2);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrderableItem.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrderableItem.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrderableItem.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/OrderableItem.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.OrderByItem;
+
+/**
+ * Denotes an item of ORDER BY clause.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class OrderableItem implements OrderByItem {
+	private final Boolean _asc;
+	private final ExpressionImpl path;
+	
+	OrderableItem(ExpressionImpl path) {
+		this(path, null);
+	}
+	
+	OrderableItem(ExpressionImpl path, Boolean asc) {
+		super();
+		this._asc = asc;
+		this.path = path;
+	}
+	
+	public String toJPQL(AliasContext ctx) {
+		return path.asExpression(ctx) + " " 
+		    + (_asc == null ? "" : (_asc ? " ASC " : "DESC"));
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ParameterExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ParameterExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ParameterExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ParameterExpression.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,36 @@
+/*
+ * 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 parameter in a query.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class ParameterExpression extends ConstantExpression {
+	public ParameterExpression(String name) {
+		super(name);
+	}
+	
+	@Override
+	public String asExpression(AliasContext ctx) {
+		return ":" + getValue();
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PathOperator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PathOperator.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PathOperator.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PathOperator.java Thu Dec  4 17:37:13 2008
@@ -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.openjpa.persistence.query;
+
+/**
+ * Operator that combines two components to form a path.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public enum PathOperator {
+	NONE(" "),
+	INNER(" JOIN "),
+	OUTER(" LEFT JOIN "),
+	FETCH_INNER(" JOIN FETCH "),
+	FETCH_OUTER(" LEFT JOIN FETCH "),
+	NAVIGATION("."),
+	KEY("KEY"),
+	ROOT(""),
+	VALUE("VALUE"),
+	ENTRY("ENTRY");
+	
+	private final String _symbol;
+	
+	PathOperator(String symbol) {
+		_symbol = symbol;
+	}
+	
+	public String toString() {
+		return _symbol;
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PlusExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PlusExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PlusExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/PlusExpression.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 PlusExpression extends BinaryOperatorExpression {
+	public PlusExpression(Expression op, Expression op2) {
+		super(op, BinaryFunctionalOperator.PLUS, op2);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryBuilderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryBuilderImpl.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryBuilderImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryBuilderImpl.java Thu Dec  4 17:37:13 2008
@@ -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.openjpa.persistence.query;
+
+import javax.persistence.DomainObject;
+import javax.persistence.PathExpression;
+import javax.persistence.QueryBuilder;
+import javax.persistence.QueryDefinition;
+
+/**
+ * The factory for QueryDefinition.
+ * 
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class QueryBuilderImpl implements QueryBuilder {
+	/**
+	 * Creates a QueryDefinition without a domain root.
+	 */
+	public QueryDefinition createQueryDefinition() {
+		return new QueryDefinitionImpl(this);
+	}
+
+	/**
+	 * Creates a QueryDefinition with given class as domain root.
+	 */
+	public DomainObject createQueryDefinition(Class root) {
+		return new QueryDefinitionImpl(this).addRoot(root);
+	}
+
+	/**
+	 * Creates a QueryDefinition that can be used as a subquery to some
+	 * other query.
+	 */
+	public DomainObject createSubqueryDefinition(PathExpression path) {
+		return new QueryDefinitionImpl(this).addSubqueryRoot(path);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryDefinitionImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryDefinitionImpl.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryDefinitionImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryDefinitionImpl.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,425 @@
+/*
+ * 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.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.CaseExpression;
+import javax.persistence.DomainObject;
+import javax.persistence.Expression;
+import javax.persistence.OrderByItem;
+import javax.persistence.PathExpression;
+import javax.persistence.Predicate;
+import javax.persistence.QueryDefinition;
+import javax.persistence.SelectItem;
+import javax.persistence.Subquery;
+
+import org.apache.openjpa.lib.util.Localizer;
+
+/**
+ * Implements QueryDefinition.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class QueryDefinitionImpl extends ExpressionImpl 
+    implements QueryDefinition, Expression  {
+	private final QueryBuilderImpl _builder;
+	private List<AbstractDomainObject> _domains;
+	private List<PathExpression> _groupBys;
+	private List<Subquery> _subqueries;
+	private List<OrderableItem> _orderBys;
+	private List<Selectable>  _projections;
+	private boolean  _distinct;
+	private Predicate _where;
+	private Predicate _having;
+	
+	protected static Localizer _loc = 
+		Localizer.forPackage(QueryDefinitionImpl.class);
+	
+	protected QueryDefinitionImpl(QueryBuilderImpl builder) {
+		_builder = builder;
+	}
+	
+	/**
+	 * Root domain object has no parent, no path but a non-null Class.
+	 */
+	public DomainObject addRoot(Class cls) {
+		RootPath root = new RootPath(this, cls);
+		addDomain(root);
+		return root;
+	}
+	
+	public DomainObject addSubqueryRoot(PathExpression path) {
+		if (_domains != null && _domains.contains(path))
+			throw new IllegalArgumentException(_loc.get("query-subroot-clash", 
+					path).toString());
+		AbstractPath impl = (AbstractPath)path;
+		if (_subqueries == null) 
+			_subqueries = new ArrayList<Subquery>();
+		AbstractDomainObject newRoot = new NavigationPath(this, impl.getParent(), 
+				impl.getLastSegment().toString());
+		addDomain(newRoot);
+		return newRoot;
+	}
+	
+	protected void addDomain(AbstractDomainObject path) {
+		if (_domains == null)
+			_domains = new ArrayList<AbstractDomainObject>();
+		_domains.add(path);
+	}
+
+	public Subquery all() {
+		return new AllExpression(this);
+	}
+
+	public Subquery any() {
+		return new AnyExpression(this);
+	}
+
+	public Expression coalesce(Expression... exp) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression coalesce(String... exp) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression coalesce(Date... exp) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression coalesce(Calendar... exp) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression currentDate() {
+		return new CurrentTimeExpression(Date.class);
+	}
+
+	public Expression currentTime() {
+		return new CurrentTimeExpression(Time.class);
+	}
+
+	public Expression currentTimestamp() {
+		return new CurrentTimeExpression(Timestamp.class);
+	}
+
+	public Predicate exists() {
+		return new ExistsExpression(this);
+	}
+
+	public CaseExpression generalCase() {
+		return new CaseExpressionImpl();
+	}
+
+	public QueryDefinition groupBy(PathExpression... pathExprs) {
+		if (_groupBys == null) {
+			_groupBys = new ArrayList<PathExpression>();
+		}
+		for (PathExpression e : pathExprs)
+			_groupBys.add(e);
+		return this;
+	}
+
+	public QueryDefinition groupBy(List<PathExpression> pathExprList) {
+		if (_groupBys == null) {
+			_groupBys = new ArrayList<PathExpression>();
+		}
+		for (PathExpression e : pathExprList)
+			_groupBys.add(e);
+		return this;
+	}
+
+	public QueryDefinition having(Predicate predicate) {
+		_having = predicate;
+		return this;
+	}
+
+	public Expression literal(String s) {
+		return new LiteralExpression(s);
+	}
+
+	public Expression literal(Number n) {
+		return new LiteralExpression(n);
+	}
+
+	public Expression literal(boolean b) {
+		return new LiteralExpression(b);
+	}
+
+	public Expression literal(Calendar c) {
+		return new LiteralExpression(c);
+	}
+
+	public Expression literal(Date d) {
+		return new LiteralExpression(d);
+	}
+
+	public Expression literal(char c) {
+		return new LiteralExpression(c);
+	}
+
+	public Expression literal(Class cls) {
+		return new LiteralExpression(cls);
+	}
+
+	public Expression literal(Enum<?> e) {
+		return new LiteralExpression(e);
+	}
+
+	public Expression nullLiteral() {
+		return new LiteralExpression(null);
+	}
+
+	public SelectItem newInstance(Class cls, SelectItem... args) {
+		return new NewInstance(cls, args);
+	}
+
+	public Expression nullif(Expression exp1, Expression exp2) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression nullif(Number arg1, Number arg2) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression nullif(String arg1, String arg2) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression nullif(Date arg1, Date arg2) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression nullif(Calendar arg1, Calendar arg2) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression nullif(Class arg1, Class arg2) {
+		throw new UnsupportedOperationException();
+	}
+
+	public Expression nullif(Enum<?> arg1, Enum<?> arg2) {
+		throw new UnsupportedOperationException();
+	}
+
+	public QueryDefinition orderBy(OrderByItem... orderByItems) {
+		if (_orderBys == null)
+			_orderBys = new ArrayList<OrderableItem>();
+		for (OrderByItem i : orderByItems) {
+			if (i instanceof OrderableItem)
+				_orderBys.add((OrderableItem)i);
+			else
+				_orderBys.add(new OrderableItem((ExpressionImpl)i, null));
+		}
+		return this;
+	}
+
+	public QueryDefinition orderBy(List<OrderByItem> orderByItemList) {
+		if (_orderBys == null)
+			_orderBys = new ArrayList<OrderableItem>();
+		for (OrderByItem i : orderByItemList) {
+			if (i instanceof OrderableItem)
+				_orderBys.add((OrderableItem)i);
+			else
+				_orderBys.add(new OrderableItem((ExpressionImpl)i, null));
+		}
+		return this;
+	}
+
+	public Expression param(String name) {
+		return new ParameterExpression(name);
+	}
+
+	public Predicate predicate(boolean b) {
+		return null;
+	}
+
+	public QueryDefinition select(SelectItem... items) {
+		return select(items == null ? null : Arrays.asList(items), false);
+	}
+
+	public QueryDefinition select(List<SelectItem> items) {
+		return select(items, false);
+	}
+
+	public QueryDefinition selectDistinct(SelectItem... items) {
+		return select(items == null ? null : Arrays.asList(items), true);
+	}
+
+	public QueryDefinition selectDistinct(List<SelectItem> items) {
+		return select(items, false);
+	}
+	
+	private QueryDefinition select(List<SelectItem> items, boolean isDistinct) {
+		if (_projections == null) {
+			_projections = new ArrayList<Selectable>();
+		} else {
+			_projections.clear();
+		}
+		_distinct = isDistinct;
+		for (SelectItem item : items)
+			_projections.add((Selectable)item);
+		return this;
+	}
+
+	public CaseExpression simpleCase(Expression caseOperand) {
+		return new CaseExpressionImpl(caseOperand);
+	}
+
+	public CaseExpression simpleCase(Number caseOperand) {
+		return new CaseExpressionImpl(caseOperand);
+	}
+
+	public CaseExpression simpleCase(String caseOperand) {
+		return new CaseExpressionImpl(caseOperand);
+	}
+
+	public CaseExpression simpleCase(Date caseOperand) {
+		return new CaseExpressionImpl(caseOperand);
+	}
+
+	public CaseExpression simpleCase(Calendar caseOperand) {
+		return new CaseExpressionImpl(caseOperand);
+	}
+
+	public CaseExpression simpleCase(Class caseOperand) {
+		return new CaseExpressionImpl(caseOperand);
+	}
+
+	public CaseExpression simpleCase(Enum<?> caseOperand) {
+		return new CaseExpressionImpl(caseOperand);
+	}
+
+	public Subquery some() {
+		return new SomeExpression(this);
+	}
+
+	public QueryDefinition where(Predicate predicate) {
+		_where = predicate;
+		return this;
+	}
+	
+	private List<Selectable> getProjections() {
+		if (_projections == null) {
+			List<Selectable> defaultProjection = new ArrayList<Selectable>();
+			defaultProjection.add(_domains.get(0));
+			return defaultProjection;
+		}
+		return _projections;
+	}
+
+	public String toJPQL() {
+		return asExpression(new AliasContext());
+	}
+	
+	/**
+	 * 
+	 */
+	@Override
+	public String asExpression(AliasContext ctx) {
+		StringBuffer buffer = new StringBuffer();
+		registerDomains(ctx);
+		buffer.append("SELECT ");
+		if (_distinct) 
+			buffer.append("DISTINCT ");
+		List<Selectable> projs = getProjections();
+		for (int i=0; i < projs.size(); i++) {
+			projs.get(i).setAlias(ctx);
+			buffer.append(projs.get(i).asProjection(ctx));
+			if (i != projs.size()-1)
+				buffer.append(",");
+		}
+		buffer.append(" FROM ");
+		for (int i=0; _domains != null && i < _domains.size(); i++) {
+			buffer.append(_domains.get(i).asJoinable(ctx));
+			List<JoinPath> joins = _domains.get(i).getJoins();
+			if (joins != null) {
+				for (int j = 0; j < joins.size(); j++) {
+					buffer.append(joins.get(j).asJoinable(ctx));
+				}
+			}
+			List<FetchPath> fetchJoins = _domains.get(i).getFetchJoins();
+			if (fetchJoins != null) {
+				for (int j = 0; j < fetchJoins.size(); j++) {
+					buffer.append(fetchJoins.get(j).asExpression(ctx));
+				}
+			}
+			
+			if (i != _domains.size()-1)
+				buffer.append(",");
+		}
+		if (_where != null) {
+			buffer.append(" WHERE ").append(((Visitable)_where).asExpression(ctx));
+		}
+		
+		if (_groupBys != null) {
+			buffer.append(" GROUP BY ");
+			for (int i = 0; i<_groupBys.size(); i++) {
+				buffer.append(((ExpressionImpl)_groupBys.get(i)).asExpression(ctx));
+				if (i != _groupBys.size()-1)
+					buffer.append(",");
+			}
+		}
+		if (_having != null) {
+			buffer.append(" HAVING ").append(((Visitable)_having).asExpression(ctx));
+		}
+		if (_orderBys != null) {
+			buffer.append(" ORDER BY ");
+			for (int i = 0; i<_orderBys.size(); i++) {
+				buffer.append(((OrderableItem)_orderBys.get(i)).toJPQL(ctx));
+				if (i != _orderBys.size()-1)
+					buffer.append(",");
+			}
+		}
+		
+		return buffer.toString();
+	}
+	
+	public String asProjection(AliasContext ctx) {
+		return asExpression(ctx);
+	}
+	
+	/**
+	 * Registers each domain with an alias.
+	 * @param ctx
+	 */
+	private void registerDomains(AliasContext ctx) {
+		if (_domains != null) {
+			for (AbstractDomainObject domain : _domains) {
+				domain.setAlias(ctx);
+			}
+		}
+		if (_subqueries != null) {
+			for (Subquery sub : _subqueries) {
+				if (sub instanceof QueryDefinitionImpl)
+					((QueryDefinitionImpl)sub).registerDomains(ctx);
+				else
+					((AbstractDomainObject)sub).setAlias(ctx);
+			}
+		}
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/QueryExpression.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.Subquery;
+
+/**
+ * An expression resulting from operation on a query itself. Can be used as a 
+ * subquery clause in a parent query.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+abstract class QueryExpression extends UnaryOperatorExpression 
+    implements Subquery {
+	public QueryExpression(QueryDefinitionImpl q, UnaryFunctionalOperator op) {
+		super(q, op);
+	}
+	
+	@Override
+	public String asExpression(AliasContext ctx) {
+		return "(" + super.asExpression(ctx) + ")";
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RangeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RangeExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RangeExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RangeExpression.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 a range used by MEMBER OF operation.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class RangeExpression extends BinaryOperatorExpression {
+	public RangeExpression(Expression e1, Expression e2) {
+		super(e1, BinaryFunctionalOperator.RANGE, e2);
+	}
+	
+	@Override
+	public String asExpression(AliasContext ctx) {
+		return "(" + ((Visitable)_e1).asExpression(ctx) 
+		     + " AND " + ((Visitable)_e2).asExpression(ctx) + ")";
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RootPath.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RootPath.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RootPath.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/RootPath.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,41 @@
+package org.apache.openjpa.persistence.query;
+
+import javax.persistence.DomainObject;
+
+/**
+ * Denotes root domain instance representing a persistent type.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class RootPath extends AbstractDomainObject implements DomainObject {
+
+	public RootPath(QueryDefinitionImpl owner, Class cls) {
+		super(owner, null, PathOperator.ROOT, cls);
+	}
+	
+	@Override
+	public Class getLastSegment() {
+		return (Class)super.getLastSegment();
+	}
+	
+	@Override
+	public String getAliasHint() {
+		return getLastSegment().getSimpleName();
+	}
+
+	@Override
+	public String asExpression(AliasContext ctx) {
+		return ctx.getAlias(this);
+	}
+	
+	@Override
+	public String asJoinable(AliasContext ctx) {
+		return getLastSegment().getSimpleName() + " " + ctx.getAlias(this);
+	}
+	
+	@Override
+	public String asProjection(AliasContext ctx) {
+		return ctx.getAlias(this);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Selectable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Selectable.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Selectable.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Selectable.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;
+
+import javax.persistence.SelectItem;
+
+/**
+ * An item that can be selected in a query.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public interface Selectable extends SelectItem {
+	String asProjection(AliasContext ctx);
+	void setAlias(AliasContext ctx);
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SizeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SizeExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SizeExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SizeExpression.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 SIZE(e) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class SizeExpression extends UnaryOperatorExpression  {
+	public SizeExpression(Expression op) {
+		super(op, UnaryFunctionalOperator.SIZE);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SomeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SomeExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SomeExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SomeExpression.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.Subquery;
+
+/**
+ * Denotes SOME(Subquery) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+class SomeExpression extends UnaryOperatorExpression implements Subquery {
+	public SomeExpression(QueryDefinitionImpl sub) {
+		super(sub, UnaryFunctionalOperator.SOME);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SquareRootExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SquareRootExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SquareRootExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SquareRootExpression.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 SQRT(e) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class SquareRootExpression extends UnaryOperatorExpression {
+	public SquareRootExpression(Expression op) {
+		super(op, UnaryFunctionalOperator.SQRT);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SubStringExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SubStringExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SubStringExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SubStringExpression.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,45 @@
+/*
+ * 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 SUBSTR(a,i1,i2) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class SubStringExpression extends BinaryOperatorExpression {
+	public SubStringExpression(Expression op, Expression op2) {
+		this(op, op2, new ConstantExpression(0));
+	}
+	
+	public SubStringExpression(Expression op, int start) {
+		this(op, start, 0);
+	}
+	
+	public SubStringExpression(Expression op, int start, int len) {
+		this(op, new ConstantExpression(start), new ConstantExpression(len));
+	}
+	
+	public SubStringExpression(Expression op, Expression op2, Expression pos) {
+		super(op, BinaryFunctionalOperator.SUBSTR, op2);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SumExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SumExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SumExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/SumExpression.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 SUM(e) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class SumExpression extends UnaryOperatorExpression  {
+	public SumExpression(Expression op) {
+		super(op, UnaryFunctionalOperator.SUM);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TimesExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TimesExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TimesExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TimesExpression.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 TimesExpression extends BinaryOperatorExpression {
+	public TimesExpression(Expression op1, Expression op2) {
+		super(op1, BinaryFunctionalOperator.TIMES, op2);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ToUpperExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ToUpperExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ToUpperExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ToUpperExpression.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 UPPER(e) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class ToUpperExpression extends UnaryOperatorExpression {
+	public ToUpperExpression(Expression op) {
+		super(op, UnaryFunctionalOperator.UPPER);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TrimExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TrimExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TrimExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TrimExpression.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,41 @@
+/*
+ * 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.TrimSpec;
+
+/**
+ * Denotes TRIM(e1,x) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class TrimExpression extends BinaryOperatorExpression {
+	TrimSpec _spec;
+	public TrimExpression(Expression op1, char ch, TrimSpec spec) {
+		super(op1, BinaryFunctionalOperator.TRIM, new ConstantExpression(ch));
+		_spec = spec;
+	}
+	
+	public TrimExpression(Expression op, Expression op1, TrimSpec spec) {
+		super(op, BinaryFunctionalOperator.TRIM, op1);
+		_spec = spec;
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TypeExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TypeExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TypeExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/TypeExpression.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 TYPE(e) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class TypeExpression extends UnaryOperatorExpression {
+	public TypeExpression(Expression op) {
+		super(op, UnaryFunctionalOperator.TYPE);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryConditionalOperator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryConditionalOperator.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryConditionalOperator.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryConditionalOperator.java Thu Dec  4 17:37:13 2008
@@ -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.openjpa.persistence.query;
+
+/**
+ * Enumeration of operator that operates on a single expression to generate 
+ * a predicate.
+ * 
+ * @see UnaryOperatorExpression
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public enum UnaryConditionalOperator {
+	EXISTS("EXISTS"),
+	EXISTS_NOT("NOT EXISTS"),
+	
+	ISEMPTY("IS EMPTY"),
+	ISEMPTY_NOT("IS NOT EMPTY"),
+	ISNULL("IS NULL"),
+	ISNULL_NOT("IS NOT NULL"),
+	SOME("SOME");
+	
+	private final String _symbol;
+	
+	UnaryConditionalOperator(String symbol) {
+		_symbol = symbol;
+	}
+	
+	public String toString() {
+		return _symbol;
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryExpressionPredicate.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryExpressionPredicate.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryExpressionPredicate.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryExpressionPredicate.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+/**
+ * Unary Predicate results from an operator on an Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+class UnaryExpressionPredicate implements Predicate, Visitable {
+	protected final Expression _e;
+	protected final UnaryConditionalOperator _op;
+	private final UnaryConditionalOperator _nop;
+
+	public UnaryExpressionPredicate(Expression e, UnaryConditionalOperator op, 
+		UnaryConditionalOperator nop) {
+		this._e   = e;
+		this._op  = op;
+		this._nop = nop;
+	}
+	
+	public Expression getOperand() {
+		return _e;
+	}
+	
+	public UnaryConditionalOperator 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 UnaryExpressionPredicate(_e, _nop, _op);
+	}
+
+	public String asExpression(AliasContext ctx) {
+		return _op + "(" + ((ExpressionImpl)_e).asExpression(ctx) + ")";
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryFunctionalOperator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryFunctionalOperator.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryFunctionalOperator.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryFunctionalOperator.java Thu Dec  4 17:37:13 2008
@@ -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.openjpa.persistence.query;
+
+/**
+ * Enumeration of operator that operates on a single expression to generate 
+ * another expression.
+ * 
+ * @see UnaryOperatorExpression
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public enum UnaryFunctionalOperator {
+	ABS("ABS"),
+	ALL("ALL"),
+	ANY("ANY"),
+	AVG("AVG"),
+	COUNT("COUNT"),
+	DISTINCT("DISTINCT"),
+	EXISTS("EXISTS"),
+	INDEX("INDEX"),
+	LENGTH("LENGTH"),
+	LOCATE("LOCATE"),
+	LOWER("TOLOWER"),
+	MAX("MAX"),
+	MIN("MIN"),
+	MINUS("-"),
+	SIZE("SIZE"),
+	SOME("SOME"),
+	SQRT("SQRT"),
+	SUM("SUM"),
+	TYPE("TYPE"),
+	UPPER("TOUPPER");
+	
+	private final String _symbol;
+	
+	UnaryFunctionalOperator(String symbol) {
+		_symbol = symbol;
+	}
+	
+	public String toString() {
+		return _symbol;
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryMinusExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryMinusExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryMinusExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryMinusExpression.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 (-e) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class UnaryMinusExpression extends UnaryOperatorExpression {
+
+	public UnaryMinusExpression(Expression expr) {
+		super(expr, UnaryFunctionalOperator.MINUS);
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperator.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperator.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperator.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,65 @@
+/*
+ * 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 Operator that operate on a single expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public enum UnaryOperator {
+	ABS("ABS"),
+	ALL("ALL"),
+	ANY("ANY"),
+	AVG("AVG"),
+	COUNT("COUNT"),
+	DISTINCT("DISTINCT"),
+	EXISTS("EXISTS"),
+	INDEX("INDEX"),
+	ISEMPTY("IS EMPTY"),
+	ISEMPTY_NOT("IS NOT EMPTY"),
+	ISNULL("IS NULL"),
+	ISNULL_NOT("IS NOT NULL"),
+	LENGTH("LENGTH"),
+	LOCATE("LOCATE"),
+	LOWER("TOLOWER"),
+	MAX("MAX"),
+	MIN("MIN"),
+	MINUS("-"),
+	SIZE("SIZE"),
+	SOME("SOME"),
+	SQRT("SQRT"),
+	SUBSTRING("SUBSTR"),
+	SUM("SUM"),
+	TIMES("*"),
+	TRIM("TRIM"),
+	TYPE("TYPE"),
+	UPPER("TOUPPER");
+	
+	private final String _symbol;
+	
+	UnaryOperator(String symbol) {
+		_symbol = symbol;
+	}
+	
+	public String toString() {
+		return _symbol;
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperatorExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperatorExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperatorExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/UnaryOperatorExpression.java Thu Dec  4 17:37:13 2008
@@ -0,0 +1,52 @@
+/*
+ * 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.Aggregate;
+import javax.persistence.Expression;
+
+class UnaryOperatorExpression extends ExpressionImpl implements Aggregate {
+	protected final Expression _e;
+	protected final UnaryFunctionalOperator   _op;
+	
+	public UnaryOperatorExpression(Expression e, UnaryFunctionalOperator op) {
+		_e = e;
+		_op = op;
+	}
+	
+	public Expression getOperand() {
+		return _e;
+	}
+	
+	public UnaryFunctionalOperator getOperator() {
+		return _op;
+	}
+	
+	public Expression distinct() {
+		return new DistinctExpression(this);
+	}
+
+	public String asExpression(AliasContext ctx) {
+		return _op + "(" + ((Visitable)_e).asExpression(ctx) + ")";
+	}
+	
+	public String asProjection(AliasContext ctx) {
+		return _op + "(" + ((Selectable)_e).asProjection(ctx) + ")";
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ValueExpression.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ValueExpression.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ValueExpression.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/ValueExpression.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 VALUE(e) Expression.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class ValueExpression extends OperatorPath {
+	public ValueExpression(AbstractDomainObject expr) {
+		super(expr, PathOperator.VALUE);
+	}
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Visitable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Visitable.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Visitable.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/Visitable.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;
+
+/**
+ * An element of query that is convertible to a JPQL String given a aliasing 
+ * scheme. QueryDefinition visits each of its element and translates them.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public interface Visitable {
+	/**
+	 * Get a JPQL fragment as used in a WHERE clause.
+	 */
+	String asExpression(AliasContext ctx);
+}

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/WhenClause.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/WhenClause.java?rev=723553&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/WhenClause.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/query/WhenClause.java Thu Dec  4 17:37:13 2008
@@ -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.openjpa.persistence.query;
+
+/**
+ * Denotes WHEN ... THEN ... clause of a Case Statement.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class WhenClause {
+	private final Object when;
+	private Object then;
+	
+	WhenClause(Object op) {
+		when = op;
+	}
+	
+	Object getThen() {
+		return then;
+	}
+	
+	void setThen(Object then) {
+		if (hasThen())
+			throw new IllegalStateException("then() is already set");
+		this.then = then;
+	}
+	
+	boolean hasThen() {
+		return then != null;
+	}
+	
+	public String toJPQL(AliasContext ctx) {
+		StringBuffer tmp = new StringBuffer();
+		tmp.append(" WHEN ").append(JPQLHelper.toJPQL(ctx, when))
+		   .append(" THEN ").append(JPQLHelper.toJPQL(ctx, then));
+		return tmp.toString();
+	}
+}



Mime
View raw message