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.Operation;
16 import org.simantics.db.RequestProcessor;
17 import org.simantics.db.VirtualGraph;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.procedure.Procedure;
20 import org.simantics.db.request.UndoTraits;
21 import org.simantics.db.request.Write;
22 import org.simantics.db.request.WriteInterface;
26 * TODO: fix this javadoc to document the correct class!!
31 * Synchronous read without checked exceptions:
34 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
36 * public Resource run(Graph g) {
37 * Resource r = doSomethingThatMayFail();
44 * Synchronous read with a selected checked exception that may be thrown:
47 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
49 * public Resource run(Graph g) throws CheckedException {
50 * Resource r = doSomethingThatMayFailWithCheckedException();
53 * }.sync(CheckedException.class);
57 * Asynchronous read with a completed() method for examining the result:
60 * Resource r = new SimpleReadGraphRequest<Resource>(session) {
62 * public Resource run(Graph g) {
63 * Resource r = doSomethingThatMayFail();
66 * public void completed(Resource result) {
67 * // quickly dispatch the result somewhere, do nothing serious in this code.
72 * @param <T> the result type
74 public abstract class WriteRequest implements Write, UndoTraits, WriteInterface<Object> {
76 private final VirtualGraph provider;
78 public WriteRequest() {
82 public WriteRequest(VirtualGraph provider) {
83 this.provider = provider;
87 public void commitOk(Operation op) {
91 final public VirtualGraph getProvider() {
96 public void request(AsyncRequestProcessor processor, final Procedure<Object> procedure) {
97 processor.asyncRequest(this, parameter -> {
98 if(parameter != null) procedure.exception(parameter);
99 else procedure.execute(null);
104 public Object request(RequestProcessor processor) throws DatabaseException {
105 processor.syncRequest(this);