Search in sources :

Example 1 with StaleBeanException

use of org.jowidgets.cap.common.api.exception.StaleBeanException in project jo-client-platform by jo-source.

the class SyncDeleterService method delete.

@Override
public void delete(final Collection<? extends IBeanKey> keys, final IExecutionCallback executionCallback) {
    for (final IBeanKey key : keys) {
        final IBean bean = data.getData(key.getId());
        if (!allowDeletedData && bean == null) {
            throw new DeletedBeanException(key.getId());
        }
        if (!allowStaleData && bean != null && bean.getVersion() != key.getVersion()) {
            throw new StaleBeanException(key.getId());
        }
        data.deleteData(key.getId());
    }
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) StaleBeanException(org.jowidgets.cap.common.api.exception.StaleBeanException) IBean(org.jowidgets.cap.common.api.bean.IBean)

Example 2 with StaleBeanException

use of org.jowidgets.cap.common.api.exception.StaleBeanException in project jo-client-platform by jo-source.

the class SyncExecutorServiceImpl method checkBeans.

private void checkBeans(final Collection<? extends IBeanKey> keys, final List<BEAN_TYPE> beans, final IExecutionCallback executionCallback) {
    // put beans into map to access them faster at the next step
    final Map<Object, BEAN_TYPE> beanMap = new HashMap<Object, BEAN_TYPE>();
    for (final BEAN_TYPE bean : beans) {
        beanMap.put(getId(bean), bean);
        CapServiceToolkit.checkCanceled(executionCallback);
    }
    // check if beans are deleted or stale
    for (final IBeanKey key : keys) {
        final BEAN_TYPE bean = beanMap.get(key.getId());
        if (!allowDeletedBeans && bean == null) {
            throw new DeletedBeanException(key.getId());
        } else {
            if (!allowStaleBeans && key.getVersion() != getVersion(bean)) {
                throw new StaleBeanException(key.getId());
            }
        }
        CapServiceToolkit.checkCanceled(executionCallback);
    }
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) HashMap(java.util.HashMap) StaleBeanException(org.jowidgets.cap.common.api.exception.StaleBeanException)

Aggregations

IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)2 DeletedBeanException (org.jowidgets.cap.common.api.exception.DeletedBeanException)2 StaleBeanException (org.jowidgets.cap.common.api.exception.StaleBeanException)2 HashMap (java.util.HashMap)1 IBean (org.jowidgets.cap.common.api.bean.IBean)1