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;
16 import java.util.HashMap;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
22 import org.simantics.db.common.request.TransientResourceRead;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.layer0.request.PropertyInfo;
25 import org.simantics.db.request.RequestFlags;
26 import org.simantics.db.service.QueryControl;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class ConnectionPointMapOfResource extends TransientResourceRead<Map<String, PropertyInfo>> {
32 private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionPointMapOfResource.class);
34 public ConnectionPointMapOfResource(ReadGraph graph, Resource resource) throws DatabaseException {
35 super(graph, resource);
38 public ConnectionPointMapOfResource(ReadGraph graph, QueryControl qc, Resource resource) throws DatabaseException {
39 super(graph, qc, resource);
43 public Map<String,PropertyInfo> perform(ReadGraph graph, Resource resource) throws DatabaseException {
45 Collection<Resource> predicates = graph.getPredicates(resource);
47 HashMap<String,PropertyInfo> result = null;
49 for(Resource predicate : predicates) {
51 PropertyInfo info = graph.syncRequest(new PossibleConnectionPointInfo(predicate), TransientCacheAsyncListener.<PropertyInfo>instance());
53 if (result == null) result = new HashMap<>(predicates.size());
54 if (result.put(info.name, info) != null)
55 LOGGER.error("The database contains siblings with the same name " + info.name + " (resource=$" + resource.getResourceId() + ").");
60 if(result != null) return result;
62 else return Collections.emptyMap();
67 public int getType() {
68 return RequestFlags.INVALIDATE;