Search in sources :

Example 1 with DbClientCallbackEvent

use of com.emc.storageos.db.client.util.DbClientCallbackEvent in project coprhd-controller by CoprHD.

the class LazyLoader method refreshMappedByStringSet.

/**
 * @param obj
 * @param lazyLoadedFieldReadMethod
 * @param mappedByFieldReadMethod
 * @param mappedByFieldWriteMethod
 * @param mappedByObjType
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws InstantiationException
 */
private void refreshMappedByStringSet(DataObject obj, Method lazyLoadedFieldReadMethod, Method mappedByFieldReadMethod, Method mappedByFieldWriteMethod, Class mappedByObjType) {
    try {
        Collection<DataObject> lazyLoadedFieldValue = (Collection) lazyLoadedFieldReadMethod.invoke(obj);
        StringSet mappedByFieldValue = (StringSet) mappedByFieldReadMethod.invoke(obj);
        // otherwise, set the mapped by stringset to the list of id's in the lazy loaded collection
        if (lazyLoadedFieldValue == null || lazyLoadedFieldValue.isEmpty()) {
            if (mappedByFieldValue != null) {
                mappedByFieldValue.clear();
                mappedByFieldWriteMethod.invoke(obj, mappedByFieldValue);
            }
        } else {
            if (mappedByFieldValue == null) {
                mappedByFieldValue = (StringSet) mappedByObjType.newInstance();
            }
            DbClientCallbackEvent cb = mappedByFieldValue.getCallback();
            mappedByFieldValue.setCallback(null);
            copyCollectionToStringSet(lazyLoadedFieldValue, mappedByFieldValue);
            mappedByFieldValue.setCallback(cb);
            mappedByFieldWriteMethod.invoke(obj, mappedByFieldValue);
        }
    } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException e) {
        // we've done all the checking we can; if we end up here, it's a programming error
        log.error(e.getMessage(), e);
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) StringSet(com.emc.storageos.db.client.model.StringSet) Collection(java.util.Collection) DbClientCallbackEvent(com.emc.storageos.db.client.util.DbClientCallbackEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with DbClientCallbackEvent

use of com.emc.storageos.db.client.util.DbClientCallbackEvent in project coprhd-controller by CoprHD.

the class LazyLoadedCollection method removeAll.

/*
     * (non-Javadoc)
     * 
     * @see java.util.Collection#removeAll(java.util.Collection)
     */
@Override
public synchronized boolean removeAll(Collection<?> c) {
    if (mappedByUriSet != null) {
        DbClientCallbackEvent cb = mappedByUriSet.getCallback();
        mappedByUriSet.setCallback(null);
        mappedByUriSet.remove(toIds(c));
        mappedByUriSet.setCallback(cb);
    }
    return getCollection().removeAll(c);
}
Also used : DbClientCallbackEvent(com.emc.storageos.db.client.util.DbClientCallbackEvent)

Example 3 with DbClientCallbackEvent

use of com.emc.storageos.db.client.util.DbClientCallbackEvent in project coprhd-controller by CoprHD.

the class LazyLoadedCollection method addAll.

/*
     * (non-Javadoc)
     * 
     * @see java.util.Collection#addAll(java.util.Collection)
     */
@Override
public synchronized boolean addAll(Collection<? extends E> c) {
    if (mappedByUriSet != null) {
        DbClientCallbackEvent cb = mappedByUriSet.getCallback();
        mappedByUriSet.setCallback(null);
        mappedByUriSet.addAll(toIds(c));
        mappedByUriSet.setCallback(cb);
    }
    return getCollection().addAll(c);
}
Also used : DbClientCallbackEvent(com.emc.storageos.db.client.util.DbClientCallbackEvent)

Example 4 with DbClientCallbackEvent

use of com.emc.storageos.db.client.util.DbClientCallbackEvent in project coprhd-controller by CoprHD.

the class LazyLoadedCollection method clear.

/*
     * (non-Javadoc)
     * 
     * @see java.util.Collection#clear()
     */
@Override
public synchronized void clear() {
    if (mappedByUriSet != null) {
        DbClientCallbackEvent cb = mappedByUriSet.getCallback();
        mappedByUriSet.setCallback(null);
        mappedByUriSet.clear();
        mappedByUriSet.setCallback(cb);
    }
    getCollection().clear();
}
Also used : DbClientCallbackEvent(com.emc.storageos.db.client.util.DbClientCallbackEvent)

Example 5 with DbClientCallbackEvent

use of com.emc.storageos.db.client.util.DbClientCallbackEvent in project coprhd-controller by CoprHD.

the class LazyLoadedCollection method add.

/*
     * (non-Javadoc)
     * 
     * @see java.util.Collection#add(java.lang.Object)
     */
@Override
public synchronized boolean add(E e) {
    if (mappedByUriSet != null) {
        DbClientCallbackEvent cb = mappedByUriSet.getCallback();
        mappedByUriSet.setCallback(null);
        mappedByUriSet.add(e.getId().toString());
        mappedByUriSet.setCallback(cb);
    }
    return getCollection().add(e);
}
Also used : DbClientCallbackEvent(com.emc.storageos.db.client.util.DbClientCallbackEvent)

Aggregations

DbClientCallbackEvent (com.emc.storageos.db.client.util.DbClientCallbackEvent)7 DataObject (com.emc.storageos.db.client.model.DataObject)2 StringSet (com.emc.storageos.db.client.model.StringSet)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1