public Number insertStatus(Integer workingSetID, WorkflowStatus status)
      throws WorkflowManagerException {
    final Number id;

    final Row row = new Row();
    try {
      row.add(new CInteger("id", id = RowID.get(ec, WorkflowConstants.WORKFLOW_TABLE, "id")));
    } catch (DBException e) {
      throw new WorkflowManagerException(e);
    }
    row.add(new CString("status", status.toString()));
    row.add(new CString("workingsetid", workingSetID.toString()));

    final InsertQuery query = new InsertQuery();
    query.setTable(WorkflowConstants.WORKFLOW_TABLE);
    query.setRow(row);

    try {
      ec.doUpdate(query);
    } catch (DBException e) {
      throw new WorkflowManagerException(e);
    }

    return id;
  }
  @Override
  public void updateStatus(Number id, WorkflowStatus status) throws WorkflowManagerException {
    final Row row = new Row();
    row.add(new CString("status", status.toString()));

    final UpdateQuery query = new UpdateQuery();
    query.setTable(WorkflowConstants.WORKFLOW_TABLE);
    query.setRow(row);
    query.constrain(
        new CanonicalColumnName(WorkflowConstants.WORKFLOW_TABLE, "id"), QConstraint.CT_EQUALS, id);

    try {
      ec.doUpdate(query);
    } catch (DBException e) {
      throw new WorkflowManagerException(e);
    }
  }
  @Override
  public void process(final Row r) {
    try {
      // Row r = ri.getStructuredRow(getExecutionContext(), "bibliography");

      String hash = get(r, "Bib_hash");
      if ("".equals(hash)) hash = get(r, "Bib_Hash");
      String type = get(r, "Publication_Type");

      Map<String, String> refData = new HashMap<String, String>();

      for (final Column c : r.getColumns()) {
        String name = c.getLocalName();
        String value = c.toString();

        if (value != null) refData.put(name, value);
      }

      Reference reference = Reference.fromMap(refData);
      reference.setHash(hash);
      reference.setType(type);
      String key = reference.generateCitation();

      if (cache.containsKey(key)) {
        reference = cache.get(key);
      } else {
        // In DB?
        ReferenceCriteria criteria = new ReferenceCriteria(session);
        criteria.citation.eq(key);
        Reference[] existing = criteria.listReference();

        if (existing.length > 0) reference = existing[0];
        else { // New reference
          session.save(reference);
          cache.put(key, reference);
        }
      }
      references.add(reference);
    } catch (Exception dbx) {
      dbx.printStackTrace();
    }
  }
  @Override
  public void addComment(Number id, WorkflowComment comment) throws WorkflowManagerException {
    final Row row = new Row();
    try {
      row.add(new CInteger("id", RowID.get(ec, WorkflowConstants.WORKFLOW_NOTES_TABLE, "id")));
    } catch (DBException e) {
      throw new WorkflowManagerException(e);
    }
    row.add(new CInteger("workflowstatusid", id));
    row.add(new CString("scope", comment.getScope()));
    row.add(new CInteger("userid", comment.getUser().getID()));
    row.add(new CString("comment", comment.getComment()));
    row.add(new CDateTime("date", comment.getDate()));

    final InsertQuery query = new InsertQuery();
    query.setRow(row);
    query.setTable(WorkflowConstants.WORKFLOW_NOTES_TABLE);

    try {
      ec.doUpdate(query);
    } catch (DBException e) {
      throw new WorkflowManagerException(e);
    }
  }
  private String get(Row row, String column) {
    Column c = row.get(column);
    if (c == null) return "";

    return c.toString();
  }