1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.common.procedure.single;
14 import java.util.Collection;
15 import java.util.HashSet;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.common.utils.Logger;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.procedure.SyncListener;
22 abstract public class StagedSingleSetSyncListener<T> implements SyncListener<Collection<T>>{
24 private Collection<T> previous = null;
26 public void start(ReadGraph graph, Collection<T> items) throws DatabaseException {}
27 public void add(ReadGraph graph, T item) throws DatabaseException {}
28 public void remove(ReadGraph graph, T item) throws DatabaseException {}
31 public synchronized void execute(ReadGraph graph, final Collection<T> result) throws DatabaseException {
33 if(previous == null) {
39 HashSet<T> added = new HashSet<T>(result);
40 added.removeAll(previous);
41 HashSet<T> removed = new HashSet<T>(previous);
42 removed.removeAll(result);
44 for(T t : added) add(graph, t);
45 for(T t : removed) remove(graph, t);
54 public void exception(ReadGraph graph, Throwable throwable) throws DatabaseException {
55 Logger.defaultLogError(throwable);