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.WriteInterface;
20 import org.simantics.db.request.WriteOnlyResult;
27 * Synchronous read without checked exceptions:
30 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
32 * public Resource run(Graph g) {
33 * Resource r = doSomethingThatMayFail();
40 * Synchronous read with a selected checked exception that may be thrown:
43 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
45 * public Resource run(Graph g) throws CheckedException {
46 * Resource r = doSomethingThatMayFailWithCheckedException();
49 * }.sync(CheckedException.class);
53 * Asynchronous read with a completed() method for examining the result:
56 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
58 * public Resource run(Graph g) {
59 * Resource r = doSomethingThatMayFail();
62 * public void completed(Resource result) {
63 * // quickly dispatch the result somewhere, do nothing serious in this code.
68 * @param <T> the result type
70 public abstract class WriteOnlyResultRequest<T> implements WriteOnlyResult<T>, WriteInterface<T> {
72 private final VirtualGraph provider;
74 public WriteOnlyResultRequest() {
78 public WriteOnlyResultRequest(VirtualGraph provider) {
79 this.provider = provider;
83 final public VirtualGraph getProvider() {
88 public void request(AsyncRequestProcessor processor, final Procedure<T> procedure) {
89 processor.asyncRequest(this, procedure);
93 public T request(RequestProcessor processor) throws DatabaseException {
94 return processor.syncRequest(this);