* @param obj
* @return Collection of Key
*/
public List getMtoNImplementor(CollectionDescriptor cod, Object obj)
{
ResultSetAndStatement rs = null;
ArrayList result = new ArrayList();
ClassDescriptor cld = pb.getDescriptorRepository().getDescriptorFor(obj.getClass());
ValueContainer[] pkValues = pb.serviceBrokerHelper().getKeyValues(cld, obj);
String[] pkColumns = cod.getFksToThisClass();
String[] fkColumns = cod.getFksToItemClass();
String table = cod.getIndirectionTable();
String selectStmt = pb.serviceSqlGenerator().getSelectMNStatement(table, fkColumns, pkColumns);
ClassDescriptor itemCLD = pb.getDescriptorRepository().getDescriptorFor(cod.getItemClass());
Collection extents = pb.getDescriptorRepository().getAllConcreteSubclassDescriptors(itemCLD);
if(extents.size() > 0)
{
itemCLD = (ClassDescriptor) extents.iterator().next();
}
FieldDescriptor[] itemClassPKFields = itemCLD.getPkFields();
if(itemClassPKFields.length != fkColumns.length)
{
throw new PersistenceBrokerException("All pk fields of the element-class need to" +
" be declared in the indirection table. Element class is "
+ itemCLD.getClassNameOfObject() + " with " + itemClassPKFields.length + " pk-fields." +
" Declared 'fk-pointing-to-element-class' elements in collection-descriptor are"
+ fkColumns.length);
}
try
{
rs = pb.serviceJdbcAccess().executeSQL(selectStmt, cld, pkValues, Query.NOT_SCROLLABLE);
while(rs.m_rs.next())
{
ValueContainer[] row = new ValueContainer[fkColumns.length];
for(int i = 0; i < row.length; i++)
{
row[i] = new ValueContainer(rs.m_rs.getObject(i + 1), itemClassPKFields[i].getJdbcType());
}
result.add(new MtoNBroker.Key(row));
}
}
catch(PersistenceBrokerException e)
{
throw e;
}
catch(SQLException e)
{
throw new PersistenceBrokerSQLException(e);
}
finally
{
if(rs != null) rs.close();
}
return result;
}