|
Hibernate example source code file (StatefulInterceptor.java)
The Hibernate StatefulInterceptor.java source code//$Id: StatefulInterceptor.java 7701 2005-07-30 05:07:01Z oneovthafew $
package org.hibernate.test.interceptor;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Session;
import org.hibernate.type.Type;
public class StatefulInterceptor extends EmptyInterceptor {
private Session session;
private List list = new ArrayList();
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
if ( !(entity instanceof Log) ) {
list.add( new Log( "insert", (String) id, entity.getClass().getName() ) );
}
return false;
}
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
if ( !(entity instanceof Log) ) {
list.add( new Log( "update", (String) id, entity.getClass().getName() ) );
}
return false;
}
public void postFlush(Iterator entities) {
if ( list.size()>0 ) {
for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
session.persist( iter.next() );
}
list.clear();
session.flush();
}
}
public void setSession(Session s) {
session = s;
}
}
Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate StatefulInterceptor.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.