empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r904271 - in /incubator/empire-db/trunk: empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/ empire-db-examples/empire-db-example-struts2/src/main/java/org/apache/empire/struts2/websample/web/actions/ empi...
Date Thu, 28 Jan 2010 21:40:25 GMT
Author: doebele
Date: Thu Jan 28 21:40:24 2010
New Revision: 904271

URL: http://svn.apache.org/viewvc?rev=904271&view=rev
Log:
EMPIREDB-72

Added:
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/   (with
props)
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/DBOrderByExpr.java
  (with props)
Modified:
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
    incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/java/org/apache/empire/struts2/websample/web/actions/EmployeeListAction.java
    incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/action/WebAction.java
    incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/actionsupport/ListActionSupport.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
    incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
Thu Jan 28 21:40:24 2010
@@ -402,7 +402,7 @@
         DBColumnExpr PHONE_EXT_NUMBER = EMP.PHONE_NUMBER.substring(PHONE_LAST_DASH).as("PHONE_EXTENSION");
         
         // DBColumnExpr genderExpr = cmd.select(EMP.GENDER.decode(EMP.GENDER.getOptions()).as(EMP.GENDER.getName()));
-		// Select requried columns
+		// Select required columns
 		cmd.select(EMP.EMPLOYEE_ID, EMPLOYEE_FULLNAME);
 		if(db.getDriver() instanceof DBDatabaseDriverPostgreSQL)
 		{
@@ -415,15 +415,9 @@
 		cmd.select(DEP.NAME.as("DEPARTMENT"));
 		cmd.select(DEP.BUSINESS_UNIT);
 		cmd.join(EMP.DEPARTMENT_ID, DEP.DEPARTMENT_ID);
-        // Set contraints and order
+        // Set constraints and order
         cmd.where(EMP.LASTNAME.length().isGreaterThan(0));
-        cmd.orderBy(EMP.LASTNAME);
-        cmd.orderBy(EMP.FIRSTNAME);
-
-        cmd.where(EMP.DEPARTMENT_ID.is("Some Strange Value"));
-        cmd.where(EMP.SALARY.is("Some Weird Value"));
-        cmd.where(EMP.EMPLOYEE_ID.is("Some Strange Value"));
-        System.out.print(cmd.getSelect());
+        cmd.orderBy(EMP.LASTNAME, EMP.FIRSTNAME);
         
 		// Query Records and print output
 		DBReader reader = new DBReader();

Modified: incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/java/org/apache/empire/struts2/websample/web/actions/EmployeeListAction.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/java/org/apache/empire/struts2/websample/web/actions/EmployeeListAction.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/java/org/apache/empire/struts2/websample/web/actions/EmployeeListAction.java
(original)
+++ incubator/empire-db/trunk/empire-db-examples/empire-db-example-struts2/src/main/java/org/apache/empire/struts2/websample/web/actions/EmployeeListAction.java
Thu Jan 28 21:40:24 2010
@@ -185,7 +185,7 @@
             DBCommand cmd = db.createCommand();
             cmd.select(db.T_DEPARTMENTS.C_DEPARTMENT_ID);
             cmd.select(db.T_DEPARTMENTS.C_NAME);
-            cmd.orderBy(db.T_DEPARTMENTS.C_NAME);
+            cmd.orderBy(db.T_DEPARTMENTS.C_NAME.asc());
             departments = db.queryOptionList(cmd.getSelect(), getConnection());
         }
         return departments;

Modified: incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/action/WebAction.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/action/WebAction.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/action/WebAction.java
(original)
+++ incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/action/WebAction.java
Thu Jan 28 21:40:24 2010
@@ -44,7 +44,6 @@
 import org.apache.struts2.views.util.UrlHelper;
 
 import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.LocaleProvider;
 import com.opensymphony.xwork2.TextProvider;
 import com.opensymphony.xwork2.util.ValueStack;
 
