Example usage for org.hibernate Interceptor findDirty

List of usage examples for org.hibernate Interceptor findDirty

Introduction

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

Prototype

int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
        String[] propertyNames, Type[] types);

Source Link

Document

Called from flush().

Usage

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

License:Open Source License

/**
 * Calls the children's findDirty methods, in order, looking for the first non-null result.
 * Once a non null result is found, <em>the remaining children's findDirty methods will
 * <b>not</b> be called.</em>
 *
 * @param entity entity//from   w  w  w .  jav  a  2  s .co  m
 * @param id id
 * @param currentState currentState
 * @param previousState previousState
 * @param propertyNames propertyNames
 * @param types types
 *
 * @return first non-null result from children, or null if all children returned null
 */
@SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull")
public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
        String[] propertyNames, Type[] types) {
    for (Interceptor i : children) {
        int[] tmp = i.findDirty(entity, id, currentState, previousState, propertyNames, types);
        if (tmp != null) {
            return tmp;
        }
    }
    return null;
}

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

License:Open Source License

private void helper(Interceptor i, boolean expectChanges) {
    i.afterTransactionBegin(null);/*w ww  .j  a  v a2 s  .c o m*/
    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:gov.nih.nci.cabig.ctms.audit.ChainedInterceptor.java

License:BSD License

public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
        String[] propertyNames, Type[] types) {
    int[] result = null;
    for (Interceptor element : interceptors) {
        result = element.findDirty(entity, id, currentState, previousState, propertyNames, types);
        if (result != null) {
            /*//from ww w  . j a v  a 2  s  . c om
             * If any interceptor has returned something not null, stop the
             * chain
             */
            break;
        }
    }
    return result;
}

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

License:Open Source License

public int[] findDirty(HibernateInterceptorChain chain, Interceptor target, Object entity, Serializable id,
        Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
    return target.findDirty(entity, id, currentState, previousState, propertyNames, types);
}

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

License:Mozilla Public License

public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
        String[] propertyNames, Type[] types) {

    List<Integer> uniqueIndices = new LinkedList<Integer>();

    for (Interceptor i : interceptors) {
        int[] indices = i.findDirty(entity, id, currentState, previousState, propertyNames, types);
        if (indices != null) {
            for (int index : indices) {
                if (!uniqueIndices.contains(index)) {
                    uniqueIndices.add(index);
                }/*from   w ww  . ja  va2  s.c  o  m*/
            }
        }
    }

    if (uniqueIndices.isEmpty()) {
        return null;
    }

    // turn it back into an array and return it

    int[] uniquePrimitiveIndices = new int[uniqueIndices.size()];

    for (int x = 0; x < uniqueIndices.size(); x++) {
        uniquePrimitiveIndices[x] = uniqueIndices.get(x).intValue();
    }

    return uniquePrimitiveIndices;
}

From source file:org.riotfamily.common.hibernate.ChainedInterceptor.java

License:Apache License

public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
        String[] propertyNames, Type[] types) {

    for (Interceptor interceptor : interceptors) {
        int[] result = interceptor.findDirty(entity, id, currentState, previousState, propertyNames, types);
        if (result != null) {
            return result;
        }//from w ww.  j a v a  2 s .  com
    }
    return null;
}