jiuyue - 2002-11-21

for some days i have done some test Using JLF.
I find that :

Such as the code
I want to write two dmo (firstObj and secondObj) into the same dataMapper.
just like this:

FirstObj firstObj = new firstObj();
firstObj.write(dataMapper);

SecondObj secondObj = new SecondObj();
secondObj.write(dataMapper);
dataMapper.commitWrites();

If the exception occours at the Second dmo bing constructed. not "dataMapper.commitWrites();"
the sequence of events is:

FirstObj firstObj = new firstObj();
firstObj.write(dataMapper);
dataMapper.close()

just the above three lines, the dataMapper should not been commited.
But my result is : the dmo -- firstObj has been written into the database! why?

-----------------------------------------------
In order to resolve the question:
I have added some code in the JLF sources. just as :

DataMapper.java
      public abstract void rollbackWrites();
CRUDDataMapper.java
    public void rollbackWrites()
    {
      postCommitUpdateObjects.removeAllElements();
    }
JDBCDataMapper.java
    public void rollbackWrites()
    {
        try
        {
            connection.rollback();
            super.rollbackWrites();
        }
        catch (SQLException e)
        {
            throw new DataMapError("Unable to rollback transaction!", e, Log.ERROR_LEVEL);
        }
    }

So in my project , i can write in the catch block like this
try {
    flow = new Flow(flowId,name);
    dataMapper = flow.getDefaultDataMapper();
    flow.write(dataMapper);
   
    FlowArg newFlowArg = new FlowArg(argType,argLength);
    newFlowArg.write(dataMapper);
    dataMapper.commitWrites();
    return true;
} catch (Exception err) {
    dataMapper.rollbackWrites();    //here is the mothod i have added!
    return false;
}
finally {
    if (dataMapper != null) dataMapper.close();
}