You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2005/05/05 22:38:26 UTC

svn commit: r168400 - in /incubator/jdo/trunk/ri11: src/java/org/apache/jdo/impl/fostore/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/jdoql/ test/java/org/apache/jdo/test/query/

Author: mbo
Date: Thu May  5 13:38:26 2005
New Revision: 168400

URL: http://svn.apache.org/viewcvs?rev=168400&view=rev
Log:
JDO-36 Implement JDOQLQueryFactory proposal. Code provided by Michael Watzek

Added:
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePM.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/jdoql/JDOQLQueryFactory.java
Modified:
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/Bundle.properties
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePMF.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerFactoryImpl.java
    incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerImpl.java
    incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java
    incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/PositiveTest.java

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/Bundle.properties?rev=168400&r1=168399&r2=168400&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/Bundle.properties (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/Bundle.properties Thu May  5 13:38:26 2005
@@ -221,6 +221,7 @@
 ERR_OIDNotProv=given OID is not provisional: {0}.
 #NOI18N
 ERR_DuplicateProvOID=duplicate provisional OID: {0}.
+EXC_CannotCreateJDOQLQueryFactory=Cannot create JDOQLQueryFactory of class ''{0}''.
 
 #
 # FOStoreSchemaUID

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePM.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePM.java?rev=168400&view=auto
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePM.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePM.java Thu May  5 13:38:26 2005
@@ -0,0 +1,160 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.fostore;
+
+import java.util.Collection;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOUserException;
+import javax.jdo.Query;
+
+import org.apache.jdo.jdoql.JDOQLQueryFactory;
+
+import org.apache.jdo.impl.pm.PersistenceManagerImpl;
+
+/**
+ * Subclass of {@link #PersistenceManagerImpl} implementing
+ * abstract methods <code>newQuery</code>.
+ *
+ * @author Michael Watzek
+ */
+public class FOStorePM extends PersistenceManagerImpl 
+{
+    /** The JDOQLQueryFactory. */
+    private JDOQLQueryFactory jdoqlQueryFactory;
+
+    /**
+     * Constructs new instance of PersistenceManagerImpl for this
+     * PersistenceManagerFactoryInternal and particular combination of 
+     * username and password.
+     * @param pmf calling PersistenceManagerFactory as
+     * PersistenceManagerFactoryInternal 
+     * @param username user name used for accessing Connector or null if none
+     * is provided.
+     * @param password user password used for accessing Connector or null if 
+     * none is provided.
+     */
+    FOStorePM(FOStorePMF pmf, String username, String password) 
+    {
+        super(pmf, username, password);
+        this.jdoqlQueryFactory = pmf.getJDOQLQueryFactory();
+    }
+    
+    /** Create a new Query with no elements.
+     * @return a new Query instance with no elements.
+     */  
+     public Query newQuery() 
+     {
+         assertIsOpen();
+         return this.jdoqlQueryFactory.newQuery(this);
+     }
+
+     /** Create a new Query using elements from another Query.  The other Query
+     * must have been created by the same JDO implementation.  It might be active
+     * in a different PersistenceManager or might have been serialized and
+     * restored.
+     * @return the new Query
+     * @param compiled another Query from the same JDO implementation
+     */  
+     public Query newQuery(Object compiled) 
+     {
+         assertIsOpen();
+         return this.jdoqlQueryFactory.newQuery(this, compiled);
+     }
+
+     /** Create a new Query using the specified language.
+      * @param language the language of the query parameter
+      * @param query the query, which is of a form determined by the language
+      * @return the new Query
+      */    
+     public Query newQuery(String language, Object query) 
+     {
+         assertIsOpen();
+         if ("javax.jdo.query.JDOQL".equals(language)) //NOI18N
+             return this.jdoqlQueryFactory.newQuery(this, query);
+         throw new JDOUserException(msg.msg(
+                 "EXC_UnsupportedQueryLanguage", language)); // NOI18N
+     }
+     
+     /** Create a new Query specifying the Class of the results.
+     * @param cls the Class of the results
+     * @return the new Query
+     */
+     public Query newQuery(Class cls) 
+     {
+         assertIsOpen();
+         return this.jdoqlQueryFactory.newQuery(this, cls);
+     }
+
+     /** Create a new Query with the candidate Extent; the class is taken
+      * from the Extent.
+      * @return the new Query
+      * @param cln the Extent of candidate instances */  
+     public Query newQuery(Extent cln) 
+     {
+           assertIsOpen();
+           return this.jdoqlQueryFactory.newQuery(this, cln);
+     }
+
+     /** Create a new Query with the Class of the results and candidate 
+      * Collection.
+     * @param cls the Class of results
+     * @param cln the Collection of candidate instances
+     * @return the new Query
+     */
+     public Query newQuery(Class cls, Collection cln) 
+     {
+         assertIsOpen();
+         return this.jdoqlQueryFactory.newQuery(this, cls, cln);
+     }
+
+     /** Create a new Query with the Class of the results and Filter.
+     * @param cls the Class of results
+     * @param filter the Filter for candidate instances
+     * @return the new Query
+     */
+     public Query newQuery(Class cls, String filter) 
+     {
+         assertIsOpen();
+         return this.jdoqlQueryFactory.newQuery(this, cls, filter);
+     }
+
+     /** Create a new Query with the Class of the results, candidate Collection,
+     * and Filter.
+     * @param cls the Class of results
+     * @param cln the Collection of candidate instances
+     * @param filter the Filter for candidate instances
+     * @return the new Query
+     */
+     public Query newQuery(Class cls, Collection cln, String filter) 
+     {
+         assertIsOpen();
+         return this.jdoqlQueryFactory.newQuery(this, cls, cln, filter);
+     }
+
+     /** Create a new Query with the candidate Extent and Filter.
+      * The class is taken from the Extent.
+      * @return the new Query
+      * @param cln the Extent of candidate instances
+      * @param filter the Filter for candidate instances */  
+     public Query newQuery(Extent cln, String filter) 
+     {
+           assertIsOpen();
+           return this.jdoqlQueryFactory.newQuery(this, cln, filter);
+     }
+
+}

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePMF.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePMF.java?rev=168400&r1=168399&r2=168400&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePMF.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/fostore/FOStorePMF.java Thu May  5 13:38:26 2005
@@ -16,40 +16,30 @@
 
 package org.apache.jdo.impl.fostore;
 
-import java.io.ByteArrayOutputStream;
-import java.io.PrintWriter;
 import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Enumeration;
 import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
 import java.util.Properties;
-import java.util.Set;
 import java.util.WeakHashMap;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-import javax.naming.NamingException;
-import javax.naming.Reference;
-import javax.naming.Referenceable;
-import javax.naming.StringRefAddr;
 
 import javax.jdo.JDOException;
 import javax.jdo.JDOFatalException;
 import javax.jdo.PersistenceManager;
 import javax.jdo.spi.PersistenceCapable;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModelFactory;
 import org.apache.jdo.impl.pm.PersistenceManagerFactoryImpl;
-import org.apache.jdo.impl.pm.PersistenceManagerImpl;
+import org.apache.jdo.jdoql.JDOQLQueryFactory;
+import org.apache.jdo.jdoql.tree.QueryTree;
 import org.apache.jdo.model.jdo.JDOClass;
-import org.apache.jdo.pm.PersistenceManagerFactoryInternal;
-import org.apache.jdo.pm.PersistenceManagerInternal;
 import org.apache.jdo.store.StoreManager;
 import org.apache.jdo.store.TranscriberFactory;
 import org.apache.jdo.util.I18NHelper;
@@ -102,6 +92,13 @@
      */
     private Properties configuredFrom = null;
     
+    /** The name of the JDOQLQueryFactory class */
+    private String jdoqlQueryFactoryClassName =  
+        "org.apache.jdo.impl.jdoql.JDOQLQueryFactoryImpl";
+
+    /** The query factory for JDOQL. */
+    private JDOQLQueryFactory jdoqlQueryFactory;
+
     /** RuntimeJavaModelFactory. */
     private static final RuntimeJavaModelFactory javaModelFactory =
         (RuntimeJavaModelFactory) AccessController.doPrivileged(
@@ -202,6 +199,45 @@
           }
       }
 
