[ 1755175 ] ad_changelog should capture insert too

[ 1755177 ] ad_changelog should have an 'action' field
This commit is contained in:
Carlos Ruiz 2008-02-03 02:23:21 +00:00
parent b2865c6d2f
commit 0a15b4a374
3 changed files with 68 additions and 9 deletions

View File

@ -121,6 +121,21 @@ public class MChangeLog extends X_AD_ChangeLog
super (ctx, 0, trxName);
} // MChangeLog
/**
* Preserved for backward compatibility
*@deprecated
*/
public MChangeLog (Properties ctx,
int AD_ChangeLog_ID, String TrxName, int AD_Session_ID,
int AD_Table_ID, int AD_Column_ID, int Record_ID,
int AD_Client_ID, int AD_Org_ID,
Object OldValue, Object NewValue)
{
this(ctx, AD_ChangeLog_ID, TrxName, AD_Session_ID, AD_Table_ID,
AD_Column_ID, Record_ID, AD_Client_ID, AD_Org_ID, OldValue,
NewValue, (String) null /*event*/ );
} // MChangeLog
/**
* Full Constructor
* @param ctx context
@ -139,7 +154,7 @@ public class MChangeLog extends X_AD_ChangeLog
int AD_ChangeLog_ID, String TrxName, int AD_Session_ID,
int AD_Table_ID, int AD_Column_ID, int Record_ID,
int AD_Client_ID, int AD_Org_ID,
Object OldValue, Object NewValue)
Object OldValue, Object NewValue, String event)
{
this (ctx, 0, TrxName);
if (AD_ChangeLog_ID == 0)
@ -160,7 +175,11 @@ public class MChangeLog extends X_AD_ChangeLog
//
setOldValue (OldValue);
setNewValue (NewValue);
// R2.5.2f_2005-09-25 2.5.2f_20050925-2201
// EVENT / Release 3.3.1t_2007-12-05 ADempiere
if (event != null)
setDescription(event + " / " + Adempiere.MAIN_VERSION + "_"
+ Adempiere.DATE_VERSION + " " + Adempiere.getImplementationVersion());
else
setDescription(Adempiere.MAIN_VERSION + "_"
+ Adempiere.DATE_VERSION + " " + Adempiere.getImplementationVersion());
} // MChangeLog

View File

@ -215,6 +215,20 @@ public class MSession extends X_AD_Session
log.info(TimeUtil.formatElapsed(getCreated(), getUpdated()));
} // logout
/**
* Preserved for backward compatibility
*@deprecated
*/
public MChangeLog changeLog (
String TrxName, int AD_ChangeLog_ID,
int AD_Table_ID, int AD_Column_ID, int Record_ID,
int AD_Client_ID, int AD_Org_ID,
Object OldValue, Object NewValue)
{
return changeLog(TrxName, AD_ChangeLog_ID, AD_Table_ID, AD_Column_ID,
Record_ID, AD_Client_ID, AD_Org_ID, OldValue, NewValue,
(String) null);
} // changeLog
/**
* Create Change Log only if table is logged
@ -233,7 +247,7 @@ public class MSession extends X_AD_Session
String TrxName, int AD_ChangeLog_ID,
int AD_Table_ID, int AD_Column_ID, int Record_ID,
int AD_Client_ID, int AD_Org_ID,
Object OldValue, Object NewValue)
Object OldValue, Object NewValue, String event)
{
// Null handling
if (OldValue == null && NewValue == null)
@ -268,7 +282,7 @@ public class MSession extends X_AD_Session
MChangeLog cl = new MChangeLog(getCtx(),
AD_ChangeLog_ID, TrxName, getAD_Session_ID(),
AD_Table_ID, AD_Column_ID, Record_ID, AD_Client_ID, AD_Org_ID,
OldValue, NewValue);
OldValue, NewValue, event);
if (cl.save())
return cl;
}

View File

@ -2165,11 +2165,11 @@ public abstract class PO
oldV = null;
if (newV != null && newV == Null.NULL)
newV = null;
//
// change log on update
MChangeLog cLog = session.changeLog (
m_trxName, AD_ChangeLog_ID,
p_info.getAD_Table_ID(), p_info.getColumn(i).AD_Column_ID,
get_ID(), getAD_Client_ID(), getAD_Org_ID(), oldV, newV);
get_ID(), getAD_Client_ID(), getAD_Org_ID(), oldV, newV, "UPDATE");
if (cLog != null)
AD_ChangeLog_ID = cLog.getAD_ChangeLog_ID();
}
@ -2297,6 +2297,12 @@ public abstract class PO
lobReset();
// Change Log
MSession session = MSession.get (p_ctx, false);
if (session == null)
log.fine("No Session found");
int AD_ChangeLog_ID = 0;
// SQL
StringBuffer sqlInsert = new StringBuffer("INSERT INTO ");
sqlInsert.append(p_info.getTableName()).append(" (");
@ -2368,6 +2374,25 @@ public abstract class PO
log.log(Level.SEVERE, msg, e);
throw new DBException(e); // fini
}
// Change Log - Only
if (session != null
&& m_IDs.length == 1
&& !p_info.isEncrypted(i) // not encrypted
&& !p_info.isVirtualColumn(i) // no virtual column
&& !"Password".equals(columnName)
&& p_info.getColumn(i).IsKey // log just the key - to log all columns comment this line
)
{
// change log on new
MChangeLog cLog = session.changeLog (
m_trxName, AD_ChangeLog_ID,
p_info.getAD_Table_ID(), p_info.getColumn(i).AD_Column_ID,
get_ID(), getAD_Client_ID(), getAD_Org_ID(), null, value, "INSERT");
if (cLog != null)
AD_ChangeLog_ID = cLog.getAD_ChangeLog_ID();
}
}
// Custom Columns
if (m_custom != null)
@ -2625,10 +2650,11 @@ public abstract class PO
&& !"Password".equals(p_info.getColumnName(i))
)
{
// change log on delete
MChangeLog cLog = session.changeLog (
m_trxName != null ? m_trxName : localTrxName, AD_ChangeLog_ID,
AD_Table_ID, p_info.getColumn(i).AD_Column_ID,
Record_ID, getAD_Client_ID(), getAD_Org_ID(), value, null);
Record_ID, getAD_Client_ID(), getAD_Org_ID(), value, null, "DELETE");
if (cLog != null)
AD_ChangeLog_ID = cLog.getAD_ChangeLog_ID();
}