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.WriteInterface;
21 import org.simantics.db.request.WriteTraits;
28 * Synchronous read without checked exceptions:
31 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
33 * public Resource run(Graph g) {
34 * Resource r = doSomethingThatMayFail();
41 * Synchronous read with a selected checked exception that may be thrown:
44 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
46 * public Resource run(Graph g) throws CheckedException {
47 * Resource r = doSomethingThatMayFailWithCheckedException();
50 * }.sync(CheckedException.class);
54 * Asynchronous read with a completed() method for examining the result:
57 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
59 * public Resource run(Graph g) {
60 * Resource r = doSomethingThatMayFail();
63 * public void completed(Resource result) {
64 * // quickly dispatch the result somewhere, do nothing serious in this code.
69 * @param <T> the result type
71 public abstract class DelayedWriteResultRequest<T> implements DelayedWriteResult<T>, WriteTraits, WriteInterface<T> {
73 private final VirtualGraph provider;
75 public DelayedWriteResultRequest() {
79 public DelayedWriteResultRequest(VirtualGraph provider) {
80 this.provider = provider;
84 final public VirtualGraph getProvider() {
89 public void request(AsyncRequestProcessor processor, final Procedure<T> procedure) {
90 processor.asyncRequest(this, procedure);
94 public T request(RequestProcessor processor) throws DatabaseException {
95 return processor.syncRequest(this);