You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2009/05/05 20:03:33 UTC

svn commit: r771948 [2/2] - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/jpql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence...

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java?rev=771948&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java Tue May  5 18:03:31 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.criteria;
+
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Order;
+
+/**
+ * Ordering clause of a criteria query.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class OrderImpl implements Order {
+	private boolean _ascending;
+	private final Expression<?> e;
+	
+	public OrderImpl(Expression<?> e, boolean asc) {
+		this.e = e;
+		_ascending = asc;
+	}
+	
+	public OrderImpl(Expression<?> e) {
+		this(e, true);
+	}
+	
+	public <T extends Comparable<T>> Expression<T> getExpression() {
+		return (Expression<T>)e;
+	}
+
+	public boolean isAscending() {
+		return _ascending;
+	}
+
+	public void reverse() {
+		_ascending = !_ascending;
+	}
+}

Propchange: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/OrderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java?rev=771948&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java Tue May  5 18:03:31 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.criteria;
+
+import javax.persistence.Parameter;
+
+/**
+ * Parameter of a criteria query.
+ * 
+ * @author Pinaki Poddar
+ *
+ * @param <T> the type of value held by this parameter.
+ */
+public class ParameterImpl<T> extends ExpressionImpl<T> implements Parameter<T>{
+	private String name;
+	private int position;
+	
+    public ParameterImpl(Class<T> cls) {
+        super(cls);
+    }
+
+	public final String getName() {
+		return name;
+	}
+	
+	public final ParameterImpl<T> setName(String name) {
+		this.name = name;
+		return this;
+	}
+
+	public final Integer getPosition() {
+		return position;
+	}
+
+}

