}
}
props.put("sequence-name", seqMetaData.getDatastoreSequence());
// Get a ValueGenerationManager to create the generator
ValueGenerationManager mgr = storeManager.getValueGenerationManager();
ValueGenerationConnectionProvider connProvider = new ValueGenerationConnectionProvider()
{
ManagedConnection mconn;
public ManagedConnection retrieveConnection()
{
// Obtain a new connection
// Note : it may be worthwhile to use the PM's connection here however where a Sequence doesnt yet
// exist the connection would then be effectively dead until the end of the tx
// The way around this would be to find a way of checking for existence of the sequence
PersistenceConfiguration conf = ec.getNucleusContext().getPersistenceConfiguration();
int isolationLevel = TransactionUtils.getTransactionIsolationLevelForName(
conf.getStringProperty("datanucleus.valuegeneration.transactionIsolation"));
this.mconn = ((RDBMSStoreManager)storeManager).getConnection(isolationLevel);
return mconn;
}
public void releaseConnection()
{
try
{
// Release the connection
mconn.close();
}
catch (NucleusException e)
{
NucleusLogger.PERSISTENCE.error(LOCALISER.msg("017007", e));
throw e;
}
}
};
Class cls = null;
ConfigurationElement elem =
ec.getNucleusContext().getPluginManager().getConfigurationElementForExtension(
"org.datanucleus.store_valuegenerator",
new String[]{"name", "datastore"},
new String[] {valueGeneratorName, storeManager.getStoreManagerKey()});
if (elem != null)
{
cls = ec.getNucleusContext().getPluginManager().loadClass(
elem.getExtension().getPlugin().getSymbolicName(), elem.getAttribute("class-name"));
}
if (cls == null)
{
throw new NucleusException("Cannot create ValueGenerator for strategy "+valueGeneratorName);
}
generator = mgr.createValueGenerator(seqMetaData.getName(), cls, props, storeManager, connProvider);
if (NucleusLogger.PERSISTENCE.isDebugEnabled())
{
NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("017003", seqMetaData.getName(), valueGeneratorName));
}