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.impl.query;
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.impl.DebugPolicy;
16 import org.simantics.db.impl.graph.ReadGraphImpl;
17 import org.simantics.db.procedure.AsyncProcedure;
18 import org.simantics.db.request.AsyncRead;
20 final public class AsyncReadEntry<T> extends CacheEntryBase {
22 protected AsyncRead<T> request;
24 public AsyncReadEntry(AsyncRead<T> request) {
25 this.request = request;
26 if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: created " + this);
31 return request.hashCode();
35 public Object getOriginalRequest() {
40 public void discard() {
46 final public void addOrSet(AsyncReadGraph graph, Object item) {
50 // ArrayList<AsyncProcedure<T>> p = null;
62 // for(AsyncProcedure<T> proc : p) {
63 // proc.execute(graph, (T)item);
64 //// proc.first.execute(graph, (T)item);
65 //// proc.second.dec();
71 public void except(AsyncReadGraph graph, Throwable t) {
75 // ArrayList<AsyncProcedure<T>> p = null;
86 // for(AsyncProcedure<T> proc : p) {
87 // proc.exception(graph, t);
94 final public Query getQuery() {
99 public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) {
101 QueryProcessor qp = (QueryProcessor)provider;
103 final ReadGraphImpl parentGraph = ReadGraphImpl.forRecompute(entry, qp);
107 request.perform(parentGraph , new AsyncProcedure<T>() {
110 public void execute(AsyncReadGraph graph, T result) {
111 addOrSet(graph, result);
115 public void exception(AsyncReadGraph graph, Throwable t) {
121 } catch (Throwable t) {
128 public void removeEntry(QueryProcessor qp) {
129 qp.cache.asyncReadMap.remove(request);
134 return request.getFlags();
138 public String toString() {
139 if(request == null) return "DISCARDED";
140 else if(isExcepted()) return request.toString() + " " + getResult();
141 else return request.toString() + " " + statusOrException;
149 @SuppressWarnings("unchecked")
150 public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
152 public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
153 >>>>>>> refs/heads/db-threads
155 AsyncProcedure<T> proc = (AsyncProcedure<T>)procedure;
160 proc.exception(graph, (Throwable)getResult());
161 } catch (Throwable t) {
168 proc.execute(graph, (T)getResult());
169 } catch (Throwable t) {
180 public String toString() {
181 if(isDiscarded()) return "DISCARDED " + request.toString();
182 else if(isExcepted()) return request.toString() + " " + getResult();
183 else return request.toString() + " " + statusOrException;