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.WriteOnly;
24 * TODO: fix this javadoc to document the correct class!!
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 WriteOnlyRequest implements WriteOnly, WriteInterface<Object> {
74 private final VirtualGraph provider;
76 public WriteOnlyRequest() {
80 public WriteOnlyRequest(VirtualGraph provider) {
81 this.provider = provider;
85 final public VirtualGraph getProvider() {
90 public void request(AsyncRequestProcessor processor, final Procedure<Object> procedure) {
91 processor.asyncRequest(this, parameter -> {
92 if(parameter != null) procedure.exception(parameter);
93 else procedure.execute(null);
98 public Object request(RequestProcessor processor) throws DatabaseException {
99 processor.syncRequest(this);