Author: arminw
Date: Sat Feb 11 17:46:48 2006
New Revision: 377107
URL: http://svn.apache.org/viewcvs?rev=377107&view=rev
Log:
Fixed: Batch handling doesn't work properly on insert when database identity
columns are used. Now OJB execute the batch statement after insert of objects
using identity columns.
Fixed: Batch handling doesn't work proper when adding new class-descriptor at
runtime and when using different metadata profiles.
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/batch/BatchConnection.java
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
URL:
http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java?rev=377107&r1=377106&r2=377107&view=diff
==============================================================================
---
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
(original)
+++
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
Sat Feb 11 17:46:48 2006
@@ -16,7 +16,15 @@
*/
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
@@ -25,8 +33,8 @@
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.locking.IsolationLevels;
import org.apache.ojb.broker.util.ClassHelper;
-import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.broker.util.logging.Logger;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
/**
* The repository containing all object mapping and manipulation information of
@@ -64,7 +72,7 @@
* (@see DescriptorRepository#getExtentClass). To speed up the costy
* evaluation, we use this tiny hash map.
*/
- private Map extentTable;
+ private final Map extentTable;
private Map superClassMultipleJoinedTablesMap;
@@ -72,6 +80,10 @@
private transient Map m_topLevelClassTable;
private transient Map m_firstConcreteClassMap;
private transient Map m_allConcreteSubClass;
+ /**
+ * Maps table name to List of related tables (N:1 or 1:1)
+ */
+ private transient Map m_batchConnectionKeyToFKMap;
/**
* Constructor declaration
@@ -114,7 +126,7 @@
ClassDescriptor cld = (ClassDescriptor)
extentTable.remove(classname);
if(cld != null && m_topLevelClassTable != null)
{
- Class extClass = null;
+ Class extClass;
try
{
extClass = ClassHelper.getClass(classname);
@@ -221,7 +233,7 @@
Set visitedColumns = new HashSet();
Iterator it = classDescriptors.iterator();
- ClassDescriptor temp = null;
+ ClassDescriptor temp;
FieldDescriptor[] fields;
while (it.hasNext())
{
@@ -495,6 +507,7 @@
m_topLevelClassTable = null;
m_firstConcreteClassMap = null;
m_allConcreteSubClass = null;
+ m_batchConnectionKeyToFKMap = null;
}
/**
@@ -556,7 +569,7 @@
Iterator i = this.iterator();
while (i.hasNext())
{
- buf.append(((XmlCapable) i.next()).toXML() + eol);
+ buf.append(((XmlCapable) i.next()).toXML()).append(eol);
}
return buf.toString();
}
@@ -666,7 +679,8 @@
if (result != null)
{
- descriptorTable.put(clazz.getName(), result);
+ // descriptorTable.put(clazz.getName(), result);
+ put(clazz, result);
}
}
return result;
@@ -803,6 +817,100 @@
}
}
}
+ }
+
+ /**
+ * Used by [EMAIL PROTECTED]
org.apache.ojb.broker.util.batch.BatchConnection} to
+ * resolve PK/FK references.
+ * @deprecated Will be removed in next major version.
+ */
+ public synchronized Map getBatchConnectionPkToFkMap()
+ {
+ if(m_batchConnectionKeyToFKMap == null)
+ {
+ Map fkInfo = new HashMap();
+ for (Iterator it = iterator(); it.hasNext();)
+ {
+ ClassDescriptor desc = (ClassDescriptor) it.next();
+ List ordList = desc.getObjectReferenceDescriptors();
+ if (!ordList.isEmpty())
+ {
+ HashSet fkTables = getFKTablesFor(desc.getFullTableName(),
fkInfo);
+ for (Iterator it2 = ordList.iterator(); it2.hasNext();)
+ {
+ ObjectReferenceDescriptor ord =
(ObjectReferenceDescriptor) it2.next();
+ ClassDescriptor oneDesc =
getDescriptorFor(ord.getItemClass());
+ fkTables.addAll(getFullTableNames(oneDesc));
+ }
+ }
+
+ List codList = desc.getCollectionDescriptors();
+ for (Iterator it2 = codList.iterator(); it2.hasNext();)
+ {
+ CollectionDescriptor cod = (CollectionDescriptor)
it2.next();
+ ClassDescriptor manyDesc =
getDescriptorFor(cod.getItemClass());
+ if (cod.isMtoNRelation())
+ {
+ HashSet fkTables =
getFKTablesFor(cod.getIndirectionTable(), fkInfo);
+ fkTables.addAll(getFullTableNames(desc));
+ fkTables.addAll(getFullTableNames(manyDesc));
+ }
+ else
+ {
+ HashSet manyTableNames = getFullTableNames(manyDesc);
+ for (Iterator it3 = manyTableNames.iterator();
it3.hasNext();)
+ {
+ HashSet fkTables = getFKTablesFor((String)
it3.next(), fkInfo);
+ fkTables.addAll(getFullTableNames(desc));
+ }
+ }
+ }
+ }
+ m_batchConnectionKeyToFKMap = fkInfo;
+ }
+ return m_batchConnectionKeyToFKMap;
+ }
+
+ /**
+ * @deprecated Will be removed in next major version.
+ */
+ private HashSet getFKTablesFor(String tableName, Map fkInfo)
+ {
+ HashSet fkTables = (HashSet) fkInfo.get(tableName);
+
+ if (fkTables == null)
+ {
+ fkTables = new HashSet();
+ fkInfo.put(tableName, fkTables);
+ }
+ return fkTables;
+ }
+
+ /**
+ * @deprecated Will be removed in next major version.
+ */
+ private HashSet getFullTableNames(ClassDescriptor desc)
+ {
+ 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 = getDescriptorFor(extClass);
+ tableName = extDesc.getFullTableName();
+ if (tableName != null)
+ {
+ tableNamesSet.add(tableName);
+ }
+ }
+ return tableNamesSet;
}
protected void finalize() throws Throwable
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/batch/BatchConnection.java
URL:
http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/batch/BatchConnection.java?rev=377107&r1=377106&r2=377107&view=diff
==============================================================================
---
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/batch/BatchConnection.java
(original)
+++
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/batch/BatchConnection.java
Sat Feb 11 17:46:48 2006
@@ -21,18 +21,13 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
+import java.util.Map;
import org.apache.ojb.broker.PersistenceBroker;
-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.JdbcConnectionDescriptor;
-import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
import org.apache.ojb.broker.util.WrappedConnection;
/**
@@ -47,16 +42,10 @@
{
private static final int MAX_COUNT = 100;
- /**
- * Maps PBKey to another HashMap,
- * which maps table name to List of related tables (N:1 or 1:1)
- */
- private static HashMap _pbkeyToFKInfo = new HashMap();
-
private boolean _useBatchInserts = true;
private HashMap _statements = new HashMap();
private ArrayList _order = new ArrayList();
- private HashMap _fkInfo;
+ private Map _fkInfo;
private HashSet _deleted;
private HashSet _dontInsert;
private HashSet _touched = new HashSet();
@@ -67,88 +56,7 @@
{
super(conn);
m_jcd = broker.serviceConnectionManager().getConnectionDescriptor();
- _fkInfo = (HashMap) _pbkeyToFKInfo.get(broker.getPBKey());
- if (_fkInfo != null)
- {
- return;
- }
-
- DescriptorRepository repos = broker.getDescriptorRepository();
- _fkInfo = new HashMap();
- for (Iterator it = repos.iterator(); it.hasNext();)
- {
- ClassDescriptor desc = (ClassDescriptor) it.next();
- List ordList = desc.getObjectReferenceDescriptors();
- if (!ordList.isEmpty())
- {
- HashSet fkTables = getFKTablesFor(desc.getFullTableName());
- for (Iterator it2 = ordList.iterator(); it2.hasNext();)
- {
- ObjectReferenceDescriptor ord =
(ObjectReferenceDescriptor) it2.next();
- ClassDescriptor oneDesc =
repos.getDescriptorFor(ord.getItemClass());
- 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));
- }
- }
- }
- }
- _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;
+ _fkInfo =
broker.getDescriptorRepository().getBatchConnectionPkToFkMap();
}
public void setUseBatchInserts(boolean useBatchInserts)
@@ -271,9 +179,7 @@
public PreparedStatement prepareStatement(String sql) throws SQLException
{
- PreparedStatement stmt = null;
- stmt = prepareBatchStatement(sql);
-
+ PreparedStatement stmt = prepareBatchStatement(sql);
if (stmt == null)
{
stmt = getDelegate().prepareStatement(sql);
@@ -284,9 +190,7 @@
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency)
throws SQLException
{
- PreparedStatement stmt = null;
- stmt = prepareBatchStatement(sql);
-
+ PreparedStatement stmt = prepareBatchStatement(sql);
if (stmt == null)
{
stmt = getDelegate().prepareStatement(sql, resultSetType,
resultSetConcurrency);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]