]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/ReflectionComputationalValue.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / adapter / ReflectionComputationalValue.java
1 /*******************************************************************************
2  * Copyright (c) 2018 Association for Decentralized Information Management in
3  * 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  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.adapter;
13
14 import org.simantics.db.ComputationalValue;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.scl.reflection.ReflectionUtils;
19 import org.simantics.scl.reflection.ValueNotFoundException;
20
21 /**
22  * @author Antti Villberg
23  * @since 1.36.0
24  */
25 public class ReflectionComputationalValue implements ComputationalValue {
26
27     @SuppressWarnings("unchecked")
28     @Override
29     public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
30         try {
31             return (T)ReflectionUtils.getValue(graph.getURI(resource)).getValue();
32         } catch(ValueNotFoundException e) {
33             throw new DatabaseException(e);
34         } catch(ClassCastException e) {
35             throw new DatabaseException(e);
36         }
37     }
38
39 }