arminw 2005/11/13 07:36:01
Modified: src/java/org/apache/ojb/broker/core MtoNBroker.java
Log:
fix OJB-77
Revision Changes Path
1.21 +27 -4
db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java
Index: MtoNBroker.java
===================================================================
RCS file:
/home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/MtoNBroker.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- MtoNBroker.java 3 Oct 2005 17:35:25 -0000 1.20
+++ MtoNBroker.java 13 Nov 2005 15:36:01 -0000 1.21
@@ -19,14 +19,17 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.sql.SQLException;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.commons.lang.ArrayUtils;
import org.apache.ojb.broker.MtoNImplementor;
import org.apache.ojb.broker.OJBRuntimeException;
import org.apache.ojb.broker.PersistenceBrokerException;
import org.apache.ojb.broker.PersistenceBrokerInternal;
+import org.apache.ojb.broker.PersistenceBrokerSQLException;
import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
import org.apache.ojb.broker.metadata.ClassDescriptor;
@@ -96,6 +99,22 @@
return;
}
+ /*
+ fix for OJB-77, composite M & N keys that have some fields common
+ find the "shared" indirection table columns, values and remove these
from m- or n- side
+ */
+ for(int i = 0; i < otherPkColumns.length; i++)
+ {
+ int index = ArrayUtils.indexOf(pkColumns, otherPkColumns[i]);
+ if(index != -1)
+ {
+ // shared indirection table column found, remove this column
from one side
+ pkColumns = (String[]) ArrayUtils.remove(pkColumns, index);
+ // remove duplicate value too
+ pkValues = (ValueContainer[]) ArrayUtils.remove(pkValues,
index);
+ }
+ }
+
String[] cols = mergeColumns(pkColumns, otherPkColumns);
String insertStmt = pb.serviceSqlGenerator()
.getGenericPreparedStatement(SqlGenerator.TYPE_GENERIC_INSERT, table, cols,
null).getStatement();
@@ -156,9 +175,13 @@
result.add(new MtoNBroker.Key(row));
}
}
- catch(Exception e)
+ catch(PersistenceBrokerException e)
{
- throw new PersistenceBrokerException(e);
+ throw e;
+ }
+ catch(SQLException e)
+ {
+ throw new PersistenceBrokerSQLException(e);
}
finally
{
@@ -428,11 +451,11 @@
&& (columnNames != null)
&& (other.columnNames != null)
&& (columnNames.length == other.columnNames.length));
+
if(result)
{
for (int i = 0; i < columnNames.length; i++)
{
- // System.out.println("## test: " + this);
int otherIndex =
other.indexForColumn(columnNames[i]);
if(otherIndex < 0)
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]