]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/TypeSetAndString.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / read / TypeSetAndString.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.tests.performance.read;
13
14 import java.util.Set;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.ResourceRead;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.service.CollectionSupport;
22 import org.simantics.layer0.Layer0;
23 import org.simantics.utils.datastructures.Pair;
24
25 public class TypeSetAndString extends ResourceRead<Pair<Set<Resource>, String>> {
26
27     public TypeSetAndString(Resource type) {
28         super(type);
29     }
30
31     @Override
32     public Pair<Set<Resource>, String> perform(ReadGraph graph) throws DatabaseException {
33         
34         Layer0 L0 = Layer0.getInstance(graph);
35         CollectionSupport cs = graph.getService(CollectionSupport.class);
36         Set<Resource> types = cs.createSet();
37         
38         types.add(resource);
39         types.addAll(graph.getSupertypes(resource));
40         
41         final StringBuilder b = new StringBuilder();
42         boolean first = true;
43         for (Resource type : types) {
44                 String name = graph.getPossibleRelatedValue(type, L0.HasName, Bindings.STRING);
45             if (!first) b.append(" ");
46             first = false;
47         }
48         
49         return Pair.make(types, b.toString());
50         
51     }
52
53 }