public Object getStrategyValue(ExecutionContext ec, AbstractClassMetaData cmd, int absoluteFieldNumber)
{
// Extract the control information for this field that needs its value
AbstractMemberMetaData mmd = null;
String fieldName = null;
IdentityStrategy strategy = null;
String sequence = null;
String valueGeneratorName = null;
TableGeneratorMetaData tableGeneratorMetaData = null;
SequenceMetaData sequenceMetaData = null;
if (absoluteFieldNumber >= 0)
{
// real field
mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(absoluteFieldNumber);
fieldName = mmd.getFullFieldName();
strategy = mmd.getValueStrategy();
sequence = mmd.getSequence();
valueGeneratorName = mmd.getValueGeneratorName();
}
else
{
// datastore-identity surrogate field
fieldName = cmd.getFullClassName() + " (datastore id)";
strategy = cmd.getIdentityMetaData().getValueStrategy();
sequence = cmd.getIdentityMetaData().getSequence();
valueGeneratorName = cmd.getIdentityMetaData().getValueGeneratorName();
}
// Extract any metadata-based generation information
if (valueGeneratorName != null)
{
if (strategy == IdentityStrategy.INCREMENT)
{
tableGeneratorMetaData = getMetaDataManager().getMetaDataForTableGenerator(ec.getClassLoaderResolver(),
valueGeneratorName);
if (tableGeneratorMetaData == null)
{
throw new NucleusUserException(LOCALISER.msg("038005", fieldName, valueGeneratorName));
}
}
else if (strategy == IdentityStrategy.SEQUENCE)
{
sequenceMetaData = getMetaDataManager().getMetaDataForSequence(ec.getClassLoaderResolver(),
valueGeneratorName);
if (sequenceMetaData == null)
{
throw new NucleusUserException(LOCALISER.msg("038006", fieldName, valueGeneratorName));
}
}
}
else if (strategy == IdentityStrategy.SEQUENCE && sequence != null)
{
// TODO Allow for package name of this class prefix for the sequence name
sequenceMetaData = getMetaDataManager().getMetaDataForSequence(ec.getClassLoaderResolver(), sequence);
if (sequenceMetaData == null)
{
// JPOX 1.1 behaviour was just to use the sequence name in the datastore so log it and fallback to that
NucleusLogger.VALUEGENERATION.warn("Field " + fieldName + " has been specified to use sequence " + sequence +
" but there is no <sequence> specified in the MetaData. " +
"Falling back to use a sequence in the datastore with this name directly.");
}
}
String strategyName = strategy.toString();
if (strategy.equals(IdentityStrategy.CUSTOM))
{
// Using a "custom" generator
strategyName = strategy.getCustomName();
}
else if (strategy.equals(IdentityStrategy.NATIVE))
{
strategyName = getStrategyForNative(cmd, absoluteFieldNumber);
}
// Value Generators are cached against a name. Some Value Generators are unique per datastore.