+    /** Sets the JDOQLQueryFactory class name used by getJDOQLQueryFactory.
+     * @param jdoqlQueryFactoryClassName the name of the JDOQLQueryFactory
+     * class.
+     */
+    public void setJDOQLQueryFactoryClassName(String jdoqlQueryFactoryClassName)
+    {
+        this.jdoqlQueryFactoryClassName = jdoqlQueryFactoryClassName;
+    }
+
+    /**
+     * Returns the JDOQLQueryFactory bound to this FOStorePMF.
+     * @return JDOQLQueryFactory
+     */
+    public synchronized JDOQLQueryFactory getJDOQLQueryFactory() {
+        if (this.jdoqlQueryFactory == null) {
+            try {
+                Class clazz = Class.forName(jdoqlQueryFactoryClassName);
+                this.jdoqlQueryFactory = (JDOQLQueryFactory) clazz.newInstance();
+            } catch (Exception ex) {
+                throw new JDOFatalException(
+                    msg.msg("EXC_CannotCreateJDOQLQueryFactory",  //NOI18N
+                            jdoqlQueryFactoryClassName), ex);
+            }
+        }
+        return this.jdoqlQueryFactory;
+    }
+
+    /** Returns a new QueryTree instance. This instance allows to specify a 
+     * query with an API (see {@link org.apache.jdo.jdoql.tree.QueryTree} and 
+     * {@link org.apache.jdo.jdoql.tree.ExpressionFactory}) rather than as JDOQL 
+     * strings. To run you create a query object from the QueryTree (see 
+     * {@link javax.jdo.PersistenceManager#newQuery(Object compiled)}) 
+     * and call the execute method on the Query object.
+     * @return new QueryTree instance.
+     */
+    public QueryTree newQueryTree() {
+        return getJDOQLQueryFactory().newTree();
+    }
+    
       /** Return the FOStore-specific accessors (the
        * properties that are not in the JDO specification).
        * @return the hash map of FOStore accessors
@@ -332,7 +368,7 @@
 
         PersistenceManager rc = null;
         try {
-            rc = new PersistenceManagerImpl(this, userid, password);
+            rc = new FOStorePM(this, userid, password);
             setConfigured();
         } catch (JDOException ex) {
             throw ex;

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java?rev=168400&view=auto
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/jdoql/JDOQLQueryFactoryImpl.java Thu May  5 13:38:26 2005
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.impl.jdoql;
+
+import java.util.Collection;
+
+import javax.jdo.Extent;
+import javax.jdo.Query;
+
+import org.apache.jdo.impl.jdoql.tree.Tree;
+import org.apache.jdo.jdoql.JDOQLQueryFactory;
+import org.apache.jdo.jdoql.tree.QueryTree;
+import org.apache.jdo.pm.PersistenceManagerInternal;
+
+/**
+ * Implements the @link{QueryFactory} interface 
+ * in order to implement a component which is capable 
+ * to run together with JDO runtime.
+ * 
+ * @author Michael Watzek
+ */
+public class JDOQLQueryFactoryImpl implements JDOQLQueryFactory 
+{
+
+    /** 
+     * Returns a new QueryTree instance. This instance allows to specify a 
+     * query with an API (see {@link org.apache.jdo.jdoql.tree.QueryTree} and 
+     * {@link org.apache.jdo.jdoql.tree.ExpressionFactory}) rather than as
+     * JDOQL strings. To run you create a query object from the QueryTree (see 
+     * {@link javax.jdo.PersistenceManager#newQuery(Object compiled)}) 
+     * and call the execute method on the Query object.
+     * @return new QueryTree instance.
+     */
+    public QueryTree newTree()
+    {
+        return new Tree();
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal)
+     */
+    public Query newQuery(PersistenceManagerInternal pm) 
+    {
+        return new QueryImpl(pm);
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Object)
+     */
+    public Query newQuery(PersistenceManagerInternal pm, Object compiled) 
+    {
+        return new QueryImpl(pm, compiled);
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class)
+     */
+    public Query newQuery(PersistenceManagerInternal pm, Class cls) 
+    {
+        return new QueryImpl(pm, cls);
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, javax.jdo.Extent)
+     */
+    public Query newQuery(PersistenceManagerInternal pm, Extent cln) 
+    {
+        return new QueryImpl(pm, cln);
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class, java.util.Collection)
+     */
+    public Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cln) 
+    {
+        return new QueryImpl(pm, cls, cln);
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class, java.lang.String)
+     */
+    public Query newQuery(PersistenceManagerInternal pm, Class cls, String filter) 
+    {
+        return new QueryImpl(pm, cls, filter);
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, java.lang.Class, java.util.Collection, java.lang.String)
+     */
+    public Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cln, String filter) 
+    {
+        return new QueryImpl(pm, cls, cln, filter);
+    }
+
+    /*
+     * @see org.apache.jdo.jdoql.QueryFactory#newQuery(org.apache.jdo.pm.PersistenceManagerInternal, javax.jdo.Extent, java.lang.String)
+     */
+    public Query newQuery(PersistenceManagerInternal pm, Extent cln, String filter) 
+    {
+        return new QueryImpl(pm, cln, filter);
+    }
+}

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerFactoryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerFactoryImpl.java?rev=168400&r1=168399&r2=168400&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerFactoryImpl.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerFactoryImpl.java Thu May  5 13:38:26 2005
@@ -22,21 +22,34 @@
  
 package org.apache.jdo.impl.pm;
 
