* @throws PException
*/
private void initSequence(Object sequence) throws PException {
if (sequence instanceof SpeedoSequence) {
try {
SpeedoSequence s = (SpeedoSequence) sequence;
//if the sequence is not a rdb sequence, use jf_longGen table
if (s.datastoreName == null || s.datastoreName.equals("")) {
if (longGenMgr == null) {
//try to find the long gen manager in the registry
synchronized (LongGenMgrRegistry.class) {
longGenMgr = LongGenMgrRegistry.getLongGenMgr(mapper);
if (longGenMgr == null) {
//if not already registered, create it
try {
longGenMgr = (LongGenMgr) Class.forName(getLongGenMgrName()).newInstance();
} catch (Exception e) {
throw new PException(e, "Cannot create LongGenMgr (probably a ClassLoader problem): " + getLongGenMgrName());
}
((LongGenMgr) longGenMgr).init(mapper, PClassMapping.CREATE_STRUCTURE_IF_NEEDED);
// and register it
LongGenMgrRegistry.registerLonGenMgr((LongGenMgr)longGenMgr);
}
}
}
//create the long gen and associate it to the sequence
s.setLongGen(((LongGenMgr) longGenMgr).getLongGen(s.getName()));
} else {
//else, use rdb_sequence_long_gen
if (mapperRdb != null) {
if (s.getLongGen() == null) {
RdbSequenceLongGen rdbLongGen = new RdbSequenceLongGen(mapperRdb, s.datastoreName, false);
if(s.start != null) {
rdbLongGen.setSequenceStart(s.start);
}
if(s.increment != null) {
rdbLongGen.setSequenceIncrement(s.increment);
}
if(s.cache != null) {
rdbLongGen.setSequenceStart(s.cache);
}
//create it
Object conn = mapperRdb.getConnection();
rdbLongGen.createSequence(conn);
//and associate it to the sequence
s.setLongGen(rdbLongGen);
//close the connection
mapperRdb.closeConnection(conn);
}
} else {
throw new PException("Problem while init the sequence "