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());
}
}
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);
}
}
Aggregations