db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: query Criteria: per path-segment alias
Date Sat, 29 May 2004 14:59:21 GMT
hi phil,

i added the new testcase to PathTest and it passed WITHOUT the modification in 
ClassDescriptor !?

jakob


Phil Warrick wrote:

> Hi Jakob,
> 
> I've added a new test case to PathTest that uncovered a problem with the 
> definition of segment: with criteria we associate pathHints with 
> segmentPaths (e.g. "As.Bs.C") whereas in
> 
> o.a.o.broker.metadata.ClassDescriptor#
> getAttributeDescriptorsForCleanPath(String aPath, Map pathHints)
> 
> the pathhints are associated with single segments ("As" or "Bs" or "C"). 
>  I modified this method to be consistent with the Criteria use (and my 
> new test case), but I'm not sure if this affects the assumptions that 
> other clients have about this method.
> 
> Phil
> 
> 
> ------------------------------------------------------------------------
> 
>     /**
>      * return all AttributeDescriptors for the path<br>
>      * ie: partner.addresses.street returns a Collection of 3 AttributeDescriptors
>      * (ObjectReferenceDescriptor, CollectionDescriptor, FieldDescriptor)<br>
>      * ie: partner.addresses returns a Collection of 2 AttributeDescriptors
>      * (ObjectReferenceDescriptor, CollectionDescriptor)
>      * @param aPath the cleaned path to the attribute
>      * @param pathHints a Map containing the class to be used for a segment
>      * @return ArrayList of AttributeDescriptors
>      */
>     private ArrayList getAttributeDescriptorsForCleanPath(String aPath, Map pathHints)
>     {
>         ArrayList result = new ArrayList();
>         ClassDescriptor cld = this;
>         ObjectReferenceDescriptor ord = null;
>         FieldDescriptor fld = null;
>         String currPath = aPath;
>         String segment;
>         int sepPos;
>         Class itemClass = null;
>         
>         // PAW
>         int segmentPathPos = -1;
> 	String segmentPath = null;
> 		
>         while (currPath.length() > 0)
>         {
>             sepPos = currPath.indexOf(".");
>             if (sepPos >= 0)
>             {
>                 segment = currPath.substring(0, sepPos);
>                 currPath = currPath.substring(sepPos + 1);
>                 // PAW
>                 segmentPathPos += sepPos + 1;
>                 segmentPath = aPath.substring(0, segmentPathPos); 
>             }
>             else
>             {
>                 segment = currPath;
>                 currPath = "";
>                 // PAW
>                 segmentPath = aPath;
>             }
> 
>             // look for 1:1 or n:1 Relationship
>             ord = cld.getObjectReferenceDescriptorByName(segment);
>             if (ord == null)
>             {
>                 // look for 1:n or m:n Relationship
>                 ord = cld.getCollectionDescriptorByName(segment);
>             }
> 
>             if (ord != null)
>             {
>                 // BRJ : look for hint
> 				//List hintClasses = (List) pathHints.get(segment);
> 				// PAW
> 				List hintClasses = (List) pathHints.get(segmentPath);
>                 if (hintClasses != null && hintClasses.get(0) != null)
>                 {
>                     itemClass = (Class) hintClasses.get(0);
>                 }
>                 else
>                 {
>                     itemClass = ord.getItemClass();
>                 }
> 
>                 cld = cld.getRepository().getDescriptorFor(itemClass);
>                 result.add(ord);
>             }
>             else
>             {
>                 // look for Field
>                 fld = cld.getFieldDescriptorByName(segment);
>                 if (fld != null)
>                 {
>                     result.add(fld);
>                 }
>             }
>         }
> 
>         return result;
>     }
> 
> 
> ------------------------------------------------------------------------
> 
> 	/*
> 	 *  Find all Bs having a particular C1-D combination
> 	 *  Works
> 	 */
> 	public void testPathClassReferenceAttrib() throws Exception
> 	{
> 		try
> 		{
> 			// c1_a criteria 
> 			Criteria crit1 = new Criteria();
> 			crit1.addEqualTo("cSet.c1Attrib", new Integer("10001"));
> 			crit1.addEqualTo("cSet.d.dAttrib", new Integer("10010"));
> 			crit1.addPathClass("cSet", C1.class); 
> 
> 			QueryByCriteria query = new QueryByCriteria(B.class, crit1);
> 
> 			Collection allBs = broker.getCollectionByQuery(query);
> 
> 			java.util.Iterator itr = allBs.iterator();
> 
> 			assertEquals(1, allBs.size());
> 			System.out.println("testPathClassReferenceAttrib() iteration size:" + allBs.size());
> 			while (itr.hasNext())
> 			{
> 				B b = (B) itr.next();
> 				System.out.println("Found B:  " + b.getId() + " " + b.getBAttrib());
> 			}
> 		}
> 		catch (Throwable t)
> 		{
> 			t.printStackTrace(System.out);
> 			fail("testPathClassReferenceAttrib: " + t.getMessage());
> 		}
> 	}
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org

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