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.structural2.queries;
14 import java.util.Collection;
15 import java.util.Collections;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
21 import org.simantics.db.common.request.TransientResourceRead;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.layer0.request.PropertyInfo;
24 import org.simantics.db.request.RequestFlags;
25 import org.simantics.db.service.QueryControl;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import gnu.trove.map.hash.THashMap;
31 public class ConnectionPointMapOfResource extends TransientResourceRead<Map<String, Resource>> {
33 private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionPointMapOfResource.class);
35 public ConnectionPointMapOfResource(ReadGraph graph, Resource resource) throws DatabaseException {
36 super(graph, resource);
39 public ConnectionPointMapOfResource(ReadGraph graph, QueryControl qc, Resource resource) throws DatabaseException {
40 super(graph, qc, resource);
44 public Map<String,Resource> perform(ReadGraph graph, Resource resource) throws DatabaseException {
46 Collection<Resource> predicates = graph.getPredicates(resource);
48 THashMap<String,Resource> result = null;
50 for(Resource predicate : predicates) {
52 PropertyInfo info = graph.syncRequest(new PossibleConnectionPointInfo(predicate), TransientCacheAsyncListener.<PropertyInfo>instance());
54 if (result == null) result = new THashMap<String,Resource>(predicates.size());
55 if (result.put(info.name, predicate) != null)
56 LOGGER.error("The database contains siblings with the same name " + info.name + " (resource=$" + resource.getResourceId() + ").");
61 if(result != null) return result;
63 else return Collections.emptyMap();
68 public int getType() {
69 return RequestFlags.INVALIDATE;