Hibernateを使用している場合は、Interceptorから始めることができます。あなた自身の目的のために、以下のメソッドをオーバーライドすることができます。
抽出されたメソッドは、シナリオに必要なインターセプタインターフェイスに属します。
/**
* Called just before an object is initialized. The interceptor may change the <tt>state</tt>, which will
* be propagated to the persistent object. Note that when this method is called, <tt>entity</tt> will be
* an empty uninitialized instance of the class.
*
* @return <tt>true</tt> if the user modified the <tt>state</tt> in any way.
*/
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException;
/**
* Called when an object is detected to be dirty, during a flush. The interceptor may modify the detected
* <tt>currentState</tt>, which will be propagated to both the database and the persistent object.
* Note that not all flushes end in actual synchronization with the database, in which case the
* new <tt>currentState</tt> will be propagated to the object, but not necessarily (immediately) to
* the database. It is strongly recommended that the interceptor <b>not</b> modify the <tt>previousState</tt>.
*
* @return <tt>true</tt> if the user modified the <tt>currentState</tt> in any way.
*/
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException;
/**
* Called before an object is saved. The interceptor may modify the <tt>state</tt>, which will be used for
* the SQL <tt>INSERT</tt> and propagated to the persistent object.
*
* @return <tt>true</tt> if the user modified the <tt>state</tt> in any way.
*/
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException;
/**
* Called before an object is deleted. It is not recommended that the interceptor modify the <tt>state</tt>.
*/
public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException;
/**
* Called before a flush
*/
public void preFlush(Iterator entities) throws CallbackException;
/**
* Called after a flush that actually ends in execution of the SQL statements required to synchronize
* in-memory state with the database.
*/
public void postFlush(Iterator entities) throws CallbackException;
JDBCを経由する必要がありますか?データベーストリガーはオプションですか?つまり、コード(または他のクライアント)がUPDATEを実行し、データベース・トリガーが変更を記録します。 –
どのDBMSを使用していますか? Oracle(Enterprise Edition)またはDB2は完全に自動的にそれを行うことができます。 Postgresでは、この情報を別のテーブルに書き込む監査トリガを簡単に作成できます。 –
私はOracle 11gを使用しています。私はこの唯一のJavaコードを開発することができます。私はトリガーを使用することはできません。私がやった最初のステップ。 2つのオブジェクト(古いもの、新しいもの)の違いをApacheライブラリで比較する。今私はテーブルの名前と列の名前を登録する方法を発見する必要があります。 – Anderson