use of org.datanucleus.store.NucleusSequence in project datanucleus-api-jdo by datanucleus.
the class JDOPersistenceManager method getSequence.
// ------------------------------------- Sequence Management --------------------------------------
/**
* Method to retrieve a sequence by name. As per JDO2 spec section 12.14.
* If the named sequence is not known, throws a JDOUserException.
* @param sequenceName Fully qualified name of the sequence
* @return The sequence
*/
public Sequence getSequence(String sequenceName) {
assertIsOpen();
SequenceMetaData seqmd = ec.getMetaDataManager().getMetaDataForSequence(ec.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 = pmf.getSequenceForFactoryClass(seqmd.getFactoryClass());
if (seq == null) {
// Create a new instance of the factory class and obtain the Sequence
Class factory = ec.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
pmf.addSequenceForFactoryClass(seqmd.getFactoryClass(), seq);
}
} else {
NucleusSequence nucSeq = ec.getStoreManager().getNucleusSequence(ec, seqmd);
seq = new JDOSequence(nucSeq);
}
return seq;
}
Aggregations