@@ -54,8 +53,7 @@
  * It implements necessary interfaces for parameter-, translation- and error-handling.<BR>
  */
 public abstract class WebAction extends ActionBase
-    implements Disposable, ExceptionAware, ActionAccessValidator, ActionItemProperty,
-               RequestParamProvider, ActionErrorProvider, TextProvider, LocaleProvider
+    implements Disposable, ExceptionAware, ActionAccessValidator, ActionErrorProvider, TextProvider
     // implements Action, Validateable, ValidationAware, ValidationAware, TextProvider, LocaleProvider,
Serializable
 {   
     // Logger

Modified: incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/actionsupport/ListActionSupport.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/actionsupport/ListActionSupport.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/actionsupport/ListActionSupport.java
(original)
+++ incubator/empire-db/trunk/empire-db-struts2/src/main/java/org/apache/empire/struts2/actionsupport/ListActionSupport.java
Thu Jan 28 21:40:24 2010
@@ -155,7 +155,6 @@
     public void setSortColumn(String column)
     {
         // sort column
-        @SuppressWarnings("hiding")
         ListSortInfo lsi = getListSortInfo();
         if (column!=null && column.equalsIgnoreCase(lsi.sortColumn))
         {

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBColumnExpr.java
Thu Jan 28 21:40:24 2010
@@ -41,6 +41,7 @@
 import org.apache.empire.db.expr.column.DBValueExpr;
 import org.apache.empire.db.expr.compare.DBCompareColExpr;
 import org.apache.empire.db.expr.compare.DBCompareExpr;
+import org.apache.empire.db.expr.order.DBOrderByExpr;
 import org.w3c.dom.Element;
 
 
@@ -1137,6 +1138,25 @@
         return convertTo(dataType, null);
     }
 
+    /**
+     * creates a new DBOrderByExpr for ascending order 
+     * <P>
+     * @return the new DBOrderByExpr object for ascending order
+     */
+    public DBOrderByExpr asc()
+    {
+        return new DBOrderByExpr(this, false);
+    }
+
+    /**
+     * creates a new DBOrderByExpr for descending order 
+     * <P>
+     * @return the new DBOrderByExpr object for descending order
+     */
+    public DBOrderByExpr desc()
+    {
+        return new DBOrderByExpr(this, true);
+    }
 
     // get object Array from List
     private Object listToArray(Object value)

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCombinedCmd.java
Thu Jan 28 21:40:24 2010
@@ -18,8 +18,11 @@
  */
 package org.apache.empire.db;
 
+import java.util.ArrayList;
 import java.util.Set;
 
+import org.apache.empire.db.expr.order.DBOrderByExpr;
+
 /**
  * This class is used for building up a partition of a SQL-Command.
  * It handles the insert from a specified key word between two DBCommandExpr objects.
@@ -29,17 +32,17 @@
  */
 public class DBCombinedCmd extends DBCommandExpr
 {
-   // Memebers
-   private DBCommandExpr left;
-   private DBCommandExpr right;
-   private String        keyWord;
+   // Members
+   protected DBCommandExpr left;
+   protected DBCommandExpr right;
+   protected String        keyWord;
 
   /**
    * Constructs a new DBFuncExpr object and
    * sets the specified parameters to this object.
    * 
    * @param left the first DBCommandExpr object
-   * @param keyWord the key word between the wo DBCommandExpr objects
+   * @param keyWord the key word between the two DBCommandExpr objects
    * @param right the second DBCommandExpr object
    */
    public DBCombinedCmd(DBCommandExpr left, String keyWord, DBCommandExpr right)
@@ -122,9 +125,16 @@
    }
 
    @Override
-   public void orderBy(DBColumnExpr expr, boolean desc)
+   public void orderBy(DBOrderByExpr... exprs)
    {
-      super.orderBy(getCmdColumn(expr), desc);
+      if (orderBy == null)
+          orderBy = new ArrayList<DBOrderByExpr>();
+      // Add order by expression
+      for (DBOrderByExpr obe : exprs)
+      {
+          DBColumnExpr c = getCmdColumn(obe.expr);
+          orderBy.add(new DBOrderByExpr(c, obe.desc));
+      }
    }
 
 

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
Thu Jan 28 21:40:24 2010
@@ -542,22 +542,6 @@
     }
 
     /**
-     * Adds a column to the group by phrase of an sql statement.
-     * 
-     * @param expr the DBCompareExpr object
-     */
-    // groupBy
-    public void groupBy(DBColumnExpr expr)
-    {
-        if (expr.isAggregate())
-            return;
-        if (groupBy == null)
-            groupBy = new ArrayList<DBColumnExpr>();
-        // group by
-        groupBy.add(expr);
-    }
-
-    /**
      * Adds a list of columns to the group by phrase of an sql statement.
      * 
      * @param exprs vararg of columns by which to group the rows

Modified: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java?rev=904271&r1=904270&r2=904271&view=diff
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
(original)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBCommandExpr.java
Thu Jan 28 21:40:24 2010
@@ -27,6 +27,7 @@
 import org.apache.empire.commons.Errors;
 import org.apache.empire.commons.Options;
 import org.apache.empire.data.DataType;
+import org.apache.empire.db.expr.order.DBOrderByExpr;
 import org.w3c.dom.Element;
 
 
@@ -286,64 +287,9 @@
 
     }
 
-    protected static class DBOrderByInfo extends DBExpr
-    {
-        public DBColumnExpr expr;
-        public boolean desc;
-
-        /**
-         * Construct a new DBOrderByInfo object set the specified
-         * parameters to this object.
-         * 
-         * @param expr the column 
-         * @param desc set true for descending or false for ascending
-         */
-        public DBOrderByInfo(DBColumnExpr expr, boolean desc)
-        {
-            this.expr = expr;
-            this.desc = desc;
-        }
-
-        /** 
-         * Returns the current database object 
-         */
-        @Override
-        public DBDatabase getDatabase()
-        {
-            return expr.getDatabase();
-        }
-
-        /*
-         * @see org.apache.empire.db.DBExpr#addReferencedColumns(Set)
-         */
-        @Override
-        public void addReferencedColumns(Set<DBColumn> list)
-        {
-            expr.addReferencedColumns(list);
-        }
-
-        /**
-         * Creates the SQL-Command set "DESC" command after the order by statement.
-         * 
-         * @param buf the SQL-Command
-         * @param context the current SQL-Command context
-         */
-        @Override
-        public void addSQL(StringBuilder buf, long context)
-        { 
-            // Set SQL-Order By
-            expr.addSQL(buf, context);
-            // only need to add DESC as default is ASC
-            if (desc)
-            {
-                buf.append(" DESC");
-            }
-        }
-    }
-
     // Members
     protected DBCmdQuery          cmdQuery = null;
-    protected List<DBOrderByInfo> orderBy  = null;
+    protected List<DBOrderByExpr> orderBy  = null;
 
     /** Constructs an empty DBCommandExpr object */
     public DBCommandExpr()
@@ -365,7 +311,7 @@
         { // Check Owner
             DBCmdColumn c = (DBCmdColumn) col;
             if (c.getRowSet() == cmdQuery)
-                return col; // it's aready a command column
+                return col; // it's already a command column
             // extract the expression
             col = c.expr;
         }
@@ -448,7 +394,7 @@
      * Constructs a new DBCombinedCmd object with this object,
      * the key word= "INTERSECT" and the selected DBCommandExpr.
      * 
-     * @param other the secend DBCommandExpr
+     * @param other the second DBCommandExpr
      * @return the new DBCombinedCmd object
      */
     public DBCommandExpr intersect(DBCommandExpr other)
@@ -465,29 +411,45 @@
     }
 
     /**
-     * Adds an order by with ascending or descending order
+     * Adds an order by expression the command
      * 
-     * @param expr the DBColumnExpr object
-     * @param desc if true, the results from select statement will sort top down
+     * @param exprs vararg of orderBy expressions
+     * 
+     * @see org.apache.empire.db.DBCommandExpr#orderBy(DBColumnExpr, boolean)
      */
-    public void orderBy(DBColumnExpr expr, boolean desc)
+    public void orderBy(DBOrderByExpr... exprs)
     {
         if (orderBy == null)
-            orderBy = new ArrayList<DBOrderByInfo>();
-        // Add order by excpression
-        orderBy.add(new DBOrderByInfo(expr, desc));
+            orderBy = new ArrayList<DBOrderByExpr>();
+        // Add order by expression
+        for (DBOrderByExpr expr : exprs)
+        {
+            orderBy.add(expr);
+        }
     }
 
     /**
-     * Adds an order by with ascending order
+     * Adds a list of columns to the orderBy clause in ascending order
      * 
-     * @param expr the column 
+     * @param exprs vararg of column expressions
+     */
+    public final void orderBy(DBColumnExpr... exprs)
+    {
+        for (DBColumnExpr expr : exprs)
+        {
+            orderBy(new DBOrderByExpr(expr, false));
+        }
+    }
+
+    /**
+     * Adds an order by with ascending or descending order
      * 
-     * @see org.apache.empire.db.DBCommandExpr#orderBy(DBColumnExpr, boolean)
+     * @param expr the DBColumnExpr object
+     * @param desc if true, the results from select statement will sort top down
      */
-    public void orderBy(DBColumnExpr expr)
+    public final void orderBy(DBColumnExpr expr, boolean desc)
     {
-        orderBy(expr, false);
+        orderBy(new DBOrderByExpr(expr, desc));
     }
 
     /**

Propchange: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/
------------------------------------------------------------------------------
    eol-style = native

Added: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/DBOrderByExpr.java
URL: http://svn.apache.org/viewvc/incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/DBOrderByExpr.java?rev=904271&view=auto
==============================================================================
--- incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/DBOrderByExpr.java
(added)
+++ incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/DBOrderByExpr.java
Thu Jan 28 21:40:24 2010
@@ -0,0 +1,81 @@
+/*
+ * 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.empire.db.expr.order;
+
+import java.util.Set;
+
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBColumnExpr;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBExpr;
+
+public class DBOrderByExpr extends DBExpr
+{
+    public DBColumnExpr expr;
+    public boolean desc;
+
+    /**
+     * Construct a new DBOrderByInfo object set the specified
+     * parameters to this object.
+     * 
+     * @param expr the column 
+     * @param desc set true for descending or false for ascending
+     */
+    public DBOrderByExpr(DBColumnExpr expr, boolean desc)
+    {
+        this.expr = expr;
+        this.desc = desc;
+    }
+
+    /*
+     * @see org.apache.empire.db.DBExpr#getDatabase()
+     */
+    @Override
+    public DBDatabase getDatabase()
+    {
+        return expr.getDatabase();
+    }
+
+    /*
+     * @see org.apache.empire.db.DBExpr#addReferencedColumns(Set)
+     */
+    @Override
+    public void addReferencedColumns(Set<DBColumn> list)
+    {
+        expr.addReferencedColumns(list);
+    }
+
+    /**
+     * Adds a column expression to the orderBy clause followed by the desc keyword if the
order should be descending 
+     * 
+     * @param buf the SQL-Command
+     * @param context the current SQL-Command context
+     */
+    @Override
+    public void addSQL(StringBuilder buf, long context)
+    {   // Set SQL-Order By
+        expr.addSQL(buf, context);
+        // only need to add DESC as default is ASC
+        if (desc)
+        {
+            buf.append(" DESC");
+        }
+    }
+
+}

Propchange: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/DBOrderByExpr.java
------------------------------------------------------------------------------
    eol-style = native

Propchange: incubator/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/expr/order/DBOrderByExpr.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message