db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olegn...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/batch BatchConnection.java
Date Tue, 13 Jan 2004 21:49:00 GMT
olegnitz    2004/01/13 13:49:00

  Modified:    src/java/org/apache/ojb/broker/util/batch Tag:
                        OJB_BRANCH_1_0 BatchConnection.java
  Log:
  merge trunk
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.12.2.1  +69 -15    db-ojb/src/java/org/apache/ojb/broker/util/batch/BatchConnection.java
  
  Index: BatchConnection.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/batch/BatchConnection.java,v
  retrieving revision 1.12
  retrieving revision 1.12.2.1
  diff -u -r1.12 -r1.12.2.1
  --- BatchConnection.java	2 Nov 2003 13:21:08 -0000	1.12
  +++ BatchConnection.java	13 Jan 2004 21:49:00 -0000	1.12.2.1
  @@ -61,6 +61,7 @@
   import java.sql.PreparedStatement;
   import java.sql.SQLException;
   import java.util.ArrayList;
  +import java.util.Collection;
   import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Iterator;
  @@ -77,6 +78,7 @@
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.platforms.PlatformException;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  @@ -124,30 +126,82 @@
           {
               ClassDescriptor desc = (ClassDescriptor) it.next();
               List ordList = desc.getObjectReferenceDescriptors();
  -
  -            if (ordList != null && !ordList.isEmpty()) {
  -                String tableName = desc.getFullTableName();
  -                HashSet fkTables = (HashSet) _fkInfo.get(tableName);
  -
  -                if (fkTables == null)
  -                {
  -                    fkTables = new HashSet();
  -                    _fkInfo.put(tableName, fkTables);
  -                }
  -
  +            if (!ordList.isEmpty())
  +            {
  +                HashSet fkTables = getFKTablesFor(desc.getFullTableName());
                   for (Iterator it2 = ordList.iterator(); it2.hasNext(); )
                   {
                       ObjectReferenceDescriptor ord =
                               (ObjectReferenceDescriptor) it2.next();
  -                    ClassDescriptor fkDesc =
  +                    ClassDescriptor oneDesc =
                               repos.getDescriptorFor(ord.getItemClass());
  -                    fkTables.add(fkDesc.getFullTableName());
  +                    fkTables.addAll(getFullTableNames(oneDesc, repos));
  +                }
  +            }
  +
  +            List codList = desc.getCollectionDescriptors();
  +            for (Iterator it2 = codList.iterator(); it2.hasNext(); )
  +            {
  +                CollectionDescriptor cod =
  +                        (CollectionDescriptor) it2.next();
  +                ClassDescriptor manyDesc =
  +                        repos.getDescriptorFor(cod.getItemClass());
  +                if (cod.isMtoNRelation())
  +                {
  +                    HashSet fkTables = getFKTablesFor(cod.getIndirectionTable());
  +                    fkTables.addAll(getFullTableNames(desc, repos));
  +                    fkTables.addAll(getFullTableNames(manyDesc, repos));
  +                }
  +                else
  +                {
  +                    HashSet manyTableNames = getFullTableNames(manyDesc, repos);
  +                    for (Iterator it3 = manyTableNames.iterator(); it3.hasNext(); )
  +                    {
  +                        HashSet fkTables = getFKTablesFor((String) it3.next());
  +                        fkTables.addAll(getFullTableNames(desc, repos));
  +                    }
                   }
               }
           }
  +System.err.println(_fkInfo);
           _pbkeyToFKInfo.put(broker.getPBKey(), _fkInfo);
       }
   
  +    private HashSet getFKTablesFor(String tableName)
  +    {
  +        HashSet fkTables = (HashSet) _fkInfo.get(tableName);
  +
  +        if (fkTables == null)
  +        {
  +            fkTables = new HashSet();
  +            _fkInfo.put(tableName, fkTables);
  +        }
  +        return fkTables;
  +    }
  +
  +    private HashSet getFullTableNames(ClassDescriptor desc, DescriptorRepository repos)
  +    {
  +        String tableName;
  +        HashSet tableNamesSet = new HashSet();
  +        Collection extents = desc.getExtentClasses();
  +
  +        tableName = desc.getFullTableName();
  +        if (tableName != null) {
  +            tableNamesSet.add(tableName);
  +        }
  +        for (Iterator it = extents.iterator(); it.hasNext(); )
  +        {
  +            Class extClass = (Class) it.next();
  +            ClassDescriptor extDesc = repos.getDescriptorFor(extClass);
  +            tableName = extDesc.getFullTableName();
  +            if (tableName != null) 
  +            {
  +                tableNamesSet.add(tableName);
  +            }
  +        }
  +        return tableNamesSet;
  +    }
  +
       public void setUseBatchInserts(boolean useBatchInserts)
       {
           _useBatchInserts = useBatchInserts;
  @@ -159,7 +213,7 @@
       void nextExecuted(String sql) throws SQLException
       {
           count++;
  -        
  +
           if (_order.contains(sql))
           {
               return;
  
  
  

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