1 package org.simantics.db.layer0.request;
3 import java.util.Collection;
5 import org.simantics.db.ReadGraph;
6 import org.simantics.db.Resource;
7 import org.simantics.db.common.request.ResourceRead;
8 import org.simantics.db.common.utils.NameUtils;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.exception.NoSingleResultException;
13 * Returns the active model or null if no single active model is available.
15 public class SingleActiveModel extends ResourceRead<Resource> {
17 public SingleActiveModel(Resource project) {
22 public Resource perform(ReadGraph graph) throws DatabaseException {
23 Collection<Resource> actives = graph.syncRequest(new ActiveModels(resource));
24 if (actives.size() == 1)
25 return actives.iterator().next();
27 if (actives.size() == 0)
28 throw new NoSingleResultException("There are no active models.", actives.size());
30 throw new NoSingleResultException("There are many active models: " + NameUtils.getSafeName(graph, actives), actives.size());