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<Boolean>, SyncListener<Boolean> {
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
34 public RangeUpdateRequest(Link<Domain,Range> link, IForwardMapping<Domain,Range> map, Mapping<Domain,Range> mapping) {
37 this.mapping = mapping;
41 public Boolean perform(ReadGraph g) throws DatabaseException {
43 link.type.updateRange(g, map, link.domainElement, link.rangeElement);
47 else if(mapping != null) {
48 mapping.domainModified(link);
57 public void exception(ReadGraph graph, Throwable throwable)
58 throws DatabaseException {
59 if(throwable instanceof DatabaseException)
60 throw (DatabaseException)throwable;
62 throw new MappingException(throwable);
66 public void execute(ReadGraph graph, Boolean result)
67 throws DatabaseException {
71 public boolean isDisposed() {
72 return mapping == null || link.removed || mapping.isDisposed();