-import java.util.*;
+import java.io.IOException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-
-import javax.jdo.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.jdo.JDOException;
+import javax.jdo.JDOFatalInternalException;
+import javax.jdo.JDOFatalUserException;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
 import javax.jdo.spi.JDOPermission;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.jdo.ejb.EJBImplHelper;
-import org.apache.jdo.impl.jdoql.tree.Tree;
 import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModelFactory;
-import org.apache.jdo.jdoql.tree.QueryTree;
-import org.apache.jdo.model.jdo.JDOClass;
 import org.apache.jdo.pm.Accessor;
 import org.apache.jdo.pm.PersistenceManagerFactoryInternal;
 import org.apache.jdo.util.I18NHelper;
@@ -1523,19 +1536,6 @@
         return;
     }
 
-    /** Returns a new QueryTree instance. This instance allows to specify a 
-     * query with an API (see {@link org.apache.jdo.jdoql.tree.QueryTree} and 
-     * {@link org.apache.jdo.jdoql.tree.ExpressionFactory}) rather than as JDOQL 
-     * strings. To run you create a query object from the QueryTree (see 
-     * {@link javax.jdo.PersistenceManager#newQuery(Object compiled)}) 
-     * and call the execute method on the Query object.
-     * @return new QueryTree instance.
-     */
-    public QueryTree newQueryTree()
-    {
-        return new Tree();
-    }
-    
     public synchronized boolean equals(Object o) {
         if (o == this)
             return true;

Modified: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerImpl.java?rev=168400&r1=168399&r2=168400&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerImpl.java (original)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/impl/pm/PersistenceManagerImpl.java Thu May  5 13:38:26 2005
@@ -22,20 +22,28 @@
 
 package org.apache.jdo.impl.pm;
 
-import java.util.*;
+import java.lang.reflect.Constructor;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-
-import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jdo.Extent;
+import javax.jdo.JDOFatalInternalException;
+import javax.jdo.JDOFatalUserException;
+import javax.jdo.JDOUserException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+import javax.jdo.spi.PersistenceCapable;
 import javax.transaction.Status;
 
-import javax.jdo.*;
-import javax.jdo.spi.*;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import org.apache.jdo.impl.jdoql.QueryImpl;
 import org.apache.jdo.impl.model.java.runtime.RuntimeJavaModelFactory;
 import org.apache.jdo.model.java.JavaModel;
 import org.apache.jdo.model.java.JavaType;
@@ -56,8 +64,7 @@
  * 
  * @author Marina Vatkina
  */ 
-public class PersistenceManagerImpl implements PersistenceManagerInternal {
-    private final boolean DEBUG = true;
+public abstract class PersistenceManagerImpl implements PersistenceManagerInternal {
     
     /**
      * True if this PersistenceManager is closed
@@ -206,7 +213,7 @@
     /**
      * I18N message handler
      */
-    private final static I18NHelper msg = 
+    protected final static I18NHelper msg = 
         I18NHelper.getInstance(PersistenceManagerImpl.class);
 
     /**
@@ -534,101 +541,68 @@
     //
 
     /** Create a new Query with no elements.
-    * @return a new Query instance with no elements.
-    */  
-    public Query newQuery() {
-        assertIsOpen();
-        return new QueryImpl(this);
-    }
-
-    /** Create a new Query using elements from another Query.  The other Query
-    * must have been created by the same JDO implementation.  It might be active
-    * in a different PersistenceManager or might have been serialized and
-    * restored.
-    * @return the new Query
-    * @param compiled another Query from the same JDO implementation
-    */  
-    public Query newQuery (Object compiled) {
-        assertIsOpen();
-        return new QueryImpl(this, compiled);
-    }
-
-    /** Create a new Query using the specified language.
-     * @param language the language of the query parameter
-     * @param query the query, which is of a form determined by the language
+     * @return a new Query instance with no elements.
+     */  
+     public abstract Query newQuery();
+
+     /** Create a new Query using elements from another Query.  The other Query
+     * must have been created by the same JDO implementation.  It might be active
+     * in a different PersistenceManager or might have been serialized and
+     * restored.
      * @return the new Query
-     */    
-    public Query newQuery (String language, Object query) {
-        assertIsOpen();
-        if ("javax.jdo.query.JDOQL".equals(language)) //NOI18N
-            return new QueryImpl(this, query);
-        throw new JDOUserException(msg.msg(
-                "EXC_UnsupportedQueryLanguage", language)); // NOI18N
-    }
-    
-    /** Create a new Query specifying the Class of the results.
-    * @param cls the Class of the results
-    * @return the new Query
-    */
-    public Query newQuery (Class cls) {
-        assertIsOpen();
-        return new QueryImpl(this, cls);
-    }
-
-    /** Create a new Query with the candidate Extent; the class is taken
-     * from the Extent.
-     * specified.
+     * @param compiled another Query from the same JDO implementation
+     */  
+     public abstract Query newQuery (Object compiled);
+
+     /** Create a new Query using the specified language.
+      * @param language the language of the query parameter
+      * @param query the query, which is of a form determined by the language
+      * @return the new Query
+      */    
+     public abstract Query newQuery (String language, Object query);
+     
+     /** Create a new Query specifying the Class of the results.
+     * @param cls the Class of the results
      * @return the new Query
-     * @param cln the Extent of candidate instances */  
-    public Query newQuery(Extent cln) {
-          assertIsOpen();
-          return new QueryImpl(this, cln);
-    }
-
-    /** Create a new Query with the Class of the results and candidate Collection.
-    * specified.
-    * @param cls the Class of results
-    * @param cln the Collection of candidate instances
-    * @return the new Query
-    */
-    public Query newQuery (Class cls, Collection cln) {
-        assertIsOpen();
-        return new QueryImpl(this, cls, cln);
-    }
+     */
+     public abstract Query newQuery (Class cls);
 
-    /** Create a new Query with the Class of the results and Filter.
-    * specified.
-    * @param cls the Class of results
-    * @param filter the Filter for candidate instances
-    * @return the new Query
-    */
-    public Query newQuery (Class cls, String filter) {
-        assertIsOpen();
-        return new QueryImpl(this, cls, filter);
-    }
+     /** Create a new Query with the candidate Extent; the class is taken
+      * from the Extent.
+      * @return the new Query
+      * @param cln the Extent of candidate instances */  
+     public abstract Query newQuery(Extent cln);
+
+     /** Create a new Query with the Class of the results and candidate Collection.
+     * @param cls the Class of results
+     * @param cln the Collection of candidate instances
+     * @return the new Query
+     */
+     public abstract Query newQuery (Class cls, Collection cln);
 
-    /** Create a new Query with the Class of the results, candidate Collection,
-    * and Filter.
-    * @param cls the Class of results
-    * @param cln the Collection of candidate instances
-    * @param filter the Filter for candidate instances
-    * @return the new Query
-    */
-    public Query newQuery (Class cls, Collection cln, String filter) {
-        assertIsOpen();
-        return new QueryImpl(this, cls, cln, filter);
-    }
+     /** Create a new Query with the Class of the results and Filter.
+     * @param cls the Class of results
+     * @param filter the Filter for candidate instances
+     * @return the new Query
+     */
+     public abstract Query newQuery (Class cls, String filter);
 
-    /** Create a new Query with the candidate Extent and Filter.
-     * The class is taken from the Extent.
+     /** Create a new Query with the Class of the results, candidate Collection,
+     * and Filter.
+     * @param cls the Class of results
+     * @param cln the Collection of candidate instances
+     * @param filter the Filter for candidate instances
      * @return the new Query
-     * @param cln the Extent of candidate instances
-     * @param filter the Filter for candidate instances */  
-    public Query newQuery(Extent cln, String filter) {
-          assertIsOpen();
-          return new QueryImpl(this, cln, filter);
-    }
+     */
+     public abstract Query newQuery (Class cls, Collection cln, String filter);
 
+     /** Create a new Query with the candidate Extent and Filter.
+      * The class is taken from the Extent.
+      * @return the new Query
+      * @param cln the Extent of candidate instances
+      * @param filter the Filter for candidate instances */  
+     public abstract Query newQuery(Extent cln, String filter);
+     
     /** The PersistenceManager may manage a collection of instances in the data
      * store based on the class of the instances.  This method returns an
      * Extent of instances in the data store that might be iterated or

Added: incubator/jdo/trunk/ri11/src/java/org/apache/jdo/jdoql/JDOQLQueryFactory.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/src/java/org/apache/jdo/jdoql/JDOQLQueryFactory.java?rev=168400&view=auto
==============================================================================
--- incubator/jdo/trunk/ri11/src/java/org/apache/jdo/jdoql/JDOQLQueryFactory.java (added)
+++ incubator/jdo/trunk/ri11/src/java/org/apache/jdo/jdoql/JDOQLQueryFactory.java Thu May  5 13:38:26 2005
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.jdo.jdoql;
+
+import java.util.Collection;
+
+import javax.jdo.Extent;
+import javax.jdo.Query;
+
+import org.apache.jdo.pm.PersistenceManagerInternal;
+import org.apache.jdo.jdoql.tree.QueryTree;
+
+/**
+ * This interface allows for choosing between different
+ * JDO query implementations. 
+ * Query implementations implementing this interface
+ * are capable to run together with other components.
+ * The interface declares methods creating JDO query instances
+ * and JDO query tree instances.
+ * All methods creating query instances take persistence manager
+ * instances as parameters.
+ * 
+ * @author Michael Watzek
+ */
+public interface JDOQLQueryFactory 
+{
+    /** 
+     * Returns a new QueryTree instance. This instance allows to specify a 
+     * query with an API (see {@link org.apache.jdo.jdoql.tree.QueryTree} and 
+     * {@link org.apache.jdo.jdoql.tree.ExpressionFactory}) rather than as
+     * JDOQL strings. To run you create a query object from the QueryTree (see 
+     * {@link javax.jdo.PersistenceManager#newQuery(Object compiled)}) 
+     * and call the execute method on the Query object.
+     * @return new QueryTree instance.
+     */
+    QueryTree newTree();
+    
+    /** 
+     * Creates a new <code>Query</code> with no elements.
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence
+     * manager is valid. 
+     * @return the new <code>Query</code>.
+     */
+    Query newQuery(PersistenceManagerInternal pm);
+    
+    /** 
+     * Creates a new <code>Query</code> using elements from another 
+     * <code>Query</code>. The other <code>Query</code> must have been created
+     * by the same JDO implementation. It might be active in a different
+     * <code>PersistenceManager</code> or might have been serialized and
+     * restored. 
+     * <P>All of the settings of the other <code>Query</code> are copied to
+     * this <code>Query</code>, except for the candidate
+     * <code>Collection</code> or <code>Extent</code>. 
+     * @return the new <code>Query</code>.
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence
+     * manager is valid. 
+     * @param compiled another <code>Query</code> from the same JDO
+     * implementation. 
+     */
+    Query newQuery(PersistenceManagerInternal pm, Object compiled);
+    
+    /** 
+     * Creates a new <code>Query</code> specifying the <code>Class</code> of
+     * the candidate instances. 
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence
+     * manager is valid. 
+     * @param cls the <code>Class</code> of the candidate instances.
+     * @return the new <code>Query</code>.
+     */
+    Query newQuery(PersistenceManagerInternal pm, Class cls);
+    
+    /** 
+     * Creates a new <code>Query</code> with the <code>Class</code> of the
+     * candidate instances and candidate <code>Extent</code>.
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence 
+     * manager is valid.
+     * @param cln the <code>Extent</code> of candidate instances.
+     * @return the new <code>Query</code>.
+     */
+    Query newQuery(PersistenceManagerInternal pm, Extent cln);
+    
+    /** 
+     * Creates a new <code>Query</code> with the candidate <code>Class</code> 
+     * and <code>Collection</code>.
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence
+     * manager is valid. 
+     * @param cls the <code>Class</code> of results.
+     * @param cln the <code>Collection</code> of candidate instances.
+     * @return the new <code>Query</code>.
+     */
+    Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cln);
+    
+    /** 
+     * Creates a new <code>Query</code> with the <code>Class</code> of the
+     * candidate instances and filter.
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence
+     * manager is valid. 
+     * @param cls the <code>Class</code> of results.
+     * @param filter the filter for candidate instances.
+     * @return the new <code>Query</code>.
+     */
+    Query newQuery(PersistenceManagerInternal pm, Class cls, String filter);
+    
+    /** 
+     * Creates a new <code>Query</code> with the <code>Class</code> of the
+     * candidate instances, candidate <code>Collection</code>, and filter.
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence
+     * manager is valid. 
+     * @param cls the <code>Class</code> of candidate instances.
+     * @param cln the <code>Collection</code> of candidate instances.
+     * @param filter the filter for candidate instances.
+     * @return the new <code>Query</code>.
+     */
+    Query newQuery(PersistenceManagerInternal pm, Class cls, Collection cln, 
+                   String filter);
+    
+    /** 
+     * Creates a new <code>Query</code> with the
+     * candidate <code>Extent</code> and filter; the class
+     * is taken from the <code>Extent</code>.
+     * @param pm the persistence manager for the new query. 
+     * It is the responsibility of the caller to check that the persistence
+     * manager is valid. 
+     * @param cln the <code>Extent</code> of candidate instances.
+     * @param filter the filter for candidate instances.
+     * @return the new <code>Query</code>.
+     */
+    Query newQuery(PersistenceManagerInternal pm, Extent cln, String filter);
+}

Modified: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java?rev=168400&r1=168399&r2=168400&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java (original)
+++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/NegativeTest.java Thu May  5 13:38:26 2005
@@ -22,18 +22,19 @@
 
 package org.apache.jdo.test.query;
 
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Vector;
-import java.util.Iterator;
 import java.io.PrintStream;
-import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Iterator;
+import java.util.Vector;
 
-import javax.jdo.*;
+import javax.jdo.JDOException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Transaction;
 
+import org.apache.jdo.impl.fostore.FOStorePMF;
 import org.apache.jdo.impl.jdoql.tree.Tree;
-import org.apache.jdo.impl.pm.PersistenceManagerFactoryImpl;
 import org.apache.jdo.jdoql.tree.QueryTree;
 import org.apache.jdo.util.I18NHelper;
 
@@ -72,8 +73,8 @@
      */
     protected QueryTree newQueryTree()
     {
-        if (pmf instanceof PersistenceManagerFactoryImpl)
-            return ((PersistenceManagerFactoryImpl)pmf).newQueryTree();
+        if (pmf instanceof FOStorePMF)
+            return ((FOStorePMF)pmf).newQueryTree();
         else
             return new Tree();
     }

Modified: incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/PositiveTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/PositiveTest.java?rev=168400&r1=168399&r2=168400&view=diff
==============================================================================
--- incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/PositiveTest.java (original)
+++ incubator/jdo/trunk/ri11/test/java/org/apache/jdo/test/query/PositiveTest.java Thu May  5 13:38:26 2005
@@ -22,16 +22,25 @@
 
 package org.apache.jdo.test.query;
 
-import java.util.*;
 import java.io.PrintStream;
-import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import javax.jdo.Extent;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
 
-import javax.jdo.*;
-
+import org.apache.jdo.impl.fostore.FOStorePMF;
 import org.apache.jdo.impl.jdoql.tree.Tree;
-import org.apache.jdo.impl.pm.PersistenceManagerFactoryImpl;
 import org.apache.jdo.jdoql.tree.QueryTree;
+
 import org.apache.jdo.pc.xempdept.Company;
 import org.apache.jdo.pc.xempdept.Department;
 import org.apache.jdo.pc.xempdept.Employee;
@@ -326,8 +335,8 @@
      */
     protected QueryTree newQueryTree()
     {
-        if (pmf instanceof PersistenceManagerFactoryImpl)
-            return ((PersistenceManagerFactoryImpl)pmf).newQueryTree();
+        if (pmf instanceof FOStorePMF)
+            return ((FOStorePMF)pmf).newQueryTree();
         else
             return new Tree();
     }



Re: svn commit: r168400 - in /incubator/jdo/trunk/ri11: src/java/org/apache/jdo/impl/fostore/ src/java/org/apache/jdo/impl/jdoql/ src/java/org/apache/jdo/impl/pm/ src/java/org/apache/jdo/jdoql/ test/java/org/apache/jdo/test/query/

Posted by Craig Russell <Cr...@Sun.COM>.
Michael,

Aren't  you supposed to be out drinking now???

Craig

On May 5, 2005, at 1:38 PM, mbo@apache.org wrote:

> Author: mbo
> Date: Thu May  5 13:38:26 2005
> New Revision: 168400
>
> URL: http://svn.apache.org/viewcvs?rev=168400&view=rev
> Log:
> JDO-36 Implement JDOQLQueryFactory proposal. Code provided by Michael 
> Watzek
>
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!