assertIsOpen();
SequenceMetaData seqmd = objectMgr.getMetaDataManager().getMetaDataForSequence(objectMgr.getClassLoaderResolver(),sequenceName);
if (seqmd == null)
{
throw new JDOUserException(LOCALISER.msg("017000", sequenceName));
}
Sequence seq = null;
if (seqmd.getFactoryClass() != null)
{
// User has specified a factory class
seq = getAbstractPersistenceManagerFactory().getSequenceForFactoryClass(seqmd.getFactoryClass());
if (seq == null)
{
// Create a new instance of the factory class and obtain the Sequence
Class factory = objectMgr.getClassLoaderResolver().classForName(seqmd.getFactoryClass());
if (factory == null)
{
throw new JDOUserException(LOCALISER.msg("017001", sequenceName, seqmd.getFactoryClass()));
}
Class[] argTypes = null;
Object[] arguments = null;
if (seqmd.getStrategy() != null)
{
argTypes = new Class[2];
argTypes[0] = String.class;
argTypes[1] = String.class;
arguments = new Object[2];
arguments[0] = seqmd.getName();
arguments[1] = seqmd.getStrategy().toString();
}
else
{
argTypes = new Class[1];
argTypes[0] = String.class;
arguments = new Object[1];
arguments[0] = seqmd.getName();
}
Method newInstanceMethod;
try
{
// Obtain the sequence from the static "newInstance(...)" method
newInstanceMethod = factory.getMethod("newInstance", argTypes);
seq = (Sequence) newInstanceMethod.invoke(null, arguments);
}
catch (Exception e)
{
throw new JDOUserException(LOCALISER.msg("017002", seqmd.getFactoryClass(), e.getMessage()));
}
// Register the sequence with the PMF
getAbstractPersistenceManagerFactory().addSequenceForFactoryClass(seqmd.getFactoryClass(), seq);
}