DatabaseManager.update(context, row);
    private static void createHarmonyData(Context context,                                          Object historyObj,                                          int flag,                                          EPerson theUser,                                          String theTool)        throws SQLException, RDFException, IOException    {        String id = (flag == REMOVE) ?            getUniqueId(historyObj) : doSerialize(context, historyObj);        // Figure out the tool used        if (theTool == null)            theTool = getTool();        String eventId = getUniqueId(getShortName(historyObj), flag);        // Previous state (as far as History is concerned). It's possible,        // of course, that changes were made without telling History!        String inputStateId = (flag == CREATE) ? null : findPreviousState(id);        // Create a model        Model model = new ModelMem();        // An id for the new state        Integer stateId = (flag == REMOVE) ? null :            new Integer(DatabaseManager.getID("HistoryState"));        // This is the object that we're making statements about....        Resource obj = model.createResource(id);        // This is the event        Resource event = model.createResource(eventId);        //  States        Resource outputState = (flag == REMOVE) ? null : model.createResource(stateId.toString());        Resource inputState = (flag == CREATE) ? null : model.createResource(inputStateId);        //  FIXME The action (also typed??)        Resource action = model.createResource(getUniqueId("action", NONE));        //  The user        Resource user = (theUser != null) ? model.createResource(getUniqueId(theUser)) : null;        // These verbs are essentially constant        Property atTime = model.createProperty(getHarmonyId("atTime"));        Property hasInput = model.createProperty(getHarmonyId("hasInput"));        Property hasOutput = model.createProperty(getHarmonyId("hasOutput"));        Property inState = model.createProperty(getHarmonyId("inState"));        //Property contains  = model.createProperty(getHarmonyId("contains"));        Property hasAction = model.createProperty(getHarmonyId("hasAction"));        Property usesTool = model.createProperty(getHarmonyId("usesTool"));        Property hasAgent = model.createProperty(getHarmonyId("hasAgent"));        Property operation = null;        // Choose the correct operation        if (flag == CREATE)            operation = model.createProperty(getHarmonyId("creates"));        else if (flag == REMOVE)            operation = model.createProperty(getHarmonyId("destroys"));        else if (flag == MODIFY)            operation = model.createProperty(getHarmonyId("transforms"));        else            throw new IllegalArgumentException("Unknown value for flag: " + flag);        // Creation events do not have input states, but everything        // else does        if (flag != CREATE)            model.add(event, hasInput, inputState);        // Removal events do not have output states, nor is the object        // in a state upon completion        if (flag != REMOVE)        {            model.add(event, hasOutput, outputState);            model.add(obj, inState, outputState);            //model.add(outputState,  contains,  obj);        }        // Time that this event occurred        model.add(event, atTime, (new java.util.Date().toString()));        model.add(action, operation, obj);        model.add(event, hasAction, action);        model.add(action, usesTool, theTool);        if (theUser != null)            model.add(action, hasAgent, user);        else            model.add(action, hasAgent, model.createLiteral("Unknown User"));        //  FIXME Strictly speaking, this is NOT a property of the        //  object itself, but of the resulting serialization!        Property generatorId = model.createProperty(uriPrefix + "/generator");        model.add(event, generatorId, ID);        List dbobjs = new LinkedList();        if (flag != REMOVE)        {            TableRow row = DatabaseManager.create(context, "HistoryState");            row.setColumn("history_state_id", stateId.intValue());            row.setColumn("object_id", id);        }        StringWriter swdata = new StringWriter();        model.write(swdata);        swdata.close();        String data = swdata.toString();        TableRow h = DatabaseManager.create(context, "History");        int hid = h.getIntColumn("history_id");        File file = forId(hid, true);        FileWriter fw = new FileWriter(file);        fw.write(data);        fw.close();        h.setColumn("creation_date", nowAsTimeStamp());        h.setColumn("checksum", Utils.getMD5(data));        DatabaseManager.update(context, h);    }