* @ejb.interface-method view-type="local"
* @ejb.transaction type="RequiresNew"
*/
public ProcessDefinitionInfo lookupProcessDefinitionInfo
(String packageId, String processId) throws InvalidKeyException {
RequestScope scope = RequestLog.enterScope
(this, "lookupProcessDefinitionInfo",
new Object[] { packageId, processId });
ProcessDefinitionInfo processDefinitionInfo = null;
try {
Connection con = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
try {
String processType = packageId + "/" + processId;
con = ds.getConnection();
prepStmt = con.prepareStatement
("SELECT DBID, ENABLED, XPDLREF FROM PROCESSDEFINITION "
+ "WHERE PACKAGEID = ? AND PROCESSID = ?");
prepStmt.setString(1, packageId);
prepStmt.setString(2, processId);
rs = prepStmt.executeQuery();
if(!rs.next()) {
// cleanup cache as a side effect
uncacheDefinition (processType);
throw new InvalidKeyException
("No process with packageId/processId = "+ processType);
}
long dbid = rs.getLong(1);
boolean enabled = (rs.getString(2).charAt(0) == 'T');
Long xpdlRef = JDBCUtil.getLong(rs, 3);
synchronized (processDefinitionInfoCache) {
processDefinitionInfo = (ProcessDefinitionInfo)
processDefinitionInfoCache.get(new Long(dbid));
if (processDefinitionInfo != null) {
if (processDefinitionInfo.dbid != dbid) {
uncacheDefinition(processType);
processDefinitionInfo = null;
}
}
}
if (processDefinitionInfo != null) {
processDefinitionInfo.enabled = enabled;
if (logger.isDebugEnabled ()) {
logger.debug
("found (" + processDefinitionInfo
.processDefinition.packageId()
+ "/" + processDefinitionInfo
.processDefinition.processId() + ") "
+ "in cache");
}
return processDefinitionInfo;
}
rs.close();
rs = null;
prepStmt.close();
prepStmt = null;
String xpdl = null;
// For backward compatibility allow xpdlref to be null
if (xpdlRef != null) {
prepStmt = new UniversalPrepStmt
(con, "SELECT XPDL FROM XPDLARCHIVE WHERE DBID = ?");
prepStmt.setLong(1, xpdlRef.longValue());
rs = prepStmt.executeQuery();
if (rs.next()) {
xpdl = JDBCUtil.getString(ds, rs, 1);
}
} else {
prepStmt = new UniversalPrepStmt
(con, "SELECT XPDL FROM PROCESSDEFINITION "
+ "WHERE DBID = ?");
prepStmt.setLong(1, dbid);
rs = prepStmt.executeQuery();
if (rs.next()) {
xpdl = JDBCUtil.getString(ds, rs, 1);
}
}
processDefinitionInfo = new ProcessDefinitionInfo
(dbid, xpdlRef,
new DefaultProcessDefinition (xpdl), enabled);
cacheDefinition(processDefinitionInfo);
return processDefinitionInfo;
} finally {
JDBCUtil.closeAll (rs, prepStmt, con);
}
} catch (SQLException se) {
throw new EJBException(se);
} catch (IOException ioe) {
throw new EJBException(ioe);
} catch (ImportException pe) {
throw new EJBException(pe);
} finally {
scope.leave (processDefinitionInfo);
}
}