1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.structural2.queries;
\r
14 import gnu.trove.map.hash.THashMap;
\r
16 import java.util.Collection;
\r
17 import java.util.Collections;
\r
18 import java.util.Map;
\r
20 import org.simantics.db.ReadGraph;
\r
21 import org.simantics.db.Resource;
\r
22 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
\r
23 import org.simantics.db.common.request.TransientResourceRead;
\r
24 import org.simantics.db.exception.DatabaseException;
\r
25 import org.simantics.db.layer0.request.PropertyInfo;
\r
26 import org.simantics.db.request.RequestFlags;
\r
27 import org.simantics.db.service.QueryControl;
\r
29 public class ConnectionPointMapOfResource extends TransientResourceRead<Map<String, Resource>> {
\r
31 public ConnectionPointMapOfResource(ReadGraph graph, Resource resource) throws DatabaseException {
\r
32 super(graph, resource);
\r
35 public ConnectionPointMapOfResource(ReadGraph graph, QueryControl qc, Resource resource) throws DatabaseException {
\r
36 super(graph, qc, resource);
\r
40 public Map<String,Resource> perform(ReadGraph graph, Resource resource) throws DatabaseException {
\r
42 Collection<Resource> predicates = graph.getPredicates(resource);
\r
44 THashMap<String,Resource> result = null;
\r
46 for(Resource predicate : predicates) {
\r
48 PropertyInfo info = graph.syncRequest(new PossibleConnectionPointInfo(predicate), TransientCacheAsyncListener.<PropertyInfo>instance());
\r
50 if (result == null) result = new THashMap<String,Resource>(predicates.size());
\r
51 if (result.put(info.name, predicate) != null)
\r
52 System.err.println(this + ": The database contains siblings with the same name " + info.name + " (resource=$" + resource.getResourceId() + ").");
\r
57 if(result != null) return result;
\r
59 else return Collections.emptyMap();
\r
64 public int getType() {
\r
65 return RequestFlags.INVALIDATE;
\r