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;
21 import org.simantics.utils.datastructures.Callback;
25 * TODO: fix this javadoc to document the correct class!!
30 * Synchronous read without checked exceptions:
33 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
35 * public Resource run(Graph g) {
36 * Resource r = doSomethingThatMayFail();
43 * Synchronous read with a selected checked exception that may be thrown:
46 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
48 * public Resource run(Graph g) throws CheckedException {
49 * Resource r = doSomethingThatMayFailWithCheckedException();
52 * }.sync(CheckedException.class);
56 * Asynchronous read with a completed() method for examining the result:
59 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
61 * public Resource run(Graph g) {
62 * Resource r = doSomethingThatMayFail();
65 * public void completed(Resource result) {
66 * // quickly dispatch the result somewhere, do nothing serious in this code.
71 * @param <T> the result type
73 public abstract class WriteOnlyRequest implements WriteOnly, WriteInterface<Object> {
75 private final VirtualGraph provider;
77 public WriteOnlyRequest() {
81 public WriteOnlyRequest(VirtualGraph provider) {
82 this.provider = provider;
86 final public VirtualGraph getProvider() {
91 public void request(AsyncRequestProcessor processor, final Procedure<Object> procedure) {
92 processor.asyncRequest(this, new Callback<DatabaseException>() {
95 public void run(DatabaseException parameter) {
96 if(parameter != null) procedure.exception(parameter);
97 else procedure.execute(null);
104 public Object request(RequestProcessor processor) throws DatabaseException {
105 processor.syncRequest(this);