db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
Date Fri, 11 Mar 2005 20:13:03 GMT
brj         2005/03/11 12:13:02

  Modified:    src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        ReferenceTest.java
               src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        ClassDescriptor.java
  Log:
  fix for armin's reference problem
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.17.2.2  +61 -45    db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java
  
  Index: ReferenceTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ReferenceTest.java,v
  retrieving revision 1.17.2.1
  retrieving revision 1.17.2.2
  diff -u -r1.17.2.1 -r1.17.2.2
  --- ReferenceTest.java	10 Mar 2005 13:11:16 -0000	1.17.2.1
  +++ ReferenceTest.java	11 Mar 2005 20:13:01 -0000	1.17.2.2
  @@ -148,50 +148,66 @@
           newC = (ObjC) newB.getRef();
           assertEquals(3, newC.getReferences().size());
   
  -// TODO: Make these queries work
  -//        // expect all A's which third level 'ref' has a 'references'
  -//        // field collection, this is only valid for 'C' class objects
  -//        // and references contain '..._d1' object --> 'a'
  -//        crit = new Criteria();
  -//        crit.addLike("name", name+"_%");
  -//        Criteria critAnd = new Criteria();
  -//        critAnd.addEqualTo("ref.ref.references.name", name+"_d1");
  -//        // TODO: this doesn't work, how can we point to the right class?
  -//        critAnd.addPathClass("ref.ref", ObjC.class);
  -//        crit.addAndCriteria(critAnd);
  -//        q = QueryFactory.newQuery(ObjA.class, crit);
  -//        result = broker.getCollectionByQuery(q);
  -//        assertEquals(1, result.size());
  -//        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  -//        {
  -//            RefObject ref = (RefObject) iterator.next();
  -//            assertTrue(ref instanceof ObjA);
  -//            String refName = ref.getName();
  -//            assertTrue(!(refName.indexOf(name)<0));
  -//        }
  -//
  -//        // expect all A's with reference object named '_second%' and
  -//        // which third level 'ref' has a 'references'
  -//        // field collection, this is only valid for 'C' class objects
  -//        // and references contain '..._second%' objects --> 'a'
  -//        crit = new Criteria();
  -//        crit.addLike("name", name+"_%");
  -//        critAnd = new Criteria();
  -//        critAnd.addLike("ref.name", name+"_second%");
  -//        crit.addAndCriteria(critAnd);
  -//        Criteria critAnd2 = new Criteria();
  -//        critAnd2.addLike("ref.ref.references.name", name+"_second%");
  -//        crit.addAndCriteria(critAnd2);
  -//        q = QueryFactory.newQuery(ObjA.class, crit);
  -//        result = broker.getCollectionByQuery(q);
  -//        assertEquals(1, result.size());
  -//        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  -//        {
  -//            RefObject ref = (RefObject) iterator.next();
  -//            assertTrue(ref instanceof ObjA);
  -//            String refName = ref.getName();
  -//            assertTrue(!(refName.indexOf(name)<0));
  -//        }
  +        // expect all A's which have a B called '_second_1'
  +        crit = new Criteria();
  +        crit.addLike("name", name+"_%");
  +        crit.addEqualTo("ref.name", name+"_second_1");
  +        crit.addPathClass("ref", ObjB.class);
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +
  +        // expect all A's which have a B called '_second_1' and 
  +        // a C called '_third' 
  +        crit = new Criteria();
  +        crit.addLike("name", name+"_%");
  +        crit.addEqualTo("ref.name", name+"_second_1");
  +        crit.addEqualTo("ref.ref.name", name+"_third");
  +        crit.addPathClass("ref", ObjB.class);
  +        crit.addPathClass("ref.ref", ObjC.class);
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +
  +        // expect all A's which third level 'ref' has a 'references'
  +        // field collection, this is only valid for 'C' class objects
  +        // and references contain '..._d1' object --> 'a'
  +        crit = new Criteria();
  +        crit.addLike("name", name+"_%");
  +        crit.addEqualTo("ref.ref.references.name", name+"_d1");
  +        crit.addPathClass("ref", ObjB.class);
  +        crit.addPathClass("ref.ref", ObjC.class);
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            RefObject ref = (RefObject) iterator.next();
  +            assertTrue(ref instanceof ObjA);
  +            String refName = ref.getName();
  +            assertTrue(!(refName.indexOf(name)<0));
  +        }
  +
  +        // expect all A's with reference object named '_second%' and
  +        // which third level 'ref' has a 'references'
  +        // field collection, this is only valid for 'C' class objects
  +        // and references contain '..._second%' objects --> 'a'
  +        crit = new Criteria();
  +        crit.addLike("name", name+"_%");
  +        crit.addLike("ref.name", name+"_second%");
  +        crit.addLike("ref.ref.references.name", name+"_second%");
  +        crit.addPathClass("ref", ObjB.class);
  +        crit.addPathClass("ref.ref", ObjC.class);
  +        q = QueryFactory.newQuery(ObjA.class, crit);
  +        result = broker.getCollectionByQuery(q);
  +        assertEquals(1, result.size());
  +        for(Iterator iterator = result.iterator(); iterator.hasNext();)
  +        {
  +            RefObject ref = (RefObject) iterator.next();
  +            assertTrue(ref instanceof ObjA);
  +            String refName = ref.getName();
  +            assertTrue(!(refName.indexOf(name)<0));
  +        }
       }
   
       /**
  
  
  
  No                   revision
  No                   revision
  1.88.2.11 +11 -3     db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.88.2.10
  retrieving revision 1.88.2.11
  diff -u -r1.88.2.10 -r1.88.2.11
  --- ClassDescriptor.java	11 Mar 2005 11:27:50 -0000	1.88.2.10
  +++ ClassDescriptor.java	11 Mar 2005 20:13:02 -0000	1.88.2.11
  @@ -1234,6 +1234,7 @@
           FieldDescriptor fld = null;
           String currPath = aPath;
           String segment;
  +        StringBuffer processedSegment = new StringBuffer();
           int sepPos;
           Class itemClass = null;
   
  @@ -1250,6 +1251,12 @@
                   segment = currPath;
                   currPath = "";
               }
  +            
  +            if (processedSegment.length() > 0)
  +            {
  +                processedSegment.append(".");
  +            }           
  +            processedSegment.append(segment); 
   
               // look for 1:1 or n:1 Relationship
               ord = cld.getObjectReferenceDescriptorByName(segment);
  @@ -1261,8 +1268,9 @@
   
               if (ord != null)
               {
  -                // BRJ : look for hint
  -                List hintClasses = (List) pathHints.get(segment);
  +                // BRJ : look for hints for the processed segment
  +                // ie: ref pointng to ClassA and ref.ref pointing to ClassC 
  +                List hintClasses = (List) pathHints.get(processedSegment.toString());
                   if (hintClasses != null && hintClasses.get(0) != null)
                   {
                       itemClass = (Class) hintClasses.get(0);
  
  
  

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