arminw 2005/11/13 07:00:51
Modified: src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE
MtoNBroker.java
Log:
fix OJB-77
Revision Changes Path
No revision
No revision
1.10.2.7 +29 -11
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.10.2.6
retrieving revision 1.10.2.7
diff -u -r1.10.2.6 -r1.10.2.7
--- MtoNBroker.java 9 May 2005 14:26:55 -0000 1.10.2.6
+++ MtoNBroker.java 13 Nov 2005 15:00:51 -0000 1.10.2.7
@@ -19,13 +19,16 @@
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.PersistenceBrokerSQLException;
import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
import org.apache.ojb.broker.core.proxy.ProxyHelper;
import org.apache.ojb.broker.metadata.ClassDescriptor;
@@ -95,6 +98,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().getInsertMNStatement(table, pkColumns, otherPkColumns);
ValueContainer[] values = mergeContainer(pkValues, otherPkValues);
@@ -153,13 +172,17 @@
result.add(new MtoNBroker.Key(row));
}
}
- catch(Exception e)
+ catch(PersistenceBrokerException e)
+ {
+ throw e;
+ }
+ catch(SQLException e)
{
- throw new PersistenceBrokerException(e);
+ throw new PersistenceBrokerSQLException(e);
}
finally
{
- rs.close();
+ if(rs != null) rs.close();
}
return result;
}
@@ -283,7 +306,7 @@
String table = wanted.getIndirectionTable();
if(table == null) throw new PersistenceBrokerException("Can't
remove MtoN implementor without an indirection table");
- String stmt = null;
+ String stmt;
String[] cols = mergeColumns(pkLeftColumns, pkRightColumns);
ValueContainer[] values = mergeContainer(leftPkValues,
rightPkValues);
if(insert)
@@ -425,20 +448,15 @@
{
for (int i = 0; i < columnNames.length; i++)
{
- // System.out.println("## test: " + this);
int otherIndex =
other.indexForColumn(columnNames[i]);
if(otherIndex < 0)
{
result = false;
break;
}
- result = result &&
values[i].equals(other.values[otherIndex]);
+ result = values[i].equals(other.values[otherIndex]);
if(!result) break;
}
- // if(result)
- // {
- // System.out.println("## Match: " + this);
- // }
}
}
return result;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]