X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Frequest%2FSingleActiveModel.java;h=bff9a22137a80489369f09f144504421f2e7bf5f;hb=refs%2Fchanges%2F29%2F1529%2F8;hp=84083c237dcc49f3daea206cb30b9fcdd4228951;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/SingleActiveModel.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/SingleActiveModel.java index 84083c237..bff9a2213 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/SingleActiveModel.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/SingleActiveModel.java @@ -1,34 +1,34 @@ -package org.simantics.db.layer0.request; - -import java.util.Collection; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ResourceRead; -import org.simantics.db.common.utils.NameUtils; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.NoSingleResultException; - -/** - * Returns the active model or null if no single active model is available. - */ -public class SingleActiveModel extends ResourceRead { - - public SingleActiveModel(Resource project) { - super(project); - } - - @Override - public Resource perform(ReadGraph graph) throws DatabaseException { - Collection actives = graph.syncRequest(new ActiveModels(resource)); - if (actives.size() == 1) - return actives.iterator().next(); - - if (actives.size() == 0) - throw new NoSingleResultException("There are no active models."); - - throw new NoSingleResultException("There are many active models: " + NameUtils.getSafeName(graph, actives)); - - } - -} +package org.simantics.db.layer0.request; + +import java.util.Collection; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.NoSingleResultException; + +/** + * Returns the active model or null if no single active model is available. + */ +public class SingleActiveModel extends ResourceRead { + + public SingleActiveModel(Resource project) { + super(project); + } + + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + Collection actives = graph.syncRequest(new ActiveModels(resource)); + if (actives.size() == 1) + return actives.iterator().next(); + + if (actives.size() == 0) + throw new NoSingleResultException("There are no active models.", actives.size()); + + throw new NoSingleResultException("There are many active models: " + NameUtils.getSafeName(graph, actives), actives.size()); + + } + +}