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