// we know that the class is present because the collection constraints have been checked already
// TODO: we must check whether there is a collection at the other side; if the type does not map to a
// table then we have to check its subtypes
String elementClassName = collDef.getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
ClassDescriptorDef elementClass = modelDef.getClass(elementClassName);
CollectionDescriptorDef remoteCollDef = collDef.getRemoteCollection();
if (remoteCollDef == null)
{
// error if there is none and we don't have remote-foreignkey specified
if (!collDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY))
{
throw new ConstraintException("The collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" must specify remote-foreignkeys as the class on the other side of the m:n association has no corresponding collection");
}
}
else
{
String remoteKeys2 = remoteCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);
if (collDef.hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY))
{
// check that the specified remote-foreignkey equals the remote foreignkey setting
String remoteKeys1 = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
if (!CommaListIterator.sameLists(remoteKeys1, remoteKeys2))
{
throw new ConstraintException("The remote-foreignkey property specified for collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" doesn't match the foreignkey property of the corresponding collection "+remoteCollDef.getName()+" in class "+elementClass.getName());
}
}
else
{
// ensure the remote-foreignkey setting
collDef.setProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY, remoteKeys2);
}
}
// issue a warning if the foreignkey and remote-foreignkey columns are the same (issue OJB-67)
String remoteForeignkey = collDef.getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
if (CommaListIterator.sameLists(foreignkey, remoteForeignkey))
{
LogHelper.warn(true,
getClass(),
"checkIndirectionTable",
"The remote foreignkey ("+remoteForeignkey+") for the collection "+collDef.getName()+" in class "+collDef.getOwner().getName()+" is identical (ignoring case) to the foreign key ("+foreignkey+").");
}
// for torque we generate names for the m:n relation that are unique across inheritance
// but only if we don't have inherited collections
if (collDef.getOriginal() != null)
{
CollectionDescriptorDef origDef = (CollectionDescriptorDef)collDef.getOriginal();
CollectionDescriptorDef origRemoteDef = origDef.getRemoteCollection();
// we're removing any torque relation name properties from the base collection
origDef.setProperty(PropertyHelper.TORQUE_PROPERTY_RELATION_NAME, null);
origDef.setProperty(PropertyHelper.TORQUE_PROPERTY_INV_RELATION_NAME, null);
if (origRemoteDef != null)
{
origRemoteDef.setProperty(PropertyHelper.TORQUE_PROPERTY_RELATION_NAME, null);
origRemoteDef.setProperty(PropertyHelper.TORQUE_PROPERTY_INV_RELATION_NAME, null);
}
}
else if (!collDef.hasProperty(PropertyHelper.TORQUE_PROPERTY_RELATION_NAME))
{
if (remoteCollDef == null)