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/query LikeCriteria.java
Date Mon, 26 Jul 2004 15:49:52 GMT
brj         2004/07/26 08:49:52

  Modified:    src/java/org/apache/ojb/broker/util Tag: OJB_1_0_RELEASE
                        BrokerHelper.java
               src/java/org/apache/ojb/broker/accesslayer/sql Tag:
                        OJB_1_0_RELEASE SqlSelectStatement.java
                        SqlQueryStatement.java
               src/test/org/apache/ojb/broker Tag: OJB_1_0_RELEASE
                        QueryTest.java
               .        Tag: OJB_1_0_RELEASE release-notes.txt
               src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
                        QueryReferenceBroker.java
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/core/proxy Tag:
                        OJB_1_0_RELEASE CollectionProxyDefaultImpl.java
               src/java/org/apache/ojb/broker/query Tag: OJB_1_0_RELEASE
                        LikeCriteria.java
  Log:
  - fixed issue with CollectionProxy and RemovalAwareCollection
  - RemovalAwareCollection is no longer the default collection-class for m:n-relationships
  - ManageableCollection#afterStore is only called if cascadeStoring is CASCADE_OBJECT
  
  - ojb no longer adds groupBy columns to the SELECT-clause, orderBy columns are still added
because of sapdb
  - orderBy columns of the original query are used as joinAttributes in count-query
  - ALIAS-prefix again works for report-queries (see QueryTest#testReportQueryAlias)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.57.2.1  +15 -1     db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java
  
  Index: BrokerHelper.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/BrokerHelper.java,v
  retrieving revision 1.57
  retrieving revision 1.57.2.1
  diff -u -r1.57 -r1.57.2.1
  --- BrokerHelper.java	25 Jun 2004 16:08:45 -0000	1.57
  +++ BrokerHelper.java	26 Jul 2004 15:49:51 -0000	1.57.2.1
  @@ -20,6 +20,7 @@
   import java.sql.SQLException;
   import java.util.Collection;
   import java.util.Iterator;
  +import java.util.List;
   import java.util.Map;
   import java.util.StringTokenizer;
   import java.util.WeakHashMap;
  @@ -593,6 +594,19 @@
               {
                   countQuery.setPathOuterJoin(path);
               }
  +        }
  +        
  +        //BRJ: add orderBy Columns asJoinAttributes
  +        List orderBy = aQuery.getOrderBy();
  +        if (orderBy != null && !orderBy.isEmpty())
  +        {
  +            String[] joinAttributes = new String[orderBy.size()];
  +            for (int i=0; i<orderBy.size(); i++)
  +            {
  +                joinAttributes[i] = ((FieldHelper)orderBy.get(i)).name;
  +            }
  +            
  +            countQuery.setJoinAttributes(joinAttributes);            
           }
   
           return countQuery;
  
  
  
  No                   revision
  No                   revision
  1.22.2.1  +10 -18    db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java
  
  Index: SqlSelectStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlSelectStatement.java,v
  retrieving revision 1.22
  retrieving revision 1.22.2.1
  diff -u -r1.22 -r1.22.2.1
  --- SqlSelectStatement.java	24 Apr 2004 08:25:38 -0000	1.22
  +++ SqlSelectStatement.java	26 Jul 2004 15:49:51 -0000	1.22.2.1
  @@ -136,10 +136,10 @@
           Query query = getQuery();
           boolean first = true;
           List orderByFields = null;
  -        int[] orderByColumnNumbers = null;
           String[] attributes = null;
           String[] joinAttributes = null;
           Iterator it = getJoinTreeToCriteria().entrySet().iterator();
  +        List columnList = new ArrayList();
   
           if (query instanceof ReportQuery)
           {
  @@ -152,7 +152,6 @@
               Map.Entry entry = (Map.Entry) it.next();
               Criteria whereCrit = (Criteria) entry.getValue();
               Criteria havingCrit = query.getHavingCriteria();
  -            List columnList;
               StringBuffer where = new StringBuffer();
               StringBuffer having = new StringBuffer();
               List groupByFields = null;
  @@ -193,11 +192,12 @@
                    * will allow us to load objects with unique mapping fields that are mapped
                    * to the same table.
                    */
  -                columnList = appendListOfColumnsForSelect(getSearchClassDescriptor(), stmt);
  +                
  +                columnList.addAll(appendListOfColumnsForSelect(getSearchClassDescriptor(),
stmt));
               }
               else
               {
  -                columnList = appendListOfColumns(attributes, stmt);
  +                columnList.addAll(appendListOfColumns(attributes, stmt));
               }
   
               // BRJ:
  @@ -209,24 +209,16 @@
               {
                   for (int i = 0; i < joinAttributes.length; i++)
                   {
  -                	// PAW: correct for pathClasses?
  -					//getAttributeInfo(joinAttributes[i], false, null);
   					getAttributeInfo(joinAttributes[i], false, null, getQuery().getPathClasses());
                   }
               }
   
               groupByFields = query.getGroupBy();
  -            if (groupByFields != null && !groupByFields.isEmpty())
  -            {
  -                ensureColumns(groupByFields, columnList, stmt);
  -            }
  -
  +            ensureColumns(groupByFields, columnList);
  +            
               orderByFields = query.getOrderBy();
  -            if (orderByFields != null && !orderByFields.isEmpty())
  -            {
  -                orderByColumnNumbers = ensureColumns(orderByFields, columnList, stmt);
  -            }
  -
  +            columnList = ensureColumns(orderByFields, columnList, stmt);
  +          
               /**
                * treeder: going to map superclass tables here, 
                * not sure about the columns, just using all columns for now
  @@ -253,7 +245,7 @@
               appendHavingClause(having, havingCrit, stmt);
           }
   
  -        appendOrderByClause(orderByFields, orderByColumnNumbers, stmt);
  +        appendOrderByClause(orderByFields, columnList, stmt);
   
           return stmt.toString();
       }
  
  
  
  1.75.2.1  +100 -49   db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
  
  Index: SqlQueryStatement.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
  retrieving revision 1.75
  retrieving revision 1.75.2.1
  diff -u -r1.75 -r1.75.2.1
  --- SqlQueryStatement.java	22 May 2004 09:51:25 -0000	1.75
  +++ SqlQueryStatement.java	26 Jul 2004 15:49:51 -0000	1.75.2.1
  @@ -47,6 +47,8 @@
    */
   public abstract class SqlQueryStatement implements SqlStatement, JoinSyntaxTypes
   {
  +    private static final String ALIAS_SEPARATOR = ".";
  +    
       private SqlQueryStatement m_parentStatement;
       /** the logger */
       private Logger m_logger;
  @@ -423,7 +425,6 @@
        */
   	protected boolean appendColName(String attr, boolean useOuterJoins, UserAlias aUserAlias,
StringBuffer buf)
       {
  -		// PAW: is this correct for pathClasses ?
   		AttributeInfo attrInfo = getAttributeInfo(attr, useOuterJoins, aUserAlias, getQuery().getPathClasses());
           TableAlias tableAlias = attrInfo.tableAlias;
   
  @@ -448,7 +449,6 @@
   	protected boolean appendColName(String attr, String attrAlias, boolean useOuterJoins,
UserAlias aUserAlias,
               StringBuffer buf)
       {
  -		// PAW: is this correct for pathClasses ?
   		AttributeInfo attrInfo = getAttributeInfo(attr, useOuterJoins, aUserAlias, getQuery().getPathClasses());
           TableAlias tableAlias = attrInfo.tableAlias;
           PathInfo pi = attrInfo.pathInfo;
  @@ -466,6 +466,66 @@
       }
   
       /**
  +     * Builds the Join for columns if they are not found among the existingColumns.
  +     * @param columns the list of columns represented by Criteria.Field to ensure
  +     * @param existingColumns the list of column names (String) that are already appended
  +     */
  +    protected void ensureColumns(List columns, List existingColumns)
  +    {
  +        if (columns == null || columns.isEmpty())
  +        {
  +            return;
  +        }
  +        
  +        Iterator iter = columns.iterator();
  +
  +        while (iter.hasNext())
  +        {
  +            FieldHelper cf = (FieldHelper) iter.next();
  +            if (!existingColumns.contains(cf.name))
  +            {
  +                getAttributeInfo(cf.name, false, null, getQuery().getPathClasses());
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Builds the Join for columns if they are not found among the existingColumns.
  +     * These <b>columns are added to the statement</b> using a column-alias
"ojb_col_x", 
  +     * x being the number of existing columns
  +     * @param columns the list of columns represented by Criteria.Field to ensure
  +     * @param existingColumns the list of column names (String) that are already appended
  +     * @param buf the statement
  +     * @return List of existingColumns including ojb_col_x
  +     */
  +    protected List ensureColumns(List columns, List existingColumns, StringBuffer buf)
  +    {
  +        if (columns == null || columns.isEmpty())
  +        {
  +            return existingColumns;
  +        }
  +
  +        Iterator iter = columns.iterator();
  +        int ojb_col = existingColumns.size() + 1;
  +
  +        while (iter.hasNext())
  +        {
  +            FieldHelper cf = (FieldHelper) iter.next();
  +            if (!existingColumns.contains(cf.name))
  +            {
  +                existingColumns.add(cf.name);
  +                
  +                buf.append(",");
  +                appendColName(cf.name, "ojb_col_" + ojb_col, false, null, buf);
  +                ojb_col++;
  +            }
  +        }
  +        
  +        return existingColumns;
  +    }
  +
  +
  +    /**
        * appends a WHERE-clause to the Statement
        * @param where
        * @param crit
  @@ -1187,7 +1247,7 @@
   		}
   		else
   		{
  -			return createTableAlias(aCld, hints, aUserAlias + aPath);
  +			return createTableAlias(aCld, hints, aUserAlias + ALIAS_SEPARATOR + aPath);
   		}
       }
   
  @@ -1230,7 +1290,7 @@
   		}
   		else
   		{
  -			return createTableAlias(aTable, aUserAlias + aPath);
  +			return createTableAlias(aTable, aUserAlias + ALIAS_SEPARATOR + aPath);
   		}
       }
   
  @@ -1291,7 +1351,7 @@
           }
           else
           {
  -			return getTableAliasForPath(aUserAlias + aPath);
  +			return getTableAliasForPath(aUserAlias + ALIAS_SEPARATOR + aPath);
           }
       }
   
  @@ -1322,27 +1382,43 @@
   		return (ClassDescriptor) classDescriptors.get(0);
   	}
   
  -    /**
  -     * Appends to the statement the ORDER BY clause for the Query
  -     */
  -    protected void appendOrderByClause(List orderByFields, int[] orderByColumnNumbers,
StringBuffer buf)
  +	/**
  +     * Appends the ORDER BY clause for the Query.
  +     * <br>
  +     * If the orderByField is found in the list of selected fields it's index is added.

  +     * Otherwise it's name is added.
  +	 * @param orderByFields 
  +	 * @param selectedFields the names of the fields in the SELECT clause
  +	 * @param buf
  +	 */
  +    protected void appendOrderByClause(List orderByFields, List selectedFields, StringBuffer
buf)
       {
  -        FieldHelper cf;
   
  -        if (orderByColumnNumbers == null)
  +        if (orderByFields == null || orderByFields.size() == 0)
           {
               return;
           }
  -
  +        
           buf.append(" ORDER BY ");
  -        for (int i = 0; i < orderByColumnNumbers.length; i++)
  +        for (int i = 0; i < orderByFields.size(); i++)
           {
  -            cf = (FieldHelper) orderByFields.get(i);
  +            FieldHelper cf = (FieldHelper) orderByFields.get(i);
  +            int colNumber = selectedFields.indexOf(cf.name);
  +            
               if (i > 0)
               {
                   buf.append(",");
               }
  -            buf.append(orderByColumnNumbers[i]);
  +            
  +            if (colNumber >= 0)
  +            {
  +                buf.append(colNumber + 1);                
  +            }
  +            else
  +            {            
  +                appendColName(cf.name, false, null, buf);
  +            }
  +            
               if (!cf.isAscending)
               {
                   buf.append(" DESC");
  @@ -1351,12 +1427,12 @@
       }
   
       /**
  -     * Appends to the statement the GROUP BY clause for the Query
  +     * Appends the GROUP BY clause for the Query
  +	 * @param groupByFields 
  +	 * @param buf
        */
       protected void appendGroupByClause(List groupByFields, StringBuffer buf)
       {
  -        FieldHelper cf;
  -
           if (groupByFields == null || groupByFields.size() == 0)
           {
               return;
  @@ -1365,11 +1441,13 @@
           buf.append(" GROUP BY ");
           for (int i = 0; i < groupByFields.size(); i++)
           {
  -            cf = (FieldHelper) groupByFields.get(i);
  +            FieldHelper cf = (FieldHelper) groupByFields.get(i);
  + 
               if (i > 0)
               {
                   buf.append(",");
               }
  +
               appendColName(cf.name, false, null, buf);
           }
       }
  @@ -1493,34 +1571,6 @@
       }
   
       /**
  -     * Appends to the statement columns if they are not found among the existingColumns.
  -     * Columns added here use a column-alias "ojb_col_x", x being the number of existing
columns
  -     * @param columns the list of columns represented by Criteria.Field to ensure
  -     * @param existingColumns the list of column names (String) that are already appended
  -     * @return the array of column numbers (base 1)
  -     */
  -    protected int[] ensureColumns(List columns, List existingColumns, StringBuffer buf)
  -    {
  -        FieldHelper cf;
  -        int[] columnNumbers = new int[columns.size()];
  -
  -        for (int i = 0; i < columnNumbers.length; i++)
  -        {
  -            cf = (FieldHelper) columns.get(i);
  -            columnNumbers[i] = existingColumns.indexOf(cf.name);
  -            if (columnNumbers[i] == -1)
  -            {
  -                columnNumbers[i] = existingColumns.size();
  -                existingColumns.add(cf.name);
  -                buf.append(",");
  -                appendColName(cf.name, "ojb_col_" + columnNumbers[i], false, null, buf);
  -            }
  -            columnNumbers[i]++; // columns numbers have base 1
  -        }
  -        return columnNumbers;
  -    }
  -
  -    /**
        * Build the tree of joins for the given criteria
        */
       private void buildJoinTree(Criteria crit)
  @@ -1637,7 +1687,8 @@
           }
   
       }
  -
  + 
  +    
       /**
        * Gets the query.
        * @return Returns a Query
  
  
  
  No                   revision
  No                   revision
  1.61.2.1  +183 -2    db-ojb/src/test/org/apache/ojb/broker/QueryTest.java
  
  Index: QueryTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/QueryTest.java,v
  retrieving revision 1.61
  retrieving revision 1.61.2.1
  diff -u -r1.61 -r1.61.2.1
  --- QueryTest.java	25 Jun 2004 13:11:35 -0000	1.61
  +++ QueryTest.java	26 Jul 2004 15:49:52 -0000	1.61.2.1
  @@ -116,6 +116,46 @@
       }
   
       /**
  +	 * test sql Criteria
  +	 */
  +    public void testSqlCriteria()
  +    {
  +        Criteria crit; 
  +        Query q;
  +        Collection results;
  +        
  +        // sql only
  +        crit = new Criteria();
  +        crit.addSql("upper(firstname) = 'TOM' and id = 1");
  +        q = QueryFactory.newQuery(Person.class, crit);
  +
  +        results = broker.getCollectionByQuery(q);
  +        int size1 = results.size();
  +        
  +        // sql plus attribute 
  +        crit = new Criteria();
  +        crit.addSql("upper(firstname) = 'TOM'");
  +        crit.addEqualTo("id",new Integer(1));
  +        q = QueryFactory.newQuery(Person.class, crit);
  +
  +        results = broker.getCollectionByQuery(q);
  +        int size2 = results.size();
  +        
  +        // attribute plus sql 
  +        crit = new Criteria();
  +        crit.addEqualTo("upper(firstname)","TOM");
  +        crit.addSql("id = 1");
  +        q = QueryFactory.newQuery(Person.class, crit);
  +
  +        results = broker.getCollectionByQuery(q);
  +        int size3 = results.size();
  +        
  +        assertTrue(size2 == size1);
  +        assertTrue(size3 == size2);
  +    }
  +
  +   
  +    /**
   	 * test OrderBy and Count
   	 */
       public void testOrderByCount()
  @@ -133,7 +173,27 @@
           int count = broker.getCount(q);
           assertEquals(results.size(), count);        
       }
  -    
  +
  +    /**
  +	 * test OrderBy joined column
  +	 */
  +    public void testOrderByJoined()
  +    {
  +        Criteria crit = new Criteria();
  +        QueryByCriteria q = QueryFactory.newQuery(Project.class, crit);
  +        q.addOrderByAscending("title");
  +        q.addOrderByAscending("persons.lastname");
  +        q.addOrderByAscending("persons.firstname");
  +
  +        Collection results = broker.getCollectionByQuery(q);
  +        assertNotNull(results);
  +        assertTrue(results.size() == 14);
  +        
  +        // compare with count
  +        int count = broker.getCount(q);
  +        assertEquals(results.size(), count);        
  +    }
  +
       /**
   	 * test Subquery get all product groups without articles
   	 *
  @@ -169,7 +229,7 @@
   
           results = broker.getCollectionByQuery(q);
           assertNotNull(results);
  -        System.out.println("*** Found " + results.size() + " empty ProductGroups ***");
  +        // System.out.println("*** Found " + results.size() + " empty ProductGroups ***");
           assertEquals("Result of the query with sub-query does not match", loops, results.size());
   
       }
  @@ -508,6 +568,36 @@
       }
   
       /**
  +	 * Simple ReportQuery returning rows with max(id) of Person grouped by not selected columns
  +	 */
  +    public void testReportQueryGroupByNonSelectColumns()
  +    {
  +
  +        Criteria crit = new Criteria();
  +        Collection results = new Vector();
  +        ReportQueryByCriteria q = QueryFactory.newReportQuery(Person.class, crit);
  +        q.setAttributes(new String[] { "max(id)" });
  +        q.addGroupBy(new String[] { "lastname", "firstname" });
  +
  +        Iterator iter = broker.getReportQueryIteratorByQuery(q);
  +
  +        assertNotNull(iter);
  +        while (iter.hasNext())
  +        {
  +            Object[] row = (Object[])iter.next();
  +            assertEquals(row.length, 1);
  +
  +            results.add(row);
  +        }
  +
  +        assertEquals(results.size(), 10);
  +
  +        // compare with count
  +        int count = broker.getCount(q);
  +        assertEquals(results.size(), count);
  +    }
  +    
  +    /**
        * Simple ReportQuery returning rows with 3 columns of Person
        * Type of column data defined by sqltypes
        * @see java.sql.Types
  @@ -1297,6 +1387,38 @@
       }
   
       /**
  +	 * Test ReportQuery and Alias
  +	 */
  +    public void testReportQueryAlias()
  +    {
  +        ArrayList list = new java.util.ArrayList();
  +
  +        Criteria crit1 = new Criteria();
  +        crit1.setAlias("NAMES");
  +        crit1.addLike("upper(allArticlesInGroup.articleName)", "F%");
  +
  +        Criteria crit2 = new Criteria();
  +        crit2.setAlias("STOCKS");
  +        crit2.addGreaterOrEqualThan("allArticlesInGroup.stock", new Integer(110));
  +
  +        crit1.addAndCriteria(crit2);
  +        ReportQueryByCriteria q = QueryFactory.newReportQuery(ProductGroup.class, crit1);
  +        q.setAttributes(new String[]{"groupId", "groupName", "STOCKS.allArticlesInGroup.articleName","NAMES.allArticlesInGroup.stock"});
  +
  +        // Due to AliasPrefixes ArticleName is taken from A2, Stock from A1, 
  +        // SELECT A0.Kategorie_Nr,A0.KategorieName,A2.Artikelname,A1.Lagerbestand FROM
Kategorien ...
  +        
  +        Iterator iter = broker.getReportQueryIteratorByQuery(q);
  +        while (iter.hasNext())
  +        {
  +            list.add(iter.next());
  +        }
  +
  +        // ProductGroup 4 with it's Articles
  +        assertEquals("check size", list.size(), 1);
  +    }
  +    
  +    /**
   	 * Run a query range test that includes one record less than the total
   	 * number of records that exist.
   	 */
  @@ -1483,6 +1605,65 @@
   
           int count = broker.getCount(qry21);
           assertEquals(count, result.size());
  +    }
  +
  +    public void testExtentByInterface()
  +    {
  +        String name = "testExtentByInterface_" + System.currentTimeMillis();
  +        Zoo zoo = new Zoo();
  +        zoo.setName(name);
  +        Mammal m1 = new Mammal();
  +        m1.setName(name);
  +        Mammal m2 = new Mammal();
  +        m2.setName(name);
  +        Reptile r1 = new Reptile();
  +        r1.setName(name);
  +        broker.beginTransaction();
  +        broker.store(zoo);
  +        m1.setZooId(zoo.getZooId());
  +        m2.setZooId(zoo.getZooId());
  +        r1.setZooId(zoo.getZooId());
  +        broker.store(m1);
  +        broker.store(m2);
  +        broker.store(r1);
  +        broker.commitTransaction();
  +
  +        Criteria crit = new Criteria();
  +        crit.addEqualTo("name", name);
  +
  +        QueryByCriteria queryAnimals = QueryFactory.newQuery(InterfaceAnimal.class, crit);
  +        QueryByCriteria queryReptile = QueryFactory.newQuery(Reptile.class, crit);
  +        QueryByCriteria queryMammal = QueryFactory.newQuery(Mammal.class, crit);
  +
  +        Collection resultA = broker.getCollectionByQuery(queryAnimals);
  +        Collection resultR = broker.getCollectionByQuery(queryReptile);
  +        Collection resultM = broker.getCollectionByQuery(queryMammal);
  +
  +        assertEquals(3, resultA.size());
  +        assertEquals(1, resultR.size());
  +        assertEquals(2, resultM.size());
  +
  +        for (Iterator iterator = resultA.iterator(); iterator.hasNext();)
  +        {
  +            InterfaceAnimal a =  (InterfaceAnimal) iterator.next();
  +            assertEquals(name, a.getName());
  +
  +        }
  +        for (Iterator iterator = resultR.iterator(); iterator.hasNext();)
  +        {
  +            Reptile a =  (Reptile) iterator.next();
  +            assertEquals(name, a.getName());
  +        }
  +        for (Iterator iterator = resultM.iterator(); iterator.hasNext();)
  +        {
  +            Mammal a =  (Mammal) iterator.next();
  +            assertEquals(name, a.getName());
  +        }
  +
  +        Reptile reptile = (Reptile) broker.getObjectByQuery(queryReptile);
  +        Mammal mammal = (Mammal) broker.getObjectByQuery(queryMammal);
  +        assertNotNull(reptile);
  +        assertNotNull(mammal);
       }
   
   }
  
  
  
  No                   revision
  No                   revision
  1.54.2.1  +14 -1     db-ojb/release-notes.txt
  
  Index: release-notes.txt
  ===================================================================
  RCS file: /home/cvs/db-ojb/release-notes.txt,v
  retrieving revision 1.54
  retrieving revision 1.54.2.1
  diff -u -r1.54 -r1.54.2.1
  --- release-notes.txt	26 Jun 2004 23:43:38 -0000	1.54
  +++ release-notes.txt	26 Jul 2004 15:49:52 -0000	1.54.2.1
  @@ -8,6 +8,19 @@
   relational databases. OJB provides ODMG and JDO interfaces.
   
   ---------------------------------------------------------------------
  +Release 1.0.x
  +---------------------------------------------------------------------
  +fixed:
  +
  +- fixed issue with CollectionProxy and RemovalAwareCollection
  +- RemovalAwareCollection is no longer the default collection-class for m:n-relationships
  +- ManageableCollection#afterStore is only called if cascadeStoring is CASCADE_OBJECT
  +
  +- ojb no longer adds groupBy columns to the SELECT-clause, orderBy columns are still added
because of sapdb
  +- orderBy columns of the original query are used as joinAttributes in count-query
  +- ALIAS-prefix again works for report-queries (see QueryTest#testReportQueryAlias) 
  +
  +---------------------------------------------------------------------
   Release 1.0
   ---------------------------------------------------------------------
   NEW FEATURES:
  
  
  
  No                   revision
  No                   revision
  1.17.2.1  +20 -2     db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java
  
  Index: QueryReferenceBroker.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v
  retrieving revision 1.17
  retrieving revision 1.17.2.1
  diff -u -r1.17 -r1.17.2.1
  --- QueryReferenceBroker.java	22 May 2004 09:51:25 -0000	1.17
  +++ QueryReferenceBroker.java	26 Jul 2004 15:49:52 -0000	1.17.2.1
  @@ -50,6 +50,7 @@
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.query.QueryFactory;
  +import org.apache.ojb.broker.util.collections.ManageableArrayList;
   import org.apache.ojb.broker.util.collections.RemovalAwareCollection;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -253,6 +254,23 @@
       }
   
       /**
  +     * retrieve a collection of itemClass Objects matching the Query query
  +     */
  +    private Collection getCollectionByQuery(Query query, CollectionDescriptor cds) throws
PersistenceBrokerException
  +    {
  +        // BRJ: do not use RemovalAwareCollection for m:n relationships
  +        // see http://db.apache.org/ojb/docu/guides/basic-technique.html#Mapping+m%3An+associations
  +        if (cds.isMtoNRelation())
  +        {
  +            return (Collection) getCollectionByQuery(ManageableArrayList.class, query,
cds.isLazy());
  +        }
  +        else
  +        {
  +            return (Collection) getCollectionByQuery(RemovalAwareCollection.class, query,
cds.isLazy());
  +        }
  +    }
  +    
  +    /**
        * @return true if this is the first task for the given ObjectReferenceDescriptor
        */
       private boolean addRetrievalTask(Object obj, Object key)
  @@ -545,7 +563,7 @@
   
                   if (collectionClass == null)
                   {
  -                    Collection result = getCollectionByQuery(fkQuery, cds.isLazy());
  +                    Collection result = getCollectionByQuery(fkQuery, cds);
   
                       // assign collection to objects attribute
                       // if attribute has an array type build an array, else assign collection
directly
  
  
  
  1.83.2.1  +13 -11    db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java,v
  retrieving revision 1.83
  retrieving revision 1.83.2.1
  diff -u -r1.83 -r1.83.2.1
  --- PersistenceBrokerImpl.java	24 Jun 2004 15:22:57 -0000	1.83
  +++ PersistenceBrokerImpl.java	26 Jul 2004 15:49:52 -0000	1.83.2.1
  @@ -79,7 +79,7 @@
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
    * @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz<a>
    * @author <a href="mailto:mattbaird@yahoo.com">Matthew Baird<a>
  - * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
  + * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
    *
    * @version $Id$
    */
  @@ -782,7 +782,7 @@
           // get all members of obj that are collections and store all their elements
           Collection listCods = cld.getCollectionDescriptors();
           // return if nothing to do
  -        if(listCods.size() == 0)
  +        if (listCods.size() == 0)
           {
               return;
           }
  @@ -790,13 +790,12 @@
           while (i.hasNext())
           {
               CollectionDescriptor cod = (CollectionDescriptor) i.next();
  -            /*
  -            if CASCADE_NONE was set, do nothing with referenced objects
  -            */
  -            if(cod.getCascadingStore() != ObjectReferenceDescriptor.CASCADE_NONE)
  +
  +            // if CASCADE_NONE was set, do nothing with referenced objects
  +            if (cod.getCascadingStore() != ObjectReferenceDescriptor.CASCADE_NONE)
               {
                   Object referencedObjects = cod.getPersistentField().get(obj);
  -                if(cod.isMtoNRelation())
  +                if (cod.isMtoNRelation())
                   {
                       storeAndLinkMtoN(false, obj, cod, referencedObjects, insert);
                   }
  @@ -804,8 +803,11 @@
                   {
                       storeAndLinkOneToMany(false, obj, cod, referencedObjects, insert);
                   }
  -                // invoke callback on collection
  -                if (referencedObjects instanceof ManageableCollection)
  +
  +                // BRJ: only when auto-update = object (CASCADE_OBJECT)
  +                // 
  +                if ((cod.getCascadingStore() == ObjectReferenceDescriptor.CASCADE_OBJECT)
  +                        && (referencedObjects instanceof ManageableCollection))
                   {
                       ((ManageableCollection) referencedObjects).afterStore(this);
                   }
  @@ -919,7 +921,7 @@
           if(insert || !(referencedObjects instanceof CollectionProxyDefaultImpl
                           && !((CollectionProxyDefaultImpl) referencedObjects).isLoaded()))
           {
  -            Iterator it = serviceBrokerHelper().getCollectionIterator(referencedObjects);
  +            Iterator it = BrokerHelper.getCollectionIterator(referencedObjects);
               Object refObj;
               while(it.hasNext())
               {
  
  
  
  No                   revision
  No                   revision
  1.7.2.1   +18 -15    db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxyDefaultImpl.java
  
  Index: CollectionProxyDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/proxy/CollectionProxyDefaultImpl.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- CollectionProxyDefaultImpl.java	10 Jun 2004 14:40:08 -0000	1.7
  +++ CollectionProxyDefaultImpl.java	26 Jul 2004 15:49:52 -0000	1.7.2.1
  @@ -315,27 +315,30 @@
        */
       public void clear()
       {
  -        Collection coll;
           Class collClass = getCollectionClass();
  -        
  +
           // ECER: assure we notify all objects being removed, 
  -        // necessary for RemovalAware classes...
  -        if (IRemovalAwareCollection.class.isAssignableFrom(collClass)) 
  +        // necessary for RemovalAwareCollections...
  +        if (IRemovalAwareCollection.class.isAssignableFrom(collClass))
           {
               getData().clear();
  -        }    
  -
  -        // BRJ: use an empty collection so isLoaded will return true
  -        try
  -        {
  -            coll = (Collection) collClass.newInstance();
           }
  -        catch (Exception e)
  +        else
           {
  -            coll = new ArrayList();
  +            Collection coll;
  +            // BRJ: use an empty collection so isLoaded will return true
  +            // for non RemovalAwareCollections only !! 
  +            try
  +            {
  +                coll = (Collection) collClass.newInstance();
  +            }
  +            catch (Exception e)
  +            {
  +                coll = new ArrayList();
  +            }
  +
  +            setData(coll);
           }
  -        
  -        setData(coll);
           _size = 0;
       }
   
  
  
  
  No                   revision
  No                   revision
  1.11.2.1  +20 -12    db-ojb/src/java/org/apache/ojb/broker/query/LikeCriteria.java
  
  Index: LikeCriteria.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/LikeCriteria.java,v
  retrieving revision 1.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- LikeCriteria.java	25 Jun 2004 13:11:35 -0000	1.11
  +++ LikeCriteria.java	26 Jul 2004 15:49:52 -0000	1.11.2.1
  @@ -33,6 +33,15 @@
    */
   public class LikeCriteria extends ValueCriteria
   {
  +    /**
  +     * The Dfault-Character used for Escaping Wildcards
  +     */
  +    public static final char DEFAULT_ESCPAPE_CHARACTER = '\\';
  +
  +    /**
  +     * The Character used for Escaping Wildcards
  +     */
  +    private static char escapeCharacter = DEFAULT_ESCPAPE_CHARACTER;
   
   	/**
   	 * @param anAttribute
  @@ -42,7 +51,7 @@
   	 */
   	public LikeCriteria(Object anAttribute, Object aValue, String aClause, String anAlias)
   	{
  -		super(anAttribute, generateSQLSearchPattern((String) aValue), aClause, anAlias);
  +		super(anAttribute, generateSQLSearchPattern(aValue), aClause, anAlias);
   	}
   
   	/**
  @@ -53,18 +62,16 @@
   	 */
   	public LikeCriteria(Object anAttribute, Object aValue, String aClause, UserAlias anAlias)
   	{
  -		super(anAttribute, generateSQLSearchPattern((String) aValue), aClause, anAlias);
  +		super(anAttribute, generateSQLSearchPattern(aValue), aClause, anAlias);
   	}
   
       /**
  -     * The Dfault-Character used for Escaping Wildcards
  +     * @see org.apache.ojb.broker.query.SelectionCriteria#bind(java.lang.Object)
        */
  -    public static final char DEFAULT_ESCPAPE_CHARACTER = '\\';
  -
  -    /**
  -     * The Character used for Escaping Wildcards
  -     */
  -    private static char escapeCharacter = DEFAULT_ESCPAPE_CHARACTER;
  +    public void bind(Object newValue)
  +    {
  +        super.bind(generateSQLSearchPattern(newValue));
  +    }
   
       /**
        * Generate a SQL search string from the pattern string passed. 
  @@ -76,7 +83,7 @@
        * @param pattern a criteria search pattern containing optional wildcards
        * @return a SQL search pattern string with all escape codes processed.
        */
  -	private static String generateSQLSearchPattern(String pattern)
  +	private static String generateSQLSearchPattern(Object pattern)
   	{
   		if (pattern == null)
   		{
  @@ -85,7 +92,7 @@
   		else
   		{
   			StringBuffer sqlpattern = new StringBuffer();
  -			char[] chars = pattern.toCharArray();
  +			char[] chars = pattern.toString().toCharArray();
   
   			for (int i = 0; i < chars.length; i++)
   			{
  @@ -167,4 +174,5 @@
       {
           escapeCharacter = escChar;
       }
  +    
   }
  
  
  

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