Propchange: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/ParameterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java?rev=771948&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java Tue May  5 18:03:31 2009
@@ -0,0 +1,114 @@
+/*
+ * 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.criteria;
+
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Path;
+import javax.persistence.metamodel.AbstractCollection;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.Bindable;
+import javax.persistence.metamodel.Map;
+
+import org.apache.openjpa.kernel.exps.ExpressionFactory;
+import org.apache.openjpa.kernel.exps.Value;
+import org.apache.openjpa.persistence.meta.Members;
+import org.apache.openjpa.persistence.meta.MetamodelImpl;
+
+/**
+ * Path from another (parent) path.
+ * 
+ * @author ppoddar
+ *
+ * @param <X>
+ */
+public class PathImpl<X> extends ExpressionImpl<X> implements Path<X> {
+    private PathImpl<?> _parent;
+    private Members.Member<?,X> member;
+    
+    /**
+     * 
+     * @param cls
+     */
+    protected PathImpl(Class<X> cls) {
+        super(cls);
+    }
+    
+    public <Z> PathImpl(Members.Member<Z, X> member) {
+        super(member.getMemberJavaType());
+        this.member = member;
+    }
+    
+    public <Z> PathImpl(PathImpl<Z> parent, 
+        Members.Member<? super Z, X> member) {
+        super(member.getMemberJavaType());
+        _parent = parent;
+        this.member = member;
+    }
+    
+    @Override
+    public Value toValue(ExpressionFactory factory, MetamodelImpl model) {
+        Value var = null;
+        if (_parent != null) { 
+            org.apache.openjpa.kernel.exps.Path path = 
+                (org.apache.openjpa.kernel.exps.Path)
+                _parent.toValue(factory, model);
+            path.get(member.fmd, false);
+            var = path;
+        } else {
+            var = factory.newPath();//getJavaType());
+            var.setMetaData(model.repos.getMetaData(getJavaType(), null, true));
+        }
+        return var;
+    }
+
+    public <Y> Path<Y> get(Attribute<? super X, Y> attr) {
+        return new PathImpl(this, (Members.Member<? super X, Y>)attr);
+    }
+
+    public Expression get(AbstractCollection collection) {
+        // TODO Auto-generated method stub
+        throw new AbstractMethodError();
+    }
+
+    public Expression get(Map collection) {
+        // TODO Auto-generated method stub
+        throw new AbstractMethodError();
+    }
+
+    public Path get(String attName) {
+        // TODO Auto-generated method stub
+        throw new AbstractMethodError();
+    }
+  //TODO: what does this return for a collection key, value? null?
+    public Bindable<X> getModel() { 
+        // TODO Auto-generated method stub
+        throw new AbstractMethodError();
+    }
+    
+    public Path<?> getParentPath() {
+        return _parent;
+    }
+
+    public Expression<Class<? extends X>> type() {
+        // TODO Auto-generated method stub
+        throw new AbstractMethodError();
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PathImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java?rev=771948&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java Tue May  5 18:03:31 2009
@@ -0,0 +1,125 @@
+/*
+ * 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.criteria;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.Predicate;
+
+import org.apache.openjpa.kernel.exps.ExpressionFactory;
+import org.apache.openjpa.persistence.meta.MetamodelImpl;
+
+public class PredicateImpl extends ExpressionImpl<Boolean> 
+    implements Predicate {
+    List<Expression<Boolean>> _exps;
+    BooleanOperator _op;
+    boolean _negated = false;
+    
+    protected PredicateImpl() {
+    	super(Boolean.class);
+    }
+                               
+    protected PredicateImpl(BooleanOperator op) {
+        this();
+        _op = op;
+    }
+    
+    protected PredicateImpl(BooleanOperator op, Predicate...restrictions) {
+		this(op);
+		for (Predicate p : restrictions)
+			add((PredicateImpl)p);
+	}
+
+    public PredicateImpl add(Expression<Boolean> s) {
+        if (_exps == null)
+            _exps = new ArrayList<Expression<Boolean>>();
+        _exps.add(s);
+        return this;
+    }
+
+    public List<Expression<Boolean>> getExpressions() {
+        return _exps;
+    }
+
+    public BooleanOperator getOperator() {
+        return _op;
+    }
+
+    public boolean isNegated() {
+        return _negated;
+    }
+
+    public PredicateImpl negate() {
+        PredicateImpl not = new PredicateImpl(_op);
+        not._negated = true;
+        not._exps = new ArrayList<Expression<Boolean>>(this._exps);
+        not._op = this._op;
+        return not;
+    }
+    
+    @Override
+    org.apache.openjpa.kernel.exps.Expression toKernelExpression(
+        ExpressionFactory factory, MetamodelImpl model) {
+    		if (_exps == null || _exps.isEmpty())
+    			return factory.emptyExpression();
+    		if (_exps.size() == 1)
+    			return ((ExpressionImpl<?>)_exps.get(0))
+    			   .toKernelExpression(factory, model);
+    		ExpressionImpl<?> e1 = (ExpressionImpl<?>)_exps.get(0);
+    		ExpressionImpl<?> e2 = (ExpressionImpl<?>)_exps.get(1);
+    		org.apache.openjpa.kernel.exps.Expression ke1 = 
+    			e1.toKernelExpression(factory, model);
+    		org.apache.openjpa.kernel.exps.Expression ke2 = 
+    			e2.toKernelExpression(factory, model);
+    		org.apache.openjpa.kernel.exps.Expression result = 
+    			_op == BooleanOperator.AND ?
+    			factory.and(ke1,ke2) : factory.or(ke1, ke2);
+
+    		for (int i = 2; i < _exps.size(); i++) {
+    			ExpressionImpl<?> e = (ExpressionImpl<?>)_exps.get(i);
+    			result = factory.and(result, 
+    				e.toKernelExpression(factory, model));
+    		}
+    		return _negated ? factory.not(result) : result;
+    }
+        
+    public static class And extends PredicateImpl {
+    	public And(Expression<Boolean> x, Expression<Boolean> y) {
+    		super(BooleanOperator.AND);
+    		add(x).add(y);
+    	}
+    	
+    	public And(Predicate...restrictions) {
+    		super(BooleanOperator.AND, restrictions);
+    	}
+   }
+    
+    public static class Or extends PredicateImpl {
+    	public Or(Expression<Boolean> x, Expression<Boolean> y) {
+    		super(BooleanOperator.OR);
+    		add(x).add(y);
+    	}
+    	
+    	public Or(Predicate...restrictions) {
+    		super(BooleanOperator.AND, restrictions);
+    	}
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/PredicateImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java?rev=771948&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java Tue May  5 18:03:31 2009
@@ -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.criteria;
+
+import javax.persistence.criteria.Root;
+import javax.persistence.metamodel.Entity;
+
+import org.apache.openjpa.persistence.criteria.FromImpl;
+
+/**
+ * A path from itself.
+ * 
+ * @author Pinaki Poddar
+ *
+ * @param <X>
+ */
+public class RootImpl<X> extends FromImpl<X,X> implements Root<X> {
+	private final Entity<X> _entity;
+	
+    public RootImpl(Entity<X> type) {
+        super(type);
+        _entity = type;
+    }
+    
+    public  Entity<X> getModel() {
+        return _entity;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/RootImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java?rev=771948&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java (added)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java Tue May  5 18:03:31 2009
@@ -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.openjpa.persistence.criteria;
+
+import javax.persistence.criteria.Selection;
+
+import org.apache.openjpa.persistence.ResultItemImpl;
+
+/**
+ * An item selected in the projection clause of  Criteria query.
+ * 
+ * @author Pinaki Poddar
+ *
+ * @param <X>
+ */
+public class SelectionImpl<X> extends ResultItemImpl<X> 
+    implements Selection<X> {
+
+    public SelectionImpl(Class<X> cls) {
+        super(cls);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/criteria/SelectionImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.kernel.exps.ExpressionParser
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.kernel.exps.ExpressionParser?rev=771948&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.kernel.exps.ExpressionParser (added)
+++ openjpa/trunk/openjpa-persistence/src/main/resources/META-INF/services/org.apache.openjpa.kernel.exps.ExpressionParser Tue May  5 18:03:31 2009
@@ -0,0 +1,17 @@
+# 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.
+org.apache.openjpa.persistence.criteria.CriteriaBuilder