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