db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r522122 - in /db/ojb/trunk/src/java/org/apache/ojb/broker: accesslayer/RsQueryObject.java core/PersistenceBrokerImpl.java query/QueryFactory.java query/QueryFactoryNew.java query/QueryFactoryNewImpl.java
Date Sat, 24 Mar 2007 22:26:07 GMT
Author: arminw
Date: Sat Mar 24 15:26:06 2007
New Revision: 522122

URL: http://svn.apache.org/viewvc?view=rev&rev=522122
Log:
allow to execute arbitrary sql-statements using a report query

Modified:
    db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactory.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNew.java
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNewImpl.java

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java?view=diff&rev=522122&r1=522121&r2=522122
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java Sat Mar 24
15:26:06 2007
@@ -15,12 +15,10 @@
  * limitations under the License.
  */
 
+import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.query.QueryByCriteria;
 import org.apache.ojb.broker.query.QueryBySQL;
-import org.apache.ojb.broker.metadata.ClassDescriptor;
-import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
-import org.apache.ojb.broker.accesslayer.JdbcAccess;
 
 /**
  * Helper class for {@link RsIterator} queries.
@@ -55,23 +53,27 @@
         this.cld = cld;
         if(query instanceof QueryBySQL)
         {
-            setSQLBased(true);
+            isSQLBased = true;
         }
     }
 
     //*******************************************
     // public methods
     //*******************************************
-
     /**
      * Execute the Query. Select all columns. 
      * @param jdbcAccess
-     * @return
+     * @return The wrapped query result
      */
     public ResultSetAndStatement performQuery(JdbcAccess jdbcAccess)
     {
         if (isSQLBased())
         {
+            // If class-descriptor not set we expect an arbitrary sql-statement
+            if(cld == null)
+            {
+                return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(), Query.SCROLLABLE);
+            }
             return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(), Query.SCROLLABLE);
         }
         else
@@ -84,7 +86,7 @@
      * Execute the Query. Select the pk-columns only. 
      * This is an optimization when using proxies.  
      * @param jdbcAccess
-     * @return
+     * @return The wrapped query result
      */
     public ResultSetAndStatement performPkQuery(JdbcAccess jdbcAccess)
     {
@@ -116,6 +118,14 @@
         return query;
     }
 
+    /**
+     * @return Returns the isSQLBased.
+     */
+    public boolean isSQLBased()
+    {
+        return isSQLBased;
+    }
+
     public String getSQLBasedQuery()
     {
         if(isSQLBased())
@@ -140,26 +150,9 @@
         }
     }
 
-    /**
-     * @param isSQLBased The isSQLBased to set.
-     */
-    private void setSQLBased(boolean isSQLBased)
-    {
-        this.isSQLBased = isSQLBased;
-    }
-
-    /**
-     * @return Returns the isSQLBased.
-     */
-    public boolean isSQLBased()
-    {
-        return isSQLBased;
-    }
-
     public String toString()
     {
         return this.getClass().getName() +
                 "[" + "query: " + query + ", class descriptor: " + cld.getClassNameOfObject()
+ "]";
     }
-
 }

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java?view=diff&rev=522122&r1=522121&r2=522122
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java Sat Mar 24
15:26:06 2007
@@ -2508,7 +2508,7 @@
      */
     public OJBIterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
     {
-        ClassDescriptor cld = getClassDescriptor(query.getSearchClass());
+        ClassDescriptor cld = query.getSearchClass() != null ? getClassDescriptor(query.getSearchClass())
: null;
         return getReportQueryIteratorFromQuery(query, cld);
     }
 

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactory.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactory.java?view=diff&rev=522122&r1=522121&r2=522122
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactory.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactory.java Sat Mar 24 15:26:06
2007
@@ -19,8 +19,7 @@
 
 /**
  * Factory to create Queries.
- * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
- * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi<a>
+ *
  * @version $Id$
  */
 public final class QueryFactory
@@ -165,8 +164,23 @@
     }
 
     /**
+     * Factory method for a arbitrary query by sql - it's not necessary that requested table
+     * is mapped in the metadata files.
+     * <br/>
+     * NOTE: This query object can only be used in conjunction with
+     * {@link org.apache.ojb.broker.PersistenceBroker#getReportQueryIteratorByQuery(org.apache.ojb.broker.query.Query)}.
+     *
+     * @param sql An arbitrary sql string.
+     * @return QueryBySQL The query object.
+     */
+    public static QueryBySQL newQuery(String sql)
+    {
+        return theFactory.newQuery(sql);
+    }
+
+    /**
      * Return a copy of a QueryByCriteria
-     * @param QueryByCriteria
+     * @param aQuery
      * @return QueryByCriteria
      */
     public static QueryByCriteria copyQuery(QueryByCriteria aQuery)

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNew.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNew.java?view=diff&rev=522122&r1=522121&r2=522122
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNew.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNew.java Sat Mar 24 15:26:06
2007
@@ -17,7 +17,7 @@
 
 /**
  * Interface for Query-Factories.
- * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi<a>
+ * 
  * @version $Id$
  */
 public interface QueryFactoryNew
@@ -126,6 +126,18 @@
      * @return QueryBySQL
      */
     QueryBySQL newQuery(Class classToSearchFrom, String anSqlStatement);
+
+    /**
+     * Factory method for a arbitrary query by sql - it's not necessary that requested table
+     * is mapped in the metadata files.
+     * <br/>
+     * NOTE: This query object can only be used in conjunction with
+     * {@link org.apache.ojb.broker.PersistenceBroker#getReportQueryIteratorByQuery(org.apache.ojb.broker.query.Query)}.
+     *
+     * @param sql An arbitrary sql string.
+     * @return QueryBySQL The query object.
+     */
+    public QueryBySQL newQuery(String sql);
 
     /**
      * Return a copy of a QueryByCriteria.

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNewImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNewImpl.java?view=diff&rev=522122&r1=522121&r2=522122
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNewImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryFactoryNewImpl.java Sat Mar 24
15:26:06 2007
@@ -166,6 +166,21 @@
     }
 
     /**
+     * Factory method for a arbitrary query by sql - it's not necessary that requested table
+     * is mapped in the metadata files.
+     * <br/>
+     * NOTE: This query object can only be used in conjunction with
+     * {@link org.apache.ojb.broker.PersistenceBroker#getReportQueryIteratorByQuery(org.apache.ojb.broker.query.Query)}.
+     *
+     * @param sql An arbitrary sql string.
+     * @return QueryBySQL The query object.
+     */
+    public QueryBySQL newQuery(String sql)
+    {
+        return new QueryBySQLImpl(null, sql);
+    }
+
+    /**
      * Return a copy of a QueryByCriteria.
      * @param aQuery
      * @return QueryByCriteria



---------------------------------------------------------------------
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