if (!in_same_tree)
{
String error_msg = LOCALISER_RDBMS.msg("050021", cmd.getFullClassName(),
cmd.getObjectidClass(), sample_class_in_other_tree);
NucleusLogger.DATASTORE.error(error_msg);
throw new NucleusUserException(error_msg);
}
}
}
}
if (cmd.isEmbeddedOnly())
{
// Nothing to do. Only persisted as SCO.
NucleusLogger.DATASTORE.info(LOCALISER.msg("032012", cmd.getFullClassName()));
}
else
{
InheritanceMetaData imd = cmd.getInheritanceMetaData();
RDBMSStoreData sdNew = null;
if (imd.getStrategy() == InheritanceStrategy.SUBCLASS_TABLE)
{
// Table mapped into the table(s) of subclass(es)
// Just add the SchemaData entry with no table - managed by subclass
sdNew = new RDBMSStoreData(cmd, null, false);
registerStoreData(sdNew);
}
else if (imd.getStrategy() == InheritanceStrategy.COMPLETE_TABLE &&
cmd.isAbstract())
{
// Abstract class with "complete-table" so gets no table
sdNew = new RDBMSStoreData(cmd, null, false);
registerStoreData(sdNew);
}
else if (imd.getStrategy() == InheritanceStrategy.NEW_TABLE ||
imd.getStrategy() == InheritanceStrategy.COMPLETE_TABLE)
{
// Table managed by this class
// Generate an identifier for the table required
DatastoreIdentifier tableName = null;
RDBMSStoreData tmpData = (RDBMSStoreData) storeDataMgr.get(cmd.getFullClassName());
if (tmpData !=null && tmpData.getDatastoreIdentifier() != null)
{
tableName = tmpData.getDatastoreIdentifier();
}
else
{
tableName = identifierFactory.newDatastoreContainerIdentifier(cmd);
}
// Check that the required table isn't already in use
StoreData[] existingStoreData = getStoreDataForDatastoreContainerObject(tableName);
if (existingStoreData != null)
{
String existingClass = null;
for (int j=0;j<existingStoreData.length;j++)
{
if (!existingStoreData[j].getName().equals(cmd.getFullClassName()))
{
existingClass = existingStoreData[j].getName();
break;
}
}
// Give a warning and then create a new instance of the table (mapped to the same datastore object)
if (existingClass != null)
{
String msg = LOCALISER_RDBMS.msg("050015", cmd.getFullClassName(),
tableName.getIdentifierName(), existingClass);
NucleusLogger.DATASTORE.warn(msg);
}
}
// Create the table to use for this class
DatastoreClass t = null;
boolean hasViewDef = false;
if (dba.getVendorID() != null)
{
hasViewDef = cmd.hasExtension("view-definition" + '-' + dba.getVendorID());
}
if (!hasViewDef)
{
hasViewDef = cmd.hasExtension("view-definition");
}
if (hasViewDef)
{
t = new ClassView(tableName, RDBMSStoreManager.this, cmd);
}
else
{
t = new ClassTable(tableName, RDBMSStoreManager.this, cmd);
}
sdNew = new RDBMSStoreData(cmd, t, true);
registerStoreData(sdNew);
// must be initialized after registering, to avoid StackOverflowError
((Table) t).preInitialize(clr);
}
else if (imd.getStrategy() == InheritanceStrategy.SUPERCLASS_TABLE)
{
// Table mapped into table of superclass
// Find the superclass - should have been created first
AbstractClassMetaData[] managingCmds = getClassesManagingTableForClass(cmd, clr);
DatastoreContainerObject superTable = null;
if (managingCmds != null && managingCmds.length == 1)
{
RDBMSStoreData superData = (RDBMSStoreData) storeDataMgr.get(managingCmds[0].getFullClassName());
if (superData != null)
{
// Specify the table if it already exists
superTable = superData.getDatastoreContainerObject();
}
sdNew = new RDBMSStoreData(cmd, superTable, false);
registerStoreData(sdNew);
}
else
{
String msg = LOCALISER_RDBMS.msg("050013", cmd.getFullClassName());
NucleusLogger.PERSISTENCE.error(msg);
throw new NucleusUserException(msg);
}
}
schemaDataAdded.add(sdNew);
}
}