최대 절전 모드를 사용하는 경우, 인터셉터를 시작할 수 있습니다. 당신은 당신의 목적을 위해 아래의 메소드를 오버라이드 할 수 있습니다.
추출 된 메소드는 시나리오에 필요한 인터셉터 인터페이스에 속합니다.
/**
* 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를 사용하고 있습니다. 이 자바 코드 만 개발할 수 있습니다. 트리거를 사용할 수 없습니다. 내가 한 첫 걸음. Apache 라이브러리를 통해 두 객체 (old, new)의 차이점을 비교하십시오. 이제는 테이블 이름과 컬럼 이름을 등록하는 방법을 알아야합니다. – Anderson