Example usage for org.hibernate Interceptor onSave

List of usage examples for org.hibernate Interceptor onSave

Introduction

In this page you can find the example usage for org.hibernate Interceptor onSave.

Prototype

boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
        throws CallbackException;

Source Link

Document

Called before an object is saved.

Usage

From source file:com.fiveamsolutions.nci.commons.util.CompositeInterceptor.java

License:Open Source License

/**
 * Calls the children's onSave methods, in order.
 *
 * @param entity entity//from  w  ww  .  java  2s.  c o m
 * @param id id
 * @param state state
 * @param propertyNames propertyNames
 * @param types types
 *
 * @return true if <em>any</em> child has modified the state in any way
 */
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
    boolean result = false;
    for (Interceptor i : children) {
        result |= i.onSave(entity, id, state, propertyNames, types);
    }

    return result;
}

From source file:com.fiveamsolutions.nci.commons.util.CompositeInterceptorTest.java

License:Open Source License

private void helper(Interceptor i, boolean expectChanges) {
    i.afterTransactionBegin(null);//from   w ww  .j av  a2  s  . c  om
    i.afterTransactionCompletion(null);
    i.beforeTransactionCompletion(null);
    assertNull(i.getEntity(null, null));
    assertNull(i.getEntityName(null));
    if (expectChanges) {
        assertNotNull(i.findDirty(null, null, null, null, null, null));
        assertNotNull(i.instantiate(null, null, null));
        assertNotNull(i.isTransient(null));
        assertTrue(!"foo".equals(i.onPrepareStatement("foo")));
    } else {
        assertNull(i.findDirty(null, null, null, null, null, null));
        assertNull(i.instantiate(null, null, null));
        assertNull(i.isTransient(null));
        assertEquals("foo", i.onPrepareStatement("foo"));
    }
    i.onCollectionRecreate(null, null);
    i.onCollectionRemove(null, null);
    i.onCollectionUpdate(null, null);
    i.onDelete(null, null, null, null, null);
    assertEquals(expectChanges, i.onFlushDirty(null, null, null, null, null, null));
    assertEquals(expectChanges, i.onLoad(null, null, null, null, null));
    assertEquals(expectChanges, i.onSave(null, null, null, null, null));
    i.postFlush(null);
    i.preFlush(null);
}

From source file:debop4k.data.orm.hibernate.interceptors.MultipleInterceptor.java

License:Apache License

@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
    if (nonEmpty()) {
        for (Interceptor interceptor : interceptors) {
            interceptor.onSave(entity, id, state, propertyNames, types);
        }//from   ww  w.j  a v  a2 s.  com
    }
    return false;
}

From source file:gov.nih.nci.cabig.ctms.audit.ChainedInterceptor.java

License:BSD License

public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
        throws CallbackException {
    boolean result = false;
    for (Interceptor element : interceptors) {
        if (element.onSave(entity, id, state, propertyNames, types)) {
            /*//w w w  .jav  a  2  s .  c  o  m
             * Returns true if one interceptor in the chain has modified the
             * object state result = true;
             */
        }
    }

    return result;
}

From source file:io.github.jonestimd.hibernate.InterceptorChain.java

License:Open Source License

@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
        throws CallbackException {
    boolean modified = false;
    for (Interceptor interceptor : chain) {
        modified |= interceptor.onSave(entity, id, state, propertyNames, types);
    }// w  w  w  .  j a  v  a2 s  .c om
    return modified;
}

From source file:kr.debop4j.data.hibernate.interceptor.MultiInterceptor.java

License:Apache License

@Override
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
    if (!isExists())
        return false;

    if (isTraceEnabled)
        log.trace("?? onSave  ? .");

    List<FutureTask<Boolean>> tasks = Lists.newLinkedList();

    for (final Interceptor interceptor : interceptors) {
        interceptor.onSave(entity, id, state, propertyNames, types);
    }//from w w  w.j  a v  a2s  . co  m

    return false;
}

From source file:org.chenillekit.hibernate.interceptors.ChainedInterceptor.java

License:Apache License

/**
 * 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.
 *///  w ww .  j a  v a 2  s  .  c o m
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
        throws CallbackException {
    boolean result = false;
    for (Object o : interceptors.entrySet()) {
        Map.Entry entry = (Map.Entry) o;
        Interceptor interceptor = (Interceptor) entry.getValue();
        if (interceptor.onSave(entity, id, state, propertyNames, types))
            result = true;
    }
    return result;
}

From source file:org.hyperic.hibernate.DefaultInterceptorChain.java

License:Open Source License

public boolean onSave(HibernateInterceptorChain chain, Interceptor target, Object entity, Serializable id,
        Object[] state, String[] propertyNames, Type[] types) {
    return target.onSave(entity, id, state, propertyNames, types);
}

From source file:org.openmrs.api.db.hibernate.ChainingInterceptor.java

License:Mozilla Public License

public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) {
    boolean objectChanged = false;

    for (Interceptor i : interceptors) {
        // must be in this order so that java doesn't skip the method call for optimizations
        objectChanged = i.onSave(entity, id, state, propertyNames, types) || objectChanged;
    }//from w w  w. ja va 2s . c  om

    return objectChanged;
}

From source file:org.osaf.cosmo.hibernate.CompoundInterceptor.java

License:Apache License

@Override
public boolean onSave(Object object, Serializable id, Object[] state, String[] propertyNames, Type[] types) {

    boolean modified = false;
    for (Interceptor i : interceptors)
        modified = i.onSave(object, id, state, propertyNames, types);

    return modified;
}