ArrayList<WorkflowInstanceInfo> instances = new ArrayList<WorkflowInstanceInfo>();
java.sql.ResultSetMetaData rsmd = resultSet.getMetaData();
boolean exceptionIsClob = rsmd.getColumnType(8) == Types.CLOB;
while (resultSet.next()) {
WorkflowInstanceInfo workflowInstanceInfo = new WorkflowInstanceInfo();
workflowInstanceInfo.setId(resultSet.getString(1));
workflowInstanceInfo.setState(DBProcessingStateWorkaround.fromKey(resultSet.getInt(2)).asWorkflowInstanceState() );
workflowInstanceInfo.setPriority(resultSet.getInt(3));
workflowInstanceInfo.setLastActivityTimestamp(new Date(resultSet.getTimestamp(4).getTime()));
workflowInstanceInfo.setProcessorPoolId(resultSet.getString(5));
workflowInstanceInfo.setTimeout(resultSet.getTimestamp(6)!=null?new Date(resultSet.getTimestamp(6).getTime()):null);
workflowInstanceInfo.setStartTime(new Date(resultSet.getTimestamp(7).getTime()));
if (exceptionIsClob) {
Clob errorinfo = resultSet.getClob(8);
if (errorinfo!=null){
workflowInstanceInfo.setErrorInfos(errorinfo.getSubString(1, (int)errorinfo.length()));
}
} else {
workflowInstanceInfo.setErrorInfos(resultSet.getString(8));
}
workflowInstanceInfo.setLastErrorTime(resultSet.getTimestamp(9)!=null?new Date(resultSet.getTimestamp(9).getTime()):null);
Date lastMod = resultSet.getTimestamp(10)!=null?new Date(resultSet.getTimestamp(10).getTime()):null;
if (workflowInstanceInfo.getState() == WorkflowInstanceState.FINISHED){
workflowInstanceInfo.setFinishTime(lastMod);
}
workflowInstanceInfo.setOverallLifetimeInMs(System.currentTimeMillis()-workflowInstanceInfo.getStartTime().getTime());
workflowInstanceInfo.setClassname(resultSet.getString(11));
instances.add(workflowInstanceInfo);
}
resultSet.close();
return instances;