You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ol...@apache.org on 2004/01/13 22:48:08 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/batch BatchConnection.java
olegnitz 2004/01/13 13:48:08
Modified: src/java/org/apache/ojb/broker/util/batch
BatchConnection.java
Log:
collection-descriptor's fk constraints are took into account
Revision Changes Path
1.13 +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.13
diff -u -r1.12 -r1.13
--- BatchConnection.java 2 Nov 2003 13:21:08 -0000 1.12
+++ BatchConnection.java 13 Jan 2004 21:48:08 -0000 1.13
@@ -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