cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r921521 - in /cayenne/sandbox/cayenne-gwt/src: main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/ test/java/org/apache/cayenne/gwt/test/client/
Date Wed, 10 Mar 2010 19:21:02 GMT
Author: andrey
Date: Wed Mar 10 19:21:01 2010
New Revision: 921521

URL: http://svn.apache.org/viewvc?rev=921521&view=rev
Log:
EJBQL support

Added:
    cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQuery.java
    cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQueryMetadata.java
Modified:
    cayenne/sandbox/cayenne-gwt/src/test/java/org/apache/cayenne/gwt/test/client/GwtTestQuery.java

Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQuery.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQuery.java?rev=921521&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQuery.java
(added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQuery.java
Wed Mar 10 19:21:01 2010
@@ -0,0 +1,204 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * An EJBQL query representation in Cayenne.
+ * 
+ * @since 3.0
+ */
+public class EJBQLQuery implements Query {
+
+    protected String name;
+    protected String ejbqlStatement;
+    protected Map<String, Object> namedParameters;
+    protected Map<Integer, Object> positionalParameters;
+
+    EJBQLQueryMetadata metadata = new EJBQLQueryMetadata();
+
+    public EJBQLQuery(String ejbqlStatement) {
+        this.ejbqlStatement = ejbqlStatement;
+    }
+
+    public EJBQLQuery() {
+    }
+
+    public void initWithProperties(Map<String, ?> properties) {
+
+        // must init defaults even if properties are empty
+        if (properties == null) {
+            properties = Collections.EMPTY_MAP;
+        }
+        metadata.initWithProperties(properties);
+    }
+
+    public boolean isFetchingDataRows() {
+        return metadata.isFetchingDataRows();
+    }
+
+    public void setFetchingDataRows(boolean flag) {
+        metadata.setFetchingDataRows(flag);
+    }
+
+    public String[] getCacheGroups() {
+        return metadata.getCacheGroups();
+    }
+
+    public QueryCacheStrategy getCacheStrategy() {
+        return metadata.getCacheStrategy();
+    }
+
+    public void setCacheGroups(String... cacheGroups) {
+        this.metadata.setCacheGroups(cacheGroups);
+    }
+
+    public void setCacheStrategy(QueryCacheStrategy strategy) {
+        metadata.setCacheStrategy(strategy);
+    }
+
+    /**
+     * Returns an unparsed EJB QL statement used to initialize this query.
+     */
+    public String getEjbqlStatement() {
+        return ejbqlStatement;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Returns unmodifiable map of combined named and positional parameters. Positional
+     * parameter keys are Integers, while named parameter keys are strings.
+     */
+
+    public Map<String, Object> getNamedParameters() {
+        return namedParameters != null
+                ? Collections.unmodifiableMap(namedParameters)
+                : Collections.EMPTY_MAP;
+    }
+
+    public Map<Integer, Object> getPositionalParameters() {
+        return positionalParameters != null ? Collections
+                .unmodifiableMap(positionalParameters) : Collections.EMPTY_MAP;
+    }
+
+    /**
+     * Sets a named query parameter value.
+     */
+    public void setParameter(String name, Object object) {
+
+        // do a minimal sanity check
+        if (name == null || name.length() < 1) {
+            throw new IllegalArgumentException("Null or empty parameter name");
+        }
+
+        // TODO: andrus, 6/12/2007 - validate against available query parameters - JPA
+        // spec requires it.
+
+        if (namedParameters == null) {
+            namedParameters = new HashMap<String, Object>();
+        }
+
+        namedParameters.put(name, object);
+    }
+
+    /**
+     * Sets a positional query parameter value. Note that parameter indexes are starting
+     * from 1.
+     */
+    public void setParameter(int position, Object object) {
+
+        if (position < 1) {
+            throw new IllegalArgumentException("Parameter position must be >= 1: "
+                    + position);
+        }
+
+        // TODO: andrus, 6/12/2007 - validate against available query parameters - JPA
+        // spec requires it.
+
+        if (positionalParameters == null) {
+            positionalParameters = new HashMap<Integer, Object>();
+        }
+
+        positionalParameters.put(Integer.valueOf(position), object);
+    }
+
+    /**
+     * Returns the fetchLimit property indicating the maximum number of rows this query
+     * would return.
+     */
+    public int getFetchLimit() {
+        return metadata.getFetchLimit();
+    }
+
+    /**
+     * Sets the fetchLimit property indicating the maximum number of rows this query would
+     * return.
+     */
+    public void setFetchLimit(int fetchLimit) {
+        metadata.setFetchLimit(fetchLimit);
+    }
+
+    public int getFetchOffset() {
+        return metadata.getFetchOffset();
+    }
+
+    public void setFetchOffset(int fetchOffset) {
+        metadata.setFetchOffset(fetchOffset);
+    }
+
+    public void setEjbqlStatement(String text) {
+        this.ejbqlStatement = text;
+    }
+
+    public int getPageSize() {
+        return metadata.getPageSize();
+    }
+
+    public void setPageSize(int pageSize) {
+        metadata.setPageSize(pageSize);
+    }
+    
+    /**
+     * Sets statement's fetch size (0 for no default size)
+     * @since 3.0 
+     */
+    public void setStatementFetchSize(int size) {
+        metadata.setStatementFetchSize(size);
+    }
+    
+    /**
+     * @return statement's fetch size
+     * @since 3.0
+     */
+    public int getStatementFetchSize() {
+        return metadata.getStatementFetchSize();
+    }
+    
+    
+}

Added: cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQueryMetadata.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQueryMetadata.java?rev=921521&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQueryMetadata.java
(added)
+++ cayenne/sandbox/cayenne-gwt/src/main/resources/org/apache/cayenne/query/emul/org/apache/cayenne/query/EJBQLQueryMetadata.java
Wed Mar 10 19:21:01 2010
@@ -0,0 +1,28 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.query;
+
+
+/**
+ * A metadata object for the {@link EJBQLQuery}.
+ * 
+ * @since 3.0
+ */
+class EJBQLQueryMetadata extends BaseQueryMetadata {
+}

Modified: cayenne/sandbox/cayenne-gwt/src/test/java/org/apache/cayenne/gwt/test/client/GwtTestQuery.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-gwt/src/test/java/org/apache/cayenne/gwt/test/client/GwtTestQuery.java?rev=921521&r1=921520&r2=921521&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-gwt/src/test/java/org/apache/cayenne/gwt/test/client/GwtTestQuery.java
(original)
+++ cayenne/sandbox/cayenne-gwt/src/test/java/org/apache/cayenne/gwt/test/client/GwtTestQuery.java
Wed Mar 10 19:21:01 2010
@@ -26,6 +26,7 @@ import org.apache.cayenne.QueryResponse;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.gwt.client.GWTDataContext;
 import org.apache.cayenne.gwt.test.client.model.Tree;
+import org.apache.cayenne.query.EJBQLQuery;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
@@ -105,4 +106,18 @@ public class GwtTestQuery extends Cayenn
 		
 		delayTestFinish(500);
 	}
+	
+	public void testEJBQL() {
+		EJBQLQuery query = new EJBQLQuery("select t from Tree t order by t.name desc");
+		
+		testQuery(query, new TestCallback<List<Tree>>() {
+			@Override
+			public void onSuccess(List<Tree> result) {
+				assertEquals(result.size(), 2);
+				Tree pine = result.get(0);
+				assertEquals(pine.getName(), "Pine");
+				assertEquals(result.get(1).getName(), "Fir");
+			}
+		});
+	}
 }



Mime
View raw message