Fixed Bug [ 1675206 ] Error when I try Merge Entity

https://sourceforge.net/tracker/index.php?func=detail&aid=1675206&group_id=176962&atid=879332
This commit is contained in:
vpj-cd 2007-03-08 18:33:03 +00:00
parent b82949d28a
commit 2d2f54e552
1 changed files with 36 additions and 54 deletions

View File

@ -45,7 +45,8 @@ public class VMerge extends CPanel
/** Error Log */ /** Error Log */
private StringBuffer m_errorLog = new StringBuffer(); private StringBuffer m_errorLog = new StringBuffer();
/** Connection */ /** Connection */
private Connection m_con = null; //private Connection m_con = null;
private Trx m_trx = null;
/** Logger */ /** Logger */
private static CLogger log = CLogger.getCLogger(VMerge.class); private static CLogger log = CLogger.getCLogger(VMerge.class);
@ -307,13 +308,13 @@ public class VMerge extends CPanel
+ ") " + ") "
+ "ORDER BY t.LoadSeq DESC"; + "ORDER BY t.LoadSeq DESC";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
Savepoint sp = null;
try try
{ {
m_con = DB.createConnection(false, Connection.TRANSACTION_READ_COMMITTED);
sp = m_con.setSavepoint("merge"); m_trx = Trx.get(Trx.createTrxName("merge"), true);
// //
pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, m_trx.createTrxName());
pstmt.setString(1, ColumnName); pstmt.setString(1, ColumnName);
pstmt.setString(2, ColumnName); pstmt.setString(2, ColumnName);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
@ -339,34 +340,29 @@ public class VMerge extends CPanel
if (success) if (success)
{ {
sql = "DELETE " + TableName + " WHERE " + ColumnName + "=" + from_ID; sql = "DELETE " + TableName + " WHERE " + ColumnName + "=" + from_ID;
Statement stmt = m_con.createStatement();
int count = 0;
try
{
count = stmt.executeUpdate (sql); if ( DB.executeUpdate(sql, m_trx.getTrxName()) < 0 )
if (count != 1)
{
m_errorLog.append(Env.NL).append("DELETE ").append(TableName)
.append(" - Count=").append(count);
success = false;
}
}
catch (SQLException ex1)
{ {
m_errorLog.append(Env.NL).append("DELETE ").append(TableName) m_errorLog.append(Env.NL).append("DELETE ").append(TableName)
.append(" - ").append(ex1.toString()); .append(" - ");
success = false; success = false;
log.config(m_errorLog.toString());
m_trx.rollback();
return false;
} }
stmt.close();
stmt = null;
} }
// //
if (success) if (success)
m_con.commit(); m_trx.commit();
else else
m_con.rollback(sp); m_trx.rollback();
m_con.close();
m_con = null; m_trx.close();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -377,15 +373,12 @@ public class VMerge extends CPanel
{ {
if (pstmt != null) if (pstmt != null)
pstmt.close(); pstmt.close();
if (m_con != null)
m_con.close();
} }
catch (Exception ex) catch (Exception ex)
{ {
} }
pstmt = null; pstmt = null;
m_con = null;
//
return success; return success;
} // merge } // merge
@ -414,36 +407,25 @@ public class VMerge extends CPanel
} }
} }
int count = -1; int count = DB.executeUpdate(sql, m_trx.getTrxName());
try
{ if ( count < 0 )
Statement stmt = m_con.createStatement ();
try
{
count = stmt.executeUpdate (sql);
log.fine(count
+ (delete ? " -Delete- " : " -Update- ") + TableName);
}
catch (SQLException ex1)
{
count = -1;
m_errorLog.append(Env.NL)
.append(delete ? "DELETE " : "UPDATE ")
.append(TableName).append(" - ").append(ex1.toString())
.append(" - ").append(sql);
}
stmt.close();
stmt = null;
}
catch (SQLException ex)
{ {
count = -1; count = -1;
m_errorLog.append(Env.NL) m_errorLog.append(Env.NL)
.append(delete ? "DELETE " : "UPDATE ") .append(delete ? "DELETE " : "UPDATE ")
.append(TableName).append(" - ").append(ex.toString()) .append(TableName).append(" - ")
.append(" - ").append(sql); .append(" - ").append(sql);
log.config(m_errorLog.toString());
m_trx.rollback();
} }
log.fine(count
+ (delete ? " -Delete- " : " -Update- ") + TableName);
return count; return count;
} // mergeTable } // mergeTable