db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r368456 - in /db/ojb/trunk/src/java/org/apache/ojb: broker/query/BindableCriterion.java broker/query/InCriteria.java broker/query/SelectionCriteria.java odmg/oql/OQLQueryImpl.java
Date Thu, 12 Jan 2006 20:22:37 GMT
Author: brj
Date: Thu Jan 12 12:22:31 2006
New Revision: 368456

URL: http://svn.apache.org/viewcvs?rev=368456&view=rev
Log:
fix for oql binding problem of InCriteria

Added:
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/BindableCriterion.java
Modified:
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/InCriteria.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/SelectionCriteria.java
    db/ojb/trunk/src/java/org/apache/ojb/odmg/oql/OQLQueryImpl.java

Added: db/ojb/trunk/src/java/org/apache/ojb/broker/query/BindableCriterion.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/query/BindableCriterion.java?rev=368456&view=auto
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/query/BindableCriterion.java (added)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/query/BindableCriterion.java Thu Jan 12 12:22:31
2006
@@ -0,0 +1,39 @@
+package org.apache.ojb.broker.query;
+
+/* Copyright 2002-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.
+ */
+
+/**
+ * Interface for Criterion that can be bound by OQLQuery.
+ * 
+ * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
+ * @version $Id:  $
+ */
+public interface BindableCriterion
+{
+    /**
+     * Used by the ODMG OQLQuery.bind() operation
+     * @return Returns a boolean indicator
+     */
+    public boolean isBound();
+
+    /**
+     * Sets the value of the criteria to newValue. 
+     * Used by the ODMG OQLQuery.bind() operation
+     */
+    public void bind(Object newValue);
+
+}
+

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/query/InCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/query/InCriteria.java?rev=368456&r1=368455&r2=368456&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/query/InCriteria.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/query/InCriteria.java Thu Jan 12 12:22:31
2006
@@ -1,7 +1,7 @@
 
 package org.apache.ojb.broker.query;
 
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2002-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.
@@ -30,7 +30,7 @@
  * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
  * @version $Id$
  */
-public class InCriteria extends Criteria
+public class InCriteria extends Criteria implements BindableCriterion
 {
     private static final long serialVersionUID = -2349356771591660674L;
 
@@ -159,6 +159,37 @@
             buildInCriteria(aPb);
             m_preprocessed = true;
         }
+    }
+
+    /**
+     * @see org.apache.ojb.broker.query.BindableCriterion#bind(java.lang.Object)
+     */
+    public void bind(Object newValue)
+    {
+        if (newValue instanceof Collection)
+        {
+            m_values = (Collection) newValue;
+        }
+        else
+        {
+            if (m_values != null)
+            {
+                m_values.add(newValue);
+            }
+            else
+            {
+                m_values = new ArrayList();
+                m_values.add(newValue);
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.ojb.broker.query.BindableCriterion#isBound()
+     */
+    public boolean isBound()
+    {
+        return (m_values != null);
     }
 
     /**

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/query/SelectionCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/broker/query/SelectionCriteria.java?rev=368456&r1=368455&r2=368456&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/query/SelectionCriteria.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/query/SelectionCriteria.java Thu Jan 12 12:22:31
2006
@@ -3,7 +3,7 @@
 import java.util.List;
 import java.util.Map;
 
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2002-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.
@@ -31,7 +31,7 @@
  * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
  * @version $Id$
  */
-public abstract class SelectionCriteria extends AbstractCriterion
+public abstract class SelectionCriteria extends AbstractCriterion implements BindableCriterion
 {
 	static final long serialVersionUID = -5194901539702756536L;
 	
@@ -88,9 +88,9 @@
 	 */
 	abstract public String getClause();
 
-	/**
-	 * sets the value of the criteria to newValue. Used by the ODMG OQLQuery.bind() operation
-	 */
+    /**
+     * @see org.apache.ojb.broker.query.BindableCriterion#bind(java.lang.Object)
+     */
 	public void bind(Object newValue)
 	{
 		setValue(newValue);
@@ -121,10 +121,9 @@
 		return m_attribute + getClause() + m_value;
 	}
 
-	/**
-	 * BRJ : Used by the ODMG OQLQuery.bind() operation
-	 * @return Returns a boolean indicator
-	 */
+    /**
+     * @see org.apache.ojb.broker.query.BindableCriterion#isBound()
+     */
 	public boolean isBound()
 	{
 		return m_bound;

Modified: db/ojb/trunk/src/java/org/apache/ojb/odmg/oql/OQLQueryImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/trunk/src/java/org/apache/ojb/odmg/oql/OQLQueryImpl.java?rev=368456&r1=368455&r2=368456&view=diff
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/odmg/oql/OQLQueryImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/odmg/oql/OQLQueryImpl.java Thu Jan 12 12:22:31 2006
@@ -1,6 +1,6 @@
 package org.apache.ojb.odmg.oql;
 
-/* Copyright 2002-2004 The Apache Software Foundation
+/* Copyright 2002-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.
@@ -22,17 +22,15 @@
 import java.util.ListIterator;
 import java.util.Vector;
 
-import antlr.RecognitionException;
-import antlr.TokenStreamException;
 import org.apache.ojb.broker.ManageableCollection;
 import org.apache.ojb.broker.PersistenceBroker;
 import org.apache.ojb.broker.accesslayer.OJBIterator;
 import org.apache.ojb.broker.query.BetweenCriteria;
+import org.apache.ojb.broker.query.BindableCriterion;
 import org.apache.ojb.broker.query.Criteria;
 import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.query.QueryByCriteria;
 import org.apache.ojb.broker.query.ReportQuery;
-import org.apache.ojb.broker.query.SelectionCriteria;
 import org.apache.ojb.broker.util.logging.Logger;
 import org.apache.ojb.broker.util.logging.LoggerFactory;
 import org.apache.ojb.odmg.ImplementationImpl;
@@ -40,8 +38,13 @@
 import org.apache.ojb.odmg.RuntimeObject;
 import org.apache.ojb.odmg.TransactionImpl;
 import org.odmg.QueryInvalidException;
+import org.odmg.QueryParameterCountInvalidException;
+import org.odmg.QueryParameterTypeInvalidException;
 import org.odmg.Transaction;
 
+import antlr.RecognitionException;
+import antlr.TokenStreamException;
+
 /**
  * The OQL query interface implementation.
  *
@@ -63,7 +66,6 @@
         this.odmg = odmg;
     }
 
-
     /**
      * returns the compiled query object
      */
@@ -104,11 +106,11 @@
      * not correspond with the type of the parameter in the query.
      */
     public void bind(Object parameter)
-            throws org.odmg.QueryParameterCountInvalidException, org.odmg.QueryParameterTypeInvalidException
+            throws QueryParameterCountInvalidException, QueryParameterTypeInvalidException
     {
         try
         {
-            SelectionCriteria crit = (SelectionCriteria) getBindIterator().next();
+            BindableCriterion crit = (BindableCriterion) getBindIterator().next();
             crit.bind(parameter);
 
             // BRJ: bind is called twice for between
@@ -120,7 +122,7 @@
         catch (Exception e)
         {
             log.error("Can't bind parameter: " + parameter, e);
-            throw new org.odmg.QueryParameterCountInvalidException(e.getMessage());
+            throw new QueryParameterCountInvalidException(e.getMessage());
         }
     }
 
@@ -130,19 +132,22 @@
         while (e.hasMoreElements())
         {
             Object o = e.nextElement();
-            if (o instanceof Criteria)
+            if (o instanceof BindableCriterion)
+            {
+                BindableCriterion bc = (BindableCriterion) o;
+                if (!bc.isBound())
+                {
+                    acc.add(bc);
+                }                
+            }
+            else if (o instanceof Criteria)
             {
                 Criteria pc = (Criteria) o;
                 flatten(pc, acc);
             }
             else
             {
-                SelectionCriteria c = (SelectionCriteria) o;
-                // BRJ : only add bindable criteria
-                if (!c.isBound())
-                {
-                    acc.add(c);
-                }
+                throw new IllegalArgumentException("Dont't know how to handle: " + o);
             }
         }
         return acc;



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message