Hibernate ORM EmptyInterceptor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM EmptyInterceptor class.

This code example shows how to use the following methods:
 */ 
public class SpringInterceptor extends EmptyInterceptor {
	private final SessionFactory sessionFactory;
	private final ApplicationContext beanRegistry;
 
	public SpringInterceptor(ApplicationContext beanRegistry, SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
		this.beanRegistry = beanRegistry;
	} 
 
	@Override 
	public Object instantiate(String entityName, EntityMode entityMode, Serializable id) {
		if (!EntityMode.POJO.equals(entityMode)) {
			return null; 
		} 
 
		Class<?> c = getClassByName(entityName);
		Object instance = this.beanRegistry.getBean(c);
		sessionFactory.getClassMetadata(c).setIdentifier(instance, id, EntityMode.POJO);
 
6
CodeRank
This code example shows how to use the following methods:
 * called last, if they make any changes other interceptors would never know about them. 
 * </pre> 
 *  
 * @since 1.10 
 */ 
public abstract class ImmutableEntityInterceptor extends EmptyInterceptor {
	 
	private static final Log log = LogFactory.getLog(ImmutableEntityInterceptor.class);
	 
	/** 
	 * Returns the class handled by the interceptor 
	 */ 
	protected abstract Class<?> getSupportedType();
	 
	/** 
	 * Subclasses can override this to return fields that are allowed to be edited, returning null 
	 * or an empty array implies the entity is immutable 
	 *  
	 * @return an array of properties 
	 */ 
6
CodeRank
This code example shows how to use the following methods:
 * recurse on lists of OpenmrsObjects. 
 * 
 * @since 1.9 
 */ 
 
public class AuditableInterceptor extends EmptyInterceptor {
	 
	private static final Log log = LogFactory.getLog(AuditableInterceptor.class);
	 
	private static final long serialVersionUID = 1L;
	 
	/** 
	 * This method is only called when inserting new objects. 
	 * @should return true if dateCreated was null 
	 * @should return true if creator was null 
	 * @should return false if dateCreated and creator was not null 
	 * @should be called when saving OpenmrsObject 
	 * @return true if the object got the dateCreated and creator fields set 
	 * @see org.hibernate.EmptyInterceptor#onSave(java.lang.Object, java.io.Serializable, 
	 *      java.lang.Object[], java.lang.String[], org.hibernate.type.Type[]) 
6
CodeRank
This code example shows how to use the following methods:
    private AuditLog auditLog;
    private InterceptHelper interceptHelper;
    private UserContext userContext;
    private Boolean flag = false;
 
    public AuditInterceptor() { 
        interceptHelper = new InterceptHelper();
    } 
 
    public void createInitialValueMap(Object object) { 
        userContext = ((AbstractBusinessObject) object).getUserContext();
        interceptHelper.hibernateMeta(object, AuditConstants.TRANSACTIONBEGIN);
    } 
 
    public void createChangeValueMap(Object object) { 
        if (interceptHelper.getEntityName().equals(AuditConfiguration.getEntityToClassPath(object.getClass().getName()))) {
            interceptHelper.hibernateMeta(object, AuditConstants.TRANSACTIONEND);
        } 
    } 
 
6
CodeRank
This code example shows how to use the following methods:
//$Id: CollectionInterceptor.java 7700 2005-07-30 05:02:47Z oneovthafew $ 
package org.hibernate.test.interceptor; 
import java.io.Serializable; 
import org.hibernate.EmptyInterceptor; 
import org.hibernate.type.Type; 
 
public class CollectionInterceptor extends EmptyInterceptor { 
 
	public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) { 
		( (User) entity ).getActions().add("updated"); 
		return false; 
	} 
 
	public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) { 
		( (User) entity ).getActions().add("created"); 
		return false; 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:
//$Id: PropertyInterceptor.java 7700 2005-07-30 05:02:47Z oneovthafew $ 
package org.hibernate.test.interceptor; 
import java.io.Serializable;
import java.util.Calendar;
import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;
 
public class PropertyInterceptor extends EmptyInterceptor {
 
	public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
		currentState[1] = Calendar.getInstance();
		return true; 
	} 
 
	public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
		state[2] = Calendar.getInstance();
		return true; 
	} 
 
} 

6
CodeRank
This code example shows how to use the following methods:
package org.hibernate.test.dynamicentity.tuplizer; 
import org.hibernate.EmptyInterceptor; 
import org.hibernate.test.dynamicentity.ProxyHelper; 
 
/** 
 * @author <a href="mailto:steve@hibernate.org">Steve Ebersole </a> 
 */ 
public class EntityNameInterceptor extends EmptyInterceptor { 
	/** 
	 * The callback from Hibernate to determine the entity name given 
	 * a presumed entity instance. 
	 * 
	 * @param object The presumed entity instance. 
	 * @return The entity name (pointing to the proper entity mapping). 
	 */ 
	public String getEntityName(Object object) { 
		String entityName = ProxyHelper.extractEntityName( object ); 
		if ( entityName == null ) { 
			entityName = super.getEntityName( object ); 
		} 

6
CodeRank
This code example shows how to use the following methods:
//$Id$ 
package org.hibernate.test.annotations.tuplizer; 
import org.hibernate.EmptyInterceptor; 
 
/** 
 * @author Emmanuel Bernard 
 */ 
public class EntityNameInterceptor extends EmptyInterceptor { 
	/** 
	 * The callback from Hibernate to determine the entity name given 
	 * a presumed entity instance. 
	 * 
	 * @param object The presumed entity instance. 
	 * @return The entity name (pointing to the proper entity mapping). 
	 */ 
	public String getEntityName(Object object) { 
		String entityName = ProxyHelper.extractEntityName( object ); 
		if ( entityName == null ) { 
			entityName = super.getEntityName( object ); 
		} 

6
CodeRank
This code example shows how to use the following methods:
//$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() ) );
		} 

6
CodeRank
This code example shows how to use the following methods:
import org.hibernate.EntityMode;
 
public class InstantiateInterceptor extends EmptyInterceptor {
	private String injectedString;
 
	public InstantiateInterceptor(String injectedString) {
		this.injectedString = injectedString;		
	} 
 
	public Object instantiate(String entityName, EntityMode entityMode, Serializable id) throws CallbackException {
		if ( ! "org.hibernate.test.interceptor.User".equals( entityName ) ) {
			return null; 
		} 
		// Simply inject a sample string into new instances 
		User instance = new User();
		instance.setName( ( String ) id );
		instance.setInjectedString( injectedString );
		return instance;
	} 
} 
6
CodeRank
See Code Examples for Hibernate ORM EmptyInterceptor Methods: