db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r521168 - /db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryByCriteriaImpl.java
Date Thu, 22 Mar 2007 09:31:15 GMT
Author: arminw
Date: Thu Mar 22 02:31:14 2007
New Revision: 521168

URL: http://svn.apache.org/viewvc?view=rev&rev=521168
Log:
remove dependency to static MetadataManager by using preprocess call to prepare object attribute
projection

Modified:
    db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryByCriteriaImpl.java

Modified: db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryByCriteriaImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryByCriteriaImpl.java?view=diff&rev=521168&r1=521167&r2=521168
==============================================================================
--- db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryByCriteriaImpl.java (original)
+++ db/ojb/trunk/src/java/org/apache/ojb/broker/query/QueryByCriteriaImpl.java Thu Mar 22
02:31:14 2007
@@ -25,7 +25,6 @@
 import org.apache.ojb.broker.PersistenceBrokerInternal;
 import org.apache.ojb.broker.metadata.ClassDescriptor;
 import org.apache.ojb.broker.metadata.FieldHelper;
-import org.apache.ojb.broker.metadata.MetadataManager;
 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
 
 /**
@@ -72,7 +71,7 @@
     protected QueryByCriteriaImpl()
     {
     }
-    
+
     /**
      * Build a Query for class targetClass with criteria.
      * Criteriy may be null (will result in a query returning ALL objects from a table)
@@ -132,7 +131,7 @@
     public QueryByCriteriaImpl(QueryByCriteriaImpl aQuery)
     {
         this (aQuery.getSearchClass());
-        
+
         if (aQuery.getCriteria() != null)
         {
             setCriteria(new Criteria(aQuery.getCriteria(),true,true,true));
@@ -155,7 +154,7 @@
         setWithExtents(aQuery.getWithExtents());
         setStartAtIndex(aQuery.getStartAtIndex());
         setEndAtIndex(aQuery.getEndAtIndex());
-        
+
         m_groupby = aQuery.getGroupBy();
         m_orderby = aQuery.getOrderBy();
         m_objectProjectionAttribute = aQuery.getObjectProjectionAttribute();
@@ -278,29 +277,29 @@
         return m_pathClasses;
     }
 
-	/**
+    /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#setCriteria(org.apache.ojb.broker.query.Criteria)
      */
-	public void setCriteria(Criteria criteria)
-	{
-		m_criteria = criteria;
+    public void setCriteria(Criteria criteria)
+    {
+        m_criteria = criteria;
         if (m_criteria != null)
         {
             m_criteria.setQuery(this);
         }
-	}
+    }
 
-	/**
+    /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#setHavingCriteria(org.apache.ojb.broker.query.Criteria)
      */
-	public void setHavingCriteria(Criteria havingCriteria)
-	{
-		m_havingCriteria = havingCriteria;
+    public void setHavingCriteria(Criteria havingCriteria)
+    {
+        m_havingCriteria = havingCriteria;
         if (m_havingCriteria != null)
         {
             m_havingCriteria.setQuery(this);
         }
-	}
+    }
 
     /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#addGroupBy(java.lang.String)
@@ -335,11 +334,11 @@
         }
     }
 
-	/**
+    /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#getGroupBy()
      */
-	public List getGroupBy()
-	{
+    public List getGroupBy()
+    {
         // BRJ:
         // combine data from query and criteria
         // TODO: to be removed when Criteria#addGroupBy is removed
@@ -352,7 +351,7 @@
         }
 
         return temp;
-	}
+    }
 
     /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#addOrderBy(java.lang.String, boolean)
@@ -424,14 +423,14 @@
         addOrderBy(fieldName, false);
     }
 
-	/* (non-Javadoc)
-	 * @see org.apache.ojb.broker.query.Query#getOrderBy()
-	 */
-	/**
+    /* (non-Javadoc)
+      * @see org.apache.ojb.broker.query.Query#getOrderBy()
+      */
+    /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#getOrderBy()
      */
-	public List getOrderBy()
-	{
+    public List getOrderBy()
+    {
         // BRJ:
         // combine data from query and criteria
         // TODO: to be removed when Criteria#addOrderBy is removed
@@ -444,7 +443,7 @@
         }
 
         return temp;
-	}
+    }
 
     /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#addPrefetchedRelationship(java.lang.String)
@@ -454,11 +453,11 @@
         m_prefetchedRelationships.add(aName);
     }
 
-	/**
+    /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#getPrefetchedRelationships()
      */
-	public List getPrefetchedRelationships()
-	{
+    public List getPrefetchedRelationships()
+    {
         // BRJ:
         // combine data from query and criteria
         // TODO: to be removed when Criteria#addPrefetchedRelationship is removed
@@ -473,14 +472,14 @@
         return temp;
     }
 
-	/**
+    /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#getOuterJoinPaths()
      */
     public Collection getOuterJoinPaths()
     {
         return m_pathOuterJoins;
     }
-    
+
     /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#getObjectProjectionAttribute()
      */
@@ -489,43 +488,46 @@
         return m_objectProjectionAttribute;
     }
 
-    /**
-     * @see org.apache.ojb.broker.query.QueryByCriteria#setObjectProjectionAttribute(java.lang.String)
-     */
     public void setObjectProjectionAttribute(String objectProjectionAttribute)
     {
-        ClassDescriptor baseCld = MetadataManager.getInstance().getRepository().getDescriptorFor(getBaseClass());
-        ArrayList descs = baseCld.getAttributeDescriptorsForPath(objectProjectionAttribute);
-        int pathLen = descs.size();
-
-        if ((pathLen > 0) && (descs.get(pathLen - 1) instanceof ObjectReferenceDescriptor))
-        {
-            ObjectReferenceDescriptor ord =
-                    ((ObjectReferenceDescriptor) descs.get(pathLen - 1));
-            setObjectProjectionAttribute(objectProjectionAttribute,
-                                         ord.getItemClass());
-        }
+        m_objectProjectionAttribute = objectProjectionAttribute;
     }
 
     /**
      * @see org.apache.ojb.broker.query.QueryByCriteria#setObjectProjectionAttribute(java.lang.String,
java.lang.Class)
      */
-    public void setObjectProjectionAttribute(String objectProjectionAttribute,
-                                             Class objectProjectionClass)
+    public void setObjectProjectionAttribute(String objectProjectionAttribute, Class objectProjectionClass)
     {
         m_objectProjectionAttribute = objectProjectionAttribute;
         setSearchClass(objectProjectionClass);
-	}
-    
+    }
+
+    private void prepareObjectProjectionAttribute(PersistenceBrokerInternal broker)
+    {
+        if(m_objectProjectionAttribute != null && getSearchClass() == null)
+        {
+            ClassDescriptor baseCld = broker.getDescriptorRepository().getDescriptorFor(getBaseClass());
+            ArrayList descs = baseCld.getAttributeDescriptorsForPath(m_objectProjectionAttribute);
+            int pathLen = descs.size();
+            if ((pathLen > 0) && (descs.get(pathLen - 1) instanceof ObjectReferenceDescriptor))
+            {
+                ObjectReferenceDescriptor ord = ((ObjectReferenceDescriptor) descs.get(pathLen
- 1));
+                setObjectProjectionAttribute(m_objectProjectionAttribute, ord.getItemClass());
+            }
+        }
+    }
+
     /**
      * @see org.apache.ojb.broker.query.Query#preprocess(org.apache.ojb.broker.PersistenceBrokerInternal)
      */
     public void preprocess(PersistenceBrokerInternal broker)
     {
         super.preprocess(broker);
+        // prepare object projection attribute
+        prepareObjectProjectionAttribute(broker);
         if (getCriteria() != null)
         {
             getCriteria().preprocess(broker);
-        }    
+        }
     }
 }



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