This method has some issues I failed to understand, such as it doesn't rollback the changes made in previous procedure call if any of the procedure calls down the hierarchy throws an exception.... Please help me out
public synchronized boolean save(DTO dto) throws DAOException,IllegalArgumentException
{ boolean retVal=false;
boolean retVal1=false;
boolean retVal2=false;
boolean retVal5=true;
try{
connection=dataSource.getConnection();
connection.setAutoCommit(false);
cstmt=connection.prepareCall("{call PKG_ALL.PROC_MAIN(?,?,?)}");
cstmt.setString(1, "A"); cstmt.setString(2, "B");
cstmt.registerOutParameter(3,Types.VARCHAR);
ResultSet rs=cstmt.executeQuery();
String ErrMsg=cstmt.getString(3);
if(ErrMsg.equalsIgnoreCase("Record Inserted")) retVal=true;
else retVal=false;
cstmt.close();
cstmt1=connection.prepareCall("{call PKG_ALL.PROC_CHILD1(?,?,?)}");
cstmt1.setString(1, "A"); cstmt1.setString(2, "B");
cstmt1.registerOutParameter(3,Types.VARCHAR);
ResultSet rs1=cstmt.executeQuery();
String ErrMsg1=cstmt1.getString(3);
if(ErrMsg1.equalsIgnoreCase("Record Inserted")) retVal1=true;
else retVal1=false;
cstmt1.close();
if(strSerialNo!=null && strSerialNo.length > 0) // for a non-mandatory multirow in the form
{
cstmt2=connection.prepareCall("{call PKG_ALL.PROC_CHILD2(?,?,?)}");
for(int k=0;k<strSerialNo.length;k++)
{
cstmt2.setString(1,"M");
cstmt2.setString(2,"I");
cstmt2.registerOutParameter(3,Types.VARCHAR);
ResultSet rs2=cstmt2.executeQuery();
String ErrMsg2=cstmt2.getString(3);
if(ErrMsg2.equalsIgnoreCase("Record Inserted")) retVal2=true;
else
{
retVal5=false;
retVal2=false;
}
}
cstmt2.close();
}
**if(retVal&&retVal1&&retVal5)**
{
retVal=true;
connection.commit();
}
else
{
//connection.rollback();
retVal=false;
}
}
catch(SQLException e)
{
throw new DAOException(":"+e.getMessage());
}
catch(Exception e)
{
throw new DAOException(":"+e.getMessage());
}
finally
{
closeConnection(connection);
}
return retVal;
}