db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r522118 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker: accesslayer/RsIterator.java accesslayer/RsQueryObject.java core/PersistenceBrokerImpl.java query/QueryFactory.java
Date Sat, 24 Mar 2007 22:11:08 GMT
Author: arminw
Date: Sat Mar 24 15:11:07 2007
New Revision: 522118

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

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryFactory.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java?view=diff&rev=522118&r1=522117&r2=522118
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
Sat Mar 24 15:11:07 2007
@@ -163,14 +163,17 @@
         setBroker(broker);
         setQueryObject(queryObject);
 
-        Class classToPrefetch = broker.getReferenceBroker().getClassToPrefetch();
-        if ((classToPrefetch != null) && classToPrefetch.isAssignableFrom(queryObject.getClassDescriptor().getClassOfObject()))
+        if(queryObject.getClassDescriptor() != null)
         {
-            setItemProxyClass(null);
-        }
-        else
-        {
-            setItemProxyClass(queryObject.getClassDescriptor().getProxyClass());
+            Class classToPrefetch = broker.getReferenceBroker().getClassToPrefetch();
+            if ((classToPrefetch != null) && classToPrefetch.isAssignableFrom(queryObject.getClassDescriptor().getClassOfObject()))
+            {
+                setItemProxyClass(null);
+            }
+            else
+            {
+                setItemProxyClass(queryObject.getClassDescriptor().getProxyClass());
+            }
         }
 
         /*

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java?view=diff&rev=522118&r1=522117&r2=522118
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/RsQueryObject.java
Sat Mar 24 15:11:07 2007
@@ -18,11 +18,12 @@
 import org.apache.ojb.broker.query.Query;
 import org.apache.ojb.broker.query.QueryBySQL;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.metadata.DescriptorRepository;
+import org.apache.ojb.broker.core.ValueContainer;
 
 /**
  * Helper class for {@link RsIterator} queries.
  *
- * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
 public class RsQueryObject
@@ -60,11 +61,26 @@
     //*******************************************
     // public methods
     //*******************************************
+    /*
+    TODO: Complete rework of this hack in OJB 2.0
+    arminw: This is a hack to enable report queries
+    based on arbitrary sql statements.
+    */
+    private static final ClassDescriptor CLD_HACK;
+    static
+    {
+        CLD_HACK = new ClassDescriptor(new DescriptorRepository());
+        CLD_HACK.setClassOfObject(Object.class);
+    }
     public ResultSetAndStatement performQuery(JdbcAccess jdbcAccess)
     {
         if (isSQLBased())
         {
-
+            // If class-descriptor not set we expect an arbitrary sql-statement
+            if(this.cld == null)
+            {
+                return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(), CLD_HACK, new
ValueContainer[]{}, Query.NOT_SCROLLABLE);
+            }
             return jdbcAccess.executeSQL(((QueryBySQL) query).getSql(), cld, Query.SCROLLABLE);
         }
         else

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java?view=diff&rev=522118&r1=522117&r2=522118
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
Sat Mar 24 15:11:07 2007
@@ -2160,7 +2160,7 @@
      */
     public Iterator 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/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryFactory.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryFactory.java?view=diff&rev=522118&r1=522117&r2=522118
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryFactory.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryFactory.java
Sat Mar 24 15:11:07 2007
@@ -165,6 +165,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 static QueryBySQL newQuery(String sql)
+    {
+        return new QueryBySQL(null, sql);
+    }
+
+    /**
      * Searches the class descriptor for the ojbConcrete class attribute
      * if it finds the concrete class attribute, append a where clause which
      * specifies we can load all classes that are this type or extents of this type.



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