]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/adaption/SimpleContextualAdapter.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / adaption / SimpleContextualAdapter.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.common.adaption;
13
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.adaption.Adapter;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.procedure.AsyncProcedure;
20 import org.simantics.db.request.Read;
21
22 public abstract class SimpleContextualAdapter<T,C> implements Adapter<T, C> {
23
24     public abstract T adapt(ReadGraph g, Resource source, C context) throws DatabaseException;
25
26     @Override
27     public void adapt(AsyncReadGraph g, final Resource source, final C context, AsyncProcedure<T> procedure) {
28
29         //System.out.println("SimpleAdapter.adapt" + this.getClass());
30
31         g.asyncRequest(new Read<T>() {
32
33             @Override
34             public T perform(ReadGraph graph) throws DatabaseException {
35                 //System.out.println("SimpleAdapter.perform" + this.getClass());
36                 return adapt(graph, source, context);
37             }
38             
39             @Override
40             public String toString() {
41                 return SimpleContextualAdapter.this.toString();
42             }
43             
44         }, procedure);
45
46     }
47
48 }