*/
public void initialize(ClassLoaderResolver clr)
{
assertIsUninitialized();
MapMetaData mapmd = mmd.getMap();
if (mapmd == null)
{
throw new NucleusUserException(LOCALISER.msg("057017",mmd));
}
PrimaryKeyMetaData pkmd = (mmd.getJoinMetaData() != null ? mmd.getJoinMetaData().getPrimaryKeyMetaData() : null);
boolean pkColsSpecified = (pkmd != null && pkmd.getColumnMetaData() != null);
boolean pkRequired = requiresPrimaryKey();
// Add owner mapping
ColumnMetaData[] ownerColmd = null;
if (mmd.getJoinMetaData() != null &&
mmd.getJoinMetaData().getColumnMetaData() != null &&
mmd.getJoinMetaData().getColumnMetaData().length > 0)
{
// Column mappings defined at this side (1-N, M-N)
// When specified at this side they use the <join> tag
ownerColmd = mmd.getJoinMetaData().getColumnMetaData();
}
ownerMapping = ColumnCreator.createColumnsForJoinTables(clr.classForName(ownerType), mmd, ownerColmd,
storeMgr, this, pkRequired, false, FieldRole.ROLE_OWNER, clr);
if (NucleusLogger.DATASTORE.isDebugEnabled())
{
debugMapping(ownerMapping);
}
String keyValueFieldName = (mmd.getKeyMetaData() != null ? mmd.getKeyMetaData().getMappedBy() : null);
String valueKeyFieldName = (mmd.getValueMetaData() != null ? mmd.getValueMetaData().getMappedBy() : null);
// Add key mapping
boolean keyPC = (mmd.hasMap() && mmd.getMap().keyIsPersistent());
Class keyCls = clr.classForName(mapmd.getKeyType());
if (keyValueFieldName != null && isEmbeddedValuePC())
{
// Added in value code
}
else if (isSerialisedKey() || isEmbeddedKeyPC() || (isEmbeddedKey() && !keyPC) ||
ClassUtils.isReferenceType(keyCls))
{
// Key = PC(embedded), PC(serialised), Non-PC(serialised), Non-PC(embedded), Reference
keyMapping = storeMgr.getMappingManager().getMapping(this, mmd, clr, FieldRole.ROLE_MAP_KEY);
if (Boolean.TRUE.equals(mmd.getContainer().allowNulls()))
{
// Make all key col(s) nullable so we can store null elements
for (int i=0;i<keyMapping.getNumberOfDatastoreMappings();i++)
{
Column elementCol = (Column)keyMapping.getDatastoreMapping(i).getDatastoreField();
elementCol.setNullable();
}
}
if (NucleusLogger.DATASTORE.isDebugEnabled())
{
debugMapping(keyMapping);
}
if (valueKeyFieldName != null && isEmbeddedKeyPC())
{
// Key (PC) is embedded and value is a field of the key
EmbeddedKeyPCMapping embMapping = (EmbeddedKeyPCMapping)keyMapping;
valueMapping = embMapping.getJavaTypeMapping(valueKeyFieldName);
}
}
else
{
// Key = PC
ColumnMetaData[] keyColmd = null;
KeyMetaData keymd = mmd.getKeyMetaData();
if (keymd != null && keymd.getColumnMetaData() != null && keymd.getColumnMetaData().length > 0)
{
// Column mappings defined at this side (1-N, M-N)
keyColmd = keymd.getColumnMetaData();
}
keyMapping = ColumnCreator.createColumnsForJoinTables(keyCls, mmd, keyColmd, storeMgr, this,
false, false, FieldRole.ROLE_MAP_KEY, clr);
if (mmd.getContainer().allowNulls() == Boolean.TRUE)
{
// Make all key col(s) nullable so we can store null elements
for (int i=0;i<keyMapping.getNumberOfDatastoreMappings();i++)
{
Column elementCol = (Column)keyMapping.getDatastoreMapping(i).getDatastoreField();
elementCol.setNullable();
}
}
if (NucleusLogger.DATASTORE.isDebugEnabled())
{
debugMapping(keyMapping);
}
}
// Add value mapping
boolean valuePC = (mmd.hasMap() && mmd.getMap().valueIsPersistent());
Class valueCls = clr.classForName(mapmd.getValueType());
if (valueKeyFieldName != null && isEmbeddedKeyPC())
{
// Added in key code
}
else if (isSerialisedValue() || isEmbeddedValuePC() || (isEmbeddedValue() && !valuePC) ||
ClassUtils.isReferenceType(valueCls))
{
// Value = PC(embedded), PC(serialised), Non-PC(serialised), Non-PC(embedded), Reference
valueMapping = storeMgr.getMappingManager().getMapping(this, mmd, clr, FieldRole.ROLE_MAP_VALUE);
if (mmd.getContainer().allowNulls() == Boolean.TRUE)
{
// Make all value col(s) nullable so we can store null elements
for (int i=0;i<valueMapping.getNumberOfDatastoreMappings();i++)
{
Column elementCol = (Column)valueMapping.getDatastoreMapping(i).getDatastoreField();
elementCol.setNullable();
}
}
if (NucleusLogger.DATASTORE.isDebugEnabled())
{
debugMapping(valueMapping);
}
if (keyValueFieldName != null && isEmbeddedValuePC())
{
// Value (PC) is embedded and key is a field of the value
EmbeddedValuePCMapping embMapping = (EmbeddedValuePCMapping)valueMapping;
keyMapping = embMapping.getJavaTypeMapping(keyValueFieldName);
}
}
else
{
// Value = PC
ColumnMetaData[] valueColmd = null;
ValueMetaData valuemd = mmd.getValueMetaData();
if (valuemd != null && valuemd.getColumnMetaData() != null && valuemd.getColumnMetaData().length > 0)
{
// Column mappings defined at this side (1-N, M-N)
valueColmd = valuemd.getColumnMetaData();
}
valueMapping = ColumnCreator.createColumnsForJoinTables(clr.classForName(mapmd.getValueType()), mmd,
valueColmd, storeMgr, this, false, true, FieldRole.ROLE_MAP_VALUE, clr);
if (mmd.getContainer().allowNulls() == Boolean.TRUE)
{
// Make all value col(s) nullable so we can store null elements
for (int i=0;i<valueMapping.getNumberOfDatastoreMappings();i++)