membersToAdd[pkFieldNum++] = mmd;
hasPrimaryKeyInThisClass = true;
}
else if (mmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
{
throw new NucleusException(LOCALISER.msg("057006", mmd.getName())).setFatal();
}
// Check if auto-increment and that it is supported by this RDBMS
if ((mmd.getValueStrategy() == IdentityStrategy.IDENTITY) &&
!dba.supportsOption(DatastoreAdapter.IDENTITY_COLUMNS))
{
throw new NucleusException(LOCALISER.msg("057020",
cmd.getFullClassName(), mmd.getName())).setFatal();
}
}
}
}
else
{
for (int relFieldNum=0; relFieldNum<fieldCount; ++relFieldNum)
{
AbstractMemberMetaData fmd = cmd.getMetaDataForManagedMemberAtPosition(relFieldNum);
if (fmd.isPrimaryKey())
{
if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
{
membersToAdd[pkFieldNum++] = fmd;
hasPrimaryKeyInThisClass = true;
}
else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
{
throw new NucleusException(LOCALISER.msg("057006",fmd.getName())).setFatal();
}
// Check if auto-increment and that it is supported by this RDBMS
if ((fmd.getValueStrategy() == IdentityStrategy.IDENTITY) &&
!dba.supportsOption(DatastoreAdapter.IDENTITY_COLUMNS))
{
throw new NucleusException(LOCALISER.msg("057020",
cmd.getFullClassName(), fmd.getName())).setFatal();
}
}
}
}
}
// No Primary Key defined, so search for superclass or handle datastore id
if (!hasPrimaryKeyInThisClass)
{
if (cmd.getIdentityType() == IdentityType.APPLICATION)
{
// application-identity
DatastoreClass elementCT = storeMgr.getDatastoreClass(cmd.getPersistenceCapableSuperclass(), clr);
if (elementCT != null)
{
// Superclass has a table so copy its PK mappings
ColumnMetaDataContainer colContainer = null;
if (cmd.getInheritanceMetaData() != null)
{
// Try via <inheritance><join>...</join></inheritance>
colContainer = cmd.getInheritanceMetaData().getJoinMetaData();
}
if (colContainer == null)
{
// Try via <primary-key>...</primary-key>
colContainer = cmd.getPrimaryKeyMetaData();
}
addApplicationIdUsingClassTableId(colContainer, elementCT, clr, cmd);
}
else
{
// Superclass has no table so create new mappings and columns
AbstractClassMetaData pkCmd = storeMgr.getClassWithPrimaryKeyForClass(cmd.getSuperAbstractClassMetaData(), clr);
if (pkCmd != null)
{
pkMappings = new JavaTypeMapping[pkCmd.getNoOfPrimaryKeyMembers()];
pkFieldNum = 0;
fieldCount = pkCmd.getNoOfInheritedManagedMembers() + pkCmd.getNoOfManagedMembers();
for (int absFieldNum = 0; absFieldNum < fieldCount; ++absFieldNum)
{
AbstractMemberMetaData fmd = pkCmd.getMetaDataForManagedMemberAtAbsolutePosition(absFieldNum);
if (fmd.isPrimaryKey())
{
AbstractMemberMetaData overriddenFmd = cmd.getOverriddenMember(fmd.getName());
if (overriddenFmd != null)
{
// PK field is overridden so use the overriding definition
fmd = overriddenFmd;
}
if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT)
{
membersToAdd[pkFieldNum++] = fmd;
}
else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL)
{
throw new NucleusException(LOCALISER.msg("057006",fmd.getName())).setFatal();
}
}
}
}
}
}
else if (cmd.getIdentityType() == IdentityType.DATASTORE)
{
// datastore-identity
ColumnMetaDataContainer colContainer = null;
if (cmd.getIdentityMetaData() != null && cmd.getIdentityMetaData().getColumnMetaData() != null &&
cmd.getIdentityMetaData().getColumnMetaData().length > 0)
{
// Try via <datastore-identity>...</datastore-identity>
colContainer = cmd.getIdentityMetaData();
}
if (colContainer == null)
{
// Try via <primary-key>...</primary-key>
colContainer = cmd.getPrimaryKeyMetaData();
}
addDatastoreId(colContainer, null, cmd);
}
else if (cmd.getIdentityType() == IdentityType.NONDURABLE)
{
// Do nothing since no identity!
}
}
//add field mappings in the end, so we compute all columns after the post initialize
for (int i=0; i<membersToAdd.length; i++)
{
if (membersToAdd[i] != null)
{
try
{
DatastoreClass datastoreClass = getStoreManager().getDatastoreClass(membersToAdd[i].getType().getName(),clr);
if (datastoreClass.getIdMapping() == null)
{
throw new NucleusException("Unsupported relationship with field "+membersToAdd[i].getFullFieldName()).setFatal();
}
}
catch (NoTableManagedException ex)
{
//do nothing