// Add the fields for this class (and any other superclasses that we need to manage the
// fields for (inheritance-strategy="subclass-table" in the superclass)
initializeForClass(cmd, clr);
MappingManager mapMgr = storeMgr.getMappingManager();
// Add Version where specified in MetaData
// TODO If there is a superclass table that has a version we should omit from here even if in MetaData
// See "getTableWithDiscriminator()" for the logic
versionMetaData = cmd.getVersionMetaDataForTable();
if (versionMetaData != null && versionMetaData.getFieldName() == null)
{
if (versionMetaData.getVersionStrategy() == VersionStrategy.NONE)
{
// No optimistic locking but the idiot wants a column for that :-)
versionMapping = new VersionLongMapping(dba, this, mapMgr.getMapping(Long.class));
}
else if (versionMetaData.getVersionStrategy() == VersionStrategy.VERSION_NUMBER)
{
versionMapping = new VersionLongMapping(dba, this, mapMgr.getMapping(Long.class));
}
else if (versionMetaData.getVersionStrategy() == VersionStrategy.DATE_TIME)
{
if (!dba.supportsOption(RDBMSAdapter.DATETIME_STORES_MILLISECS))
{
// TODO Localise this
throw new NucleusException("Class " + cmd.getFullClassName() + " is defined " +
"to use date-time versioning, yet this datastore doesnt support storing " +
"milliseconds in DATETIME/TIMESTAMP columns. Use version-number");
}
versionMapping = new VersionTimestampMapping(dba, this, mapMgr.getMapping(Timestamp.class));
}
}
// Add Discriminator where specified in MetaData
DiscriminatorMetaData dismd = cmd.getDiscriminatorMetaDataForTable();
if (dismd != null)
{
discriminatorMetaData = dismd;
if (storeMgr.getBooleanProperty("datanucleus.rdbms.discriminatorPerSubclassTable"))
{
// Backwards compatibility only. Creates discriminator in all subclass tables even though not needed
// TODO Remove this in the future
if (dismd.getStrategy() == DiscriminatorStrategy.CLASS_NAME)
{
discriminatorMapping = new DiscriminatorStringMapping(dba, this,
mapMgr.getMapping(String.class));
}
else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP)
{
ColumnMetaData disColmd = dismd.getColumnMetaData();
if (disColmd != null && disColmd.getJdbcType() != null)
{
if (disColmd.getJdbcType().equalsIgnoreCase("INTEGER") ||
disColmd.getJdbcType().equalsIgnoreCase("BIGINT") ||
disColmd.getJdbcType().equalsIgnoreCase("NUMERIC"))
{
discriminatorMapping = new DiscriminatorLongMapping(dba, this,
mapMgr.getMapping(Long.class));
}
else
{
discriminatorMapping = new DiscriminatorStringMapping(dba, this,
mapMgr.getMapping(String.class));
}
}
else
{
discriminatorMapping = new DiscriminatorStringMapping(dba, this,
mapMgr.getMapping(String.class));
}
}
}
else
{
// Create discriminator column only in top most table that needs it
ClassTable tableWithDiscrim = getTableWithDiscriminator();
if (tableWithDiscrim == this)
{
// No superclass with a discriminator so add it in this table
if (dismd.getStrategy() == DiscriminatorStrategy.CLASS_NAME)
{
discriminatorMapping = new DiscriminatorStringMapping(dba, this,
mapMgr.getMapping(String.class));
}
else if (dismd.getStrategy() == DiscriminatorStrategy.VALUE_MAP)
{
ColumnMetaData disColmd = dismd.getColumnMetaData();
if (disColmd != null && disColmd.getJdbcType() != null)
{
if (disColmd.getJdbcType().equalsIgnoreCase("INTEGER") ||
disColmd.getJdbcType().equalsIgnoreCase("BIGINT") ||
disColmd.getJdbcType().equalsIgnoreCase("NUMERIC"))
{
discriminatorMapping = new DiscriminatorLongMapping(dba, this,
mapMgr.getMapping(Long.class));
}
else
{
discriminatorMapping = new DiscriminatorStringMapping(dba, this,
mapMgr.getMapping(String.class));
}
}
else
{
discriminatorMapping = new DiscriminatorStringMapping(dba, this,
mapMgr.getMapping(String.class));
}
}
}
}
}