1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2013 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.objmap.graph.impl;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.exception.DatabaseException;
\r
16 import org.simantics.db.procedure.SyncListener;
\r
17 import org.simantics.db.request.Read;
\r
19 import org.simantics.objmap.exceptions.MappingException;
\r
20 import org.simantics.objmap.forward.IForwardMapping;
\r
21 import org.simantics.objmap.graph.impl.Link;
\r
24 public class RangeUpdateRequest<Domain,Range> implements Read<Boolean>, SyncListener<Boolean> {
\r
26 Link<Domain,Range> link;
\r
28 * Note that this map uses a read request that it has got from caller and
\r
29 * not the one that is used in updateRange. This is intentional.
\r
31 IForwardMapping<Domain, Range> map; // map==null is used to flag that request is performed once
\r
32 Mapping<Domain, Range> mapping; // mapping==null is used as a flag the request disposed
\r
34 public RangeUpdateRequest(Link<Domain,Range> link, IForwardMapping<Domain,Range> map, Mapping<Domain,Range> mapping) {
\r
37 this.mapping = mapping;
\r
41 public Boolean perform(ReadGraph g) throws DatabaseException {
\r
43 link.type.updateRange(g, map, link.domainElement, link.rangeElement);
\r
45 return Boolean.TRUE;
\r
47 else if(mapping != null) {
\r
48 mapping.domainModified(link);
\r
50 return Boolean.FALSE;
\r
57 public void exception(ReadGraph graph, Throwable throwable)
\r
58 throws DatabaseException {
\r
59 if(throwable instanceof DatabaseException)
\r
60 throw (DatabaseException)throwable;
\r
62 throw new MappingException(throwable);
\r
66 public void execute(ReadGraph graph, Boolean result)
\r
67 throws DatabaseException {
\r
71 public boolean isDisposed() {
\r
72 return mapping == null || link.removed || mapping.isDisposed();
\r