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.request;
14 import org.simantics.db.AsyncRequestProcessor;
15 import org.simantics.db.RequestProcessor;
16 import org.simantics.db.VirtualGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.procedure.Procedure;
19 import org.simantics.db.request.DelayedWriteResult;
20 import org.simantics.db.request.UndoTraits;
21 import org.simantics.db.request.WriteInterface;
22 import org.simantics.db.request.WriteTraits;
29 * Synchronous read without checked exceptions:
32 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
34 * public Resource run(Graph g) {
35 * Resource r = doSomethingThatMayFail();
42 * Synchronous read with a selected checked exception that may be thrown:
45 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
47 * public Resource run(Graph g) throws CheckedException {
48 * Resource r = doSomethingThatMayFailWithCheckedException();
51 * }.sync(CheckedException.class);
55 * Asynchronous read with a completed() method for examining the result:
58 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
60 * public Resource run(Graph g) {
61 * Resource r = doSomethingThatMayFail();
64 * public void completed(Resource result) {
65 * // quickly dispatch the result somewhere, do nothing serious in this code.
70 * @param <T> the result type
72 public abstract class DelayedWriteResultRequest<T> implements DelayedWriteResult<T>, WriteTraits, WriteInterface<T> {
74 private final VirtualGraph provider;
76 public DelayedWriteResultRequest() {
80 public DelayedWriteResultRequest(VirtualGraph provider) {
81 this.provider = provider;
85 final public VirtualGraph getProvider() {
90 public UndoTraits getUndoTraits() {
95 public void request(AsyncRequestProcessor processor, final Procedure<T> procedure) {
96 processor.asyncRequest(this, procedure);
100 public T request(RequestProcessor processor) throws DatabaseException {
101 return processor.syncRequest(this);