1 /*******************************************************************************
2 * Copyright (c) 2007, 2013 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.objmap.graph.impl;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.procedure.SyncListener;
17 import org.simantics.db.request.Read;
19 import org.simantics.objmap.exceptions.MappingException;
20 import org.simantics.objmap.forward.IForwardMapping;
21 import org.simantics.objmap.graph.impl.Link;
24 public class RangeUpdateRequest<Domain,Range> implements Read<Integer>, SyncListener<Integer> {
26 Link<Domain,Range> link;
28 * Note that this map uses a read request that it has got from caller and
29 * not the one that is used in updateRange. This is intentional.
31 IForwardMapping<Domain, Range> map; // map==null is used to flag that request is performed once
32 Mapping<Domain, Range> mapping; // mapping==null is used as a flag the request disposed
35 public RangeUpdateRequest(Link<Domain,Range> link, IForwardMapping<Domain,Range> map, Mapping<Domain,Range> mapping) {
38 this.mapping = mapping;
43 public Integer perform(ReadGraph g) throws DatabaseException {
44 boolean changed = false;
46 changed = link.type.checkChanges(g, map, link.domainElement, link.rangeElement);
47 else if (mapping != null)
48 changed = link.type.checkChanges(g, mapping, link.domainElement, link.rangeElement);
50 return changed ? counter + 1 : counter;
54 public void exception(ReadGraph graph, Throwable throwable)
55 throws DatabaseException {
56 if(throwable instanceof DatabaseException)
57 throw (DatabaseException)throwable;
59 throw new MappingException(throwable);
63 public void execute(ReadGraph graph, Integer result)
64 throws DatabaseException {
65 boolean changed = result != counter;
70 link.type.updateRange(graph, map, link.domainElement, link.rangeElement);
73 else if (mapping != null && changed) {
74 mapping.domainModified(link);
80 public boolean isDisposed() {
81 return mapping == null || link.removed || mapping.isDisposed();