I kept everything intact here, just added the WhereClause to encapsulate
along side the hashtable for now so as not to break anything.

I guess this isn't really useful until BasePeer uses it for doing the actual
queries, but that could easily be changed.

Some changes that I made to crossdb are the tables as part of the
WhereCondition for both comparators, so, although I haven't tried it, could
probalby do the self joins that Jeff was talking about.  ie: do not need to
specify the tables explicitly.

Travis
Index: SqlEnum.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/util/SqlEnum.java,v
retrieving revision 1.4
diff -u -r1.4 SqlEnum.java
--- SqlEnum.java        20 Jan 2002 21:37:56 -0000      1.4
+++ SqlEnum.java        3 May 2002 01:26:46 -0000
@@ -1,5 +1,7 @@
-package org.apache.torque.util;
-
+package org.apache.torque.util;
+
+import com.spaceprogram.sql.WhereCondition;
+
 /* ====================================================================
  * The Apache Software License, Version 1.1
  *
@@ -115,5 +117,47 @@
     public static final SqlEnum ISNULL =
         new SqlEnum(" IS NULL ");
     public static final SqlEnum ISNOTNULL =
-        new SqlEnum(" IS NOT NULL ");
+        new SqlEnum(" IS NOT NULL ");
+
+       public int getCrossdbComparison(){
+               /*
+               in WhereCondition
+
+                       public static final int LESS_THAN = 20;
+       public static final int LESS_THAN_OR_EQUAL_TO = 50;
+       public static final int EQUAL_TO = 100; // ex: WHERE a = b or a = 'b' or 'a' = 
+'b'
+       public static final int GREATER_THAN_OR_EQUAL_TO = 150;
+       public static final int GREATER_THAN = 200;
+
+       public static final int NOT_EQUAL_TO = 4;
+       public static final int LIKE = 5; // ex: WHERE a LIKE '%x%' or 'x%' or '%x' or 
+'x%x' ???
+       public static final int IN = 6; // list ex: WHERE a IN (x, y, z)
+       public static final int BETWEEN = 7;
+
+               public static final int NOT_NULL = 11;
+               public static final int IS_NULL = 12;
+                       */
+               //String es = e.toString();
+               SqlEnum e = this;
+               if(e == EQUAL){
+                       return WhereCondition.EQUAL_TO;
+               }
+               else if(e == NOT_EQUAL){
+                       return WhereCondition.NOT_EQUAL_TO;
+               }
+               else if(e == GREATER_THAN){
+                       return WhereCondition.GREATER_THAN;
+               }
+               else if(e == LESS_THAN){
+                       return WhereCondition.LESS_THAN;
+               }
+               else if(e == LESS_EQUAL){
+                       return WhereCondition.LESS_THAN_OR_EQUAL_TO;
+               }
+               else if(e == GREATER_EQUAL){
+                       return WhereCondition.GREATER_THAN_OR_EQUAL_TO;
+               }
+               return WhereCondition.EQUAL_TO; // default
+
+       }
 }
Index: BasePeer.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java,v
retrieving revision 1.37
diff -u -r1.37 BasePeer.java
--- BasePeer.java       30 Apr 2002 10:37:07 -0000      1.37
+++ BasePeer.java       3 May 2002 01:30:30 -0000
@@ -1035,7 +1035,13 @@
         {
            throw new TorqueException("No changes to save");
         }
-    }
+    }
+
+
+       public static String createCrossdbQueryString(Criteria crit){
+                                       return crit.wc.toString();
+                       }
+
 
     /**
      * Method to create an SQL query based on values in a Criteria.
@@ -1307,6 +1313,7 @@
         category.debug(sql);
         return sql;
     }
+
 
 
     /**
Index: Criteria.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/util/Criteria.java,v
retrieving revision 1.27
diff -u -r1.27 Criteria.java
--- Criteria.java       30 Apr 2002 10:37:07 -0000      1.27
+++ Criteria.java       3 May 2002 01:23:18 -0000
@@ -72,7 +72,9 @@
 import org.apache.torque.om.DateKey;
 import org.apache.torque.om.ObjectKey;
 import org.apache.commons.collections.StringStack;
-import org.apache.log4j.Category;
+import org.apache.log4j.Category;
+import com.crossdb.sql.WhereCondition;
+import com.crossdb.sql.WhereClause;
 
 /**
  * This is a utility class that is used for retrieving different types
@@ -91,7 +93,14 @@
  * @version $Id: Criteria.java,v 1.27 2002/04/30 10:37:07 mpoeschl Exp $
  */
 public class Criteria extends Hashtable
-{
+{
+
+
+       /**
+        * crossdb WhereClause
+        */
+       WhereClause wc = new WhereClause();
+
 
     /** Comparison type. */
     public static final SqlEnum EQUAL = SqlEnum.EQUAL;
@@ -491,7 +500,9 @@
         sb.append(c.getTable());
         sb.append('.');
         sb.append(c.getColumn());
-        super.put(sb.toString(), c);
+        super.put(sb.toString(), c);
+
+               wc.addClause(c.wc); // new WhereCondition(c.getTable(), c.getColumn(), 
+c.getComparison().getCrossdbComparison(), c.getValue().toString()));
         return this;
     }
 
@@ -1018,8 +1029,20 @@
      * @return A modified Criteria object.
      */
     public Criteria add(String column, Object value, SqlEnum comparison)
-    {
-        super.put(column, new Criterion(column, value, comparison));
+    {
+               Criterion c = new Criterion(column, value, comparison);
+        super.put(column, c);
+               // TR MODIFIED//////////////////
+                                          // can replace the conparison here pretty 
+easily by changing SqlEnum
+          //or making new similar class
+                                          // using EQUAL_TO for test.
+                                          // also this would be better off being set 
+in the appropriate function
+          //so you can pass in the
+                                          // primitive value
+                                          wc.addClause(c.wc);
+
+                                          // END MODIFY/////////////////
+
         return this;
     }
 
@@ -1079,8 +1102,10 @@
         StringBuffer sb = new StringBuffer(table.length() + column.length() + 1);
         sb.append(table);
         sb.append('.');
-        sb.append(column);
-        super.put(sb.toString(),new Criterion(table, column, value, comparison));
+        sb.append(column);
+               Criterion c = new Criterion(table, column, value, comparison);
+        super.put(sb.toString(),c);
+               wc.addClause(c.wc);
         return this;
     }
 
@@ -1957,7 +1982,8 @@
 
         if (oc == null)
         {
-            super.put(column, nc);
+            super.put(column, nc);
+                       wc.addCondition(new WhereCondition(column, 
+comparison.getCrossdbComparison(), value.toString()));
         }
         else
         {
@@ -2027,7 +2053,8 @@
 
         if (oc == null)
         {
-            super.put(sb.toString(),nc);
+            super.put(sb.toString(),nc);
+                               wc.addCondition(new WhereCondition(table, column, 
+comparison.getCrossdbComparison(), value.toString()));
         }
         else
         {
@@ -2533,7 +2560,8 @@
 
         if (oc == null)
         {
-            super.put(column, nc);
+            super.put(column, nc);
+                       wc.addCondition("OR", new WhereCondition(column, 
+comparison.getCrossdbComparison(), value.toString()));
         }
         else
         {
@@ -2602,7 +2630,8 @@
         Criterion nc = new Criterion(table, column, value, comparison);
         if (oc == null)
         {
-            super.put(sb.toString(), nc);
+            super.put(sb.toString(), nc);
+                               wc.addCondition("OR", new WhereCondition(column, 
+comparison.getCrossdbComparison(), value.toString()));
         }
         else
         {
@@ -3042,7 +3071,8 @@
      * criteria.
      */
     public final class Criterion implements Serializable
-    {
+    {
+               WhereClause wc = new WhereClause();
         public static final String AND = " AND ";
         public static final String OR = " OR ";
 
@@ -3079,7 +3109,8 @@
         private Criterion(Object val, SqlEnum comp)
         {
             this.value = val;
-            this.comparison = comp;
+            this.comparison = comp;
+
         }
 
         /**
@@ -3094,7 +3125,9 @@
         {
             this(val, comp);
             this.table = (table == null ? "" : table);
-            this.column = (column == null ? "" : column);
+            this.column = (column == null ? "" : column);
+                               wc.addCondition(new WhereCondition(table, column, 
+comp.getCrossdbComparison(),
+                               val.toString()));
         }
 
         /**
@@ -3118,7 +3151,12 @@
             {
                 table = tableColumn.substring(0, dot);
                 column = tableColumn.substring(dot + 1);
-            }
+            }
+                       if(table.equals("")){
+                               table = null;
+                       }
+                       wc.addCondition(new WhereCondition(table, column, 
+comp.getCrossdbComparison(),
+                               val.toString()));
         }
 
         /**
@@ -3288,7 +3326,10 @@
         public Criterion and(Criterion criterion)
         {
             this.clauses.add(criterion);
-            this.conjunctions.add(AND);
+            this.conjunctions.add(AND);
+
+                       wc.addClause(criterion.wc);
+
             return this;
         }
 
@@ -3298,7 +3339,8 @@
         public Criterion or(Criterion criterion)
         {
             this.clauses.add(criterion);
-            this.conjunctions.add(OR);
+            this.conjunctions.add(OR);
+                       Criteria.this.wc.addClause("OR", criterion.wc);
             return this;
         }
 

Attachment: CrossdbCriteriaTest.java
Description: Binary data

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to