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/accesslayer MtoNCollectionPrefetcher.java
Date Sat, 24 Jan 2004 14:05:25 GMT
brj         2004/01/24 06:05:25

  Modified:    src/java/org/apache/ojb/broker/accesslayer Tag:
                        OJB_BRANCH_1_0 MtoNCollectionPrefetcher.java
  Log:
  fix problem with missing indirection prefix
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.4   +56 -20    db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java
  
  Index: MtoNCollectionPrefetcher.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- MtoNCollectionPrefetcher.java	15 Jan 2004 21:01:54 -0000	1.1.2.3
  +++ MtoNCollectionPrefetcher.java	24 Jan 2004 14:05:25 -0000	1.1.2.4
  @@ -141,9 +141,9 @@
        */
       protected Query buildPrefetchQuery(Collection ids)
       {
  -        CollectionDescriptor cds = getCollectionDescriptor();
  -        String[] indFkCols = cds.getFksToThisClass();
  -        String[] indItemFkCols = cds.getFksToItemClass();
  +        CollectionDescriptor cds = getCollectionDescriptor(); 
  +        String[] indFkCols = getFksToThisClass();
  +        String[] indItemFkCols = getFksToItemClass();
           FieldDescriptor[] itemPkFields = getItemClassDescriptor().getPkFields();
       
           Criteria crit = buildPrefetchCriteria(ids, indFkCols, indItemFkCols, itemPkFields);
  @@ -152,11 +152,16 @@
       }
   
       
  +    /**
  +     * Build a query to read the mn-implementors
  +     * @param ids
  +     * @return
  +     */
       protected Query buildMtoNImplementorQuery(Collection ids)
       {
           CollectionDescriptor cds = getCollectionDescriptor();
  -        String[] indFkCols = cds.getFksToThisClass();
  -        String[] indItemFkCols = cds.getFksToItemClass();
  +        String[] indFkCols = getFksToThisClass();
  +        String[] indItemFkCols = getFksToItemClass();
           FieldDescriptor[] itemPkFields = getItemClassDescriptor().getPkFields();
           String[] cols = new String[indFkCols.length + indItemFkCols.length]; 
           
  @@ -172,6 +177,42 @@
       }
   
       /**
  +     * prefix the this class fk columns with the indirection table
  +     * @return
  +     */
  +    private String[] getFksToThisClass()
  +    {
  +        String indTable = getCollectionDescriptor().getIndirectionTable();
  +        String[] fks = getCollectionDescriptor().getFksToThisClass();
  +        String[] result = new String[fks.length];
  +        
  +        for (int i = 0; i < result.length; i++)
  +        {
  +            result[i] = indTable + "." + fks[i];
  +        }
  +        
  +        return result;
  +    }
  +    
  +    /**
  +     * prefix the item class fk columns with the indirection table
  +     * @return
  +     */
  +    private String[] getFksToItemClass()
  +    { 
  +        String indTable = getCollectionDescriptor().getIndirectionTable();
  +        String[] fks = getCollectionDescriptor().getFksToItemClass();
  +        String[] result = new String[fks.length];
  +          
  +        for (int i = 0; i < result.length; i++)
  +        {
  +            result[i] = indTable + "." + fks[i];
  +        }
  +        
  +        return result;
  +    } 
  +    
  +    /**
        * Build the multiple queries for one relationship because of limitation of IN(...)
        * 
        * @param owners Collection containing all objects of the ONE side
  @@ -235,7 +276,7 @@
        * 
        * @param ids Collection of identities of M side
        * @param fkCol indirection table fks to this class
  -     * @param itemFkCol indirection table fks to item class
  +     * @param itemFk indirection table fks to item class
        * @param itemPkField
        * @return
        */
  @@ -245,10 +286,7 @@
           ArrayList values = new ArrayList();
           Iterator iter = ids.iterator();
           Identity id;
  -    
  -        String fkColumn = getCollectionDescriptor().getIndirectionTable() + "." + fkCol;
  -        String itemFkColumn = getCollectionDescriptor().getIndirectionTable() + "." + itemFkCol;
  -    
  +       
           while (iter.hasNext())
           {
               id = (Identity) iter.next();
  @@ -260,15 +298,15 @@
               case 0 :
                   break;
               case 1 :
  -                crit.addEqualTo(fkColumn, values.get(0));
  +                crit.addEqualTo(fkCol, values.get(0));
                   break;
               default :
                   // create IN (...) for the single key field
  -                crit.addIn(fkColumn, values);
  +                crit.addIn(fkCol, values);
                   break;
           }
       
  -        crit.addEqualToField(itemPkField.getAttributeName(), itemFkColumn);
  +        crit.addEqualToField(itemPkField.getAttributeName(), itemFkCol);
   
           return crit;
       }
  @@ -295,19 +333,17 @@
       
               for (int i = 0; i < val.length; i++)
               {
  -                String fkColumn = getCollectionDescriptor().getIndirectionTable() + "."
+ fkCols[i];
  -                String itemFkColumn = getCollectionDescriptor().getIndirectionTable() +
"." + itemFkCols[i];
  -    
  +   
                   if (val[i] == null)
                   {
  -                    c.addIsNull(fkColumn);
  +                    c.addIsNull(fkCols[i]);
                   }
                   else
                   {
  -                    c.addEqualTo(fkColumn, val[i]);
  +                    c.addEqualTo(fkCols[i], val[i]);
                   }
       
  -                crit.addEqualToField(itemPkFields[i].getAttributeName(), itemFkColumn);
  +                crit.addEqualToField(itemPkFields[i].getAttributeName(), itemFkCols[i]);
               }
               crit.addOrCriteria(c);
           }
  
  
  

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