]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/UnescapedPropertyMapOfResource.java
New implementation NearestOwnerFinder of CommonDBUtils.getNearestOwner
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / request / UnescapedPropertyMapOfResource.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.layer0.request;
13
14 import gnu.trove.map.hash.THashMap;
15
16 import java.util.Collection;
17 import java.util.Map;
18
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.ResourceRead;
23 import org.simantics.db.exception.DatabaseException;
24
25 public class UnescapedPropertyMapOfResource extends ResourceRead<Map<String, PropertyInfo>> {
26
27         public UnescapedPropertyMapOfResource(Resource resource) {
28             super(resource);
29         }
30
31         @Override
32         public Map<String,PropertyInfo> perform(ReadGraph graph) throws DatabaseException {
33
34                 Collection<Resource> predicates = graph.getPredicates(resource); 
35         THashMap<String, PropertyInfo> result = new THashMap<String, PropertyInfo>(predicates.size());
36                 for(Resource predicate : predicates) {
37                         PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate), TransientCacheAsyncListener.<PropertyInfo>instance());
38                         if(info != null && info.isHasProperty) {
39                         String name = info.name;
40                         if (result.put(name, info) != null)
41                                 System.err.println(this + ": The database resource $" + resource.getResourceId() + " contains siblings with the same name " + name + " (resource=$" + info.predicate.getResourceId() +").");
42                         }                               
43                 }
44                 return result;
45                 
46         }
47         
48 }