From 321607bdbd3ca800128d40b5511092f71cb66367 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Wed, 29 Aug 2018 13:56:12 +0300 Subject: [PATCH] Replace instantiations of DatabaseException with more specific gitlab #92 Change-Id: I3030bdb2d02492783bda2ca8118c96b48b734c13 --- .../exception/InvalidVariableException.java | 2 + .../exception/MissingVariableException.java | 9 +-- .../MissingVariableValueException.java | 1 + .../NonWritableVariableException.java | 1 + .../exception/PendingVariableException.java | 1 + .../org/simantics/db/layer0/function/All.java | 21 ++--- .../variable/AbstractChildVariable.java | 6 +- .../AbstractConstantPropertyVariable.java | 6 +- .../db/layer0/variable/AbstractVariable.java | 80 ++++++++++--------- .../db/layer0/variable/SCLValueAccessor.java | 13 +-- .../variable/StandardGraphChildVariable.java | 4 +- .../StandardGraphPropertyVariable.java | 10 ++- ...StandardGraphResourcePropertyVariable.java | 19 +++-- .../layer0/variable/StandardRVIResolver.java | 8 +- .../layer0/variable/ValueProxyVariable.java | 56 +++++++------ .../layer0/variable/VariableRepository.java | 5 +- .../db/layer0/variable/Variables.java | 27 ++++--- .../db/exception/DatabaseException.java | 40 +++++----- .../exception/DatatypeNotFoundException.java | 48 +++++++++++ .../db}/exception/VariableException.java | 10 ++- .../monitor/ResolveMonitorVariable.java | 2 +- .../simantics/modeling/adapters/Removers.java | 2 +- .../loader/ScenegraphLoaderUtils.java | 52 ++++++------ .../spreadsheet/util/SpreadsheetUtils.java | 8 +- .../structural2/StructuralRVIResolver.java | 14 ++-- 25 files changed, 261 insertions(+), 184 deletions(-) create mode 100644 bundles/org.simantics.db/src/org/simantics/db/exception/DatatypeNotFoundException.java rename bundles/{org.simantics.db.layer0/src/org/simantics/db/layer0 => org.simantics.db/src/org/simantics/db}/exception/VariableException.java (86%) diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/InvalidVariableException.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/InvalidVariableException.java index 2af2edcaa..03beab469 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/InvalidVariableException.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/InvalidVariableException.java @@ -1,5 +1,7 @@ package org.simantics.db.layer0.exception; +import org.simantics.db.exception.VariableException; + /** * @author Tuukka Lehtonen */ diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableException.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableException.java index 8d5fe852e..90be7c061 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableException.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableException.java @@ -12,21 +12,16 @@ package org.simantics.db.layer0.exception; import org.simantics.db.Resource; - +import org.simantics.db.exception.VariableException; public class MissingVariableException extends VariableException { private static final long serialVersionUID = -8379218573294565788L; private final Resource resource; - - public MissingVariableException(String message) { - super(message); - this.resource = null; - } public MissingVariableException(String message, Resource resource) { - super(message); + super(message + " " + String.valueOf(resource)); this.resource = resource; } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableValueException.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableValueException.java index eedd4c26a..94b4a5cbf 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableValueException.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/MissingVariableValueException.java @@ -13,6 +13,7 @@ package org.simantics.db.layer0.exception; import org.simantics.db.ReadGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.VariableException; public class MissingVariableValueException extends VariableException { diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/NonWritableVariableException.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/NonWritableVariableException.java index beb0fe01a..475dedbfc 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/NonWritableVariableException.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/NonWritableVariableException.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.simantics.db.layer0.exception; +import org.simantics.db.exception.VariableException; import org.simantics.db.layer0.variable.Variable; /** diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/PendingVariableException.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/PendingVariableException.java index da0e51eec..3972140b9 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/PendingVariableException.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/PendingVariableException.java @@ -12,6 +12,7 @@ package org.simantics.db.layer0.exception; import org.simantics.db.Resource; +import org.simantics.db.exception.VariableException; public class PendingVariableException extends VariableException { diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java index 84cefe37f..991a0500c 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/function/All.java @@ -39,13 +39,16 @@ import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.validation.L0Validations; +import org.simantics.db.exception.AdaptionException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.DoesNotContainValueException; import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.exception.RuntimeDatabaseException; +import org.simantics.db.exception.VariableException; +import org.simantics.db.layer0.exception.InvalidVariableException; +import org.simantics.db.layer0.exception.MissingVariableException; import org.simantics.db.layer0.exception.MissingVariableValueException; import org.simantics.db.layer0.exception.PendingVariableException; -import org.simantics.db.layer0.exception.VariableException; import org.simantics.db.layer0.request.PossibleURI; import org.simantics.db.layer0.request.PropertyInfo; import org.simantics.db.layer0.request.PropertyInfoRequest; @@ -167,7 +170,7 @@ public class All { if(value == null) throw new MissingVariableValueException(variable.getPossibleURI(graph)); return value.getValue(binding); } catch (AdaptException e) { - throw new DatabaseException(e); + throw new AdaptionException("Could not get value for " + context.getURI(graph), e); } } @@ -267,7 +270,7 @@ public class All { try { modifier.apply(graph, context, value, Bindings.getBinding(value.getClass())); } catch (BindingConstructionException e) { - throw new DatabaseException(e); + throw new org.simantics.db.exception.BindingException("",e); } } @@ -1307,14 +1310,14 @@ public class All { } if (variable.parentResource == null) - throw new VariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ")."); + throw new InvalidVariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ")."); try { return graph.getRelatedValue2(variable.parentResource, variable.property.predicate, variable); } catch (NoSingleResultException e) { - throw new MissingVariableValueException(variable.getPossibleURI(graph)); + throw new MissingVariableValueException(variable.getPossibleURI(graph), e); } catch (DoesNotContainValueException e) { - throw new MissingVariableValueException(variable.getPossibleURI(graph)); + throw new MissingVariableValueException(variable.getPossibleURI(graph), e); } } @@ -1330,14 +1333,14 @@ public class All { } if (variable.parentResource == null) - throw new VariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ")."); + throw new MissingVariableException("Variable is not represented by any resource (URI=" + variable.getPossibleURI(graph) + ").", context.getPossibleRepresents(graph)); try { return graph.getRelatedValue2(variable.parentResource, variable.property.predicate, variable); } catch (NoSingleResultException e) { - throw new MissingVariableValueException(variable.getPossibleURI(graph)); + throw new MissingVariableValueException(variable.getPossibleURI(graph), e); } catch (DoesNotContainValueException e) { - throw new MissingVariableValueException(variable.getPossibleURI(graph)); + throw new MissingVariableValueException(variable.getPossibleURI(graph), e); } } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java index 7df218130..11dd941c6 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java @@ -12,6 +12,7 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.uri.UnescapedChildMapOfResource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.exception.MissingVariableValueException; +import org.simantics.db.layer0.exception.NonWritableVariableException; import org.simantics.db.layer0.variable.RVI.RVIPart; import org.simantics.db.layer0.variable.RVI.StringRVIPart; import org.simantics.db.layer0.variable.Variables.Role; @@ -42,9 +43,8 @@ public abstract class AbstractChildVariable extends AbstractVariable { } @Override - public void setValue(WriteGraph graph, Object value, Binding binding) - throws DatabaseException { - throw new DatabaseException("Cannot write value to a child variable."); + public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException { + throw new NonWritableVariableException("Cannot write value to a child variable."); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractConstantPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractConstantPropertyVariable.java index aa665cf61..f2b7ff47b 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractConstantPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractConstantPropertyVariable.java @@ -12,6 +12,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.NonWritableVariableException; import org.simantics.utils.ObjectUtils; abstract public class AbstractConstantPropertyVariable extends AbstractPropertyVariable { @@ -40,9 +41,8 @@ abstract public class AbstractConstantPropertyVariable extends AbstractPropertyV } @Override - public void setValue(WriteGraph graph, Object value, Binding binding) - throws DatabaseException { - throw new DatabaseException("Value is constant."); + public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException { + throw new NonWritableVariableException("Value is constant."); } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java index 53c5fb5b7..00b01cca6 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java @@ -82,7 +82,7 @@ public abstract class AbstractVariable implements Variable { @Override public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("PropertyInfo is not available"); + throw new InvalidVariableException("PropertyInfo is not available"); } @Override @@ -117,7 +117,7 @@ public abstract class AbstractVariable implements Variable { String name = child.getPossiblePropertyValue(graph, Variables.NAME, Bindings.STRING); if(rName.equals(name)) return child; } - throw new DatabaseException("Could not resolve child " + resource); + throw new MissingVariableException("Could not resolve child " + rName, resource); } protected Variable resolveChild(ReadGraph graph, GuidRVIPart part) throws DatabaseException { @@ -130,7 +130,7 @@ public abstract class AbstractVariable implements Variable { String name = child.getPossiblePropertyValue(graph, Variables.NAME, Bindings.STRING); if(rName.equals(name)) return child; } - throw new DatabaseException("Could not resolve child " + resource); + throw new MissingVariableException("Could not resolve child " + rName, resource); } protected Variable resolveProperty(ReadGraph graph, GuidRVIPart part) throws DatabaseException { @@ -203,7 +203,7 @@ public abstract class AbstractVariable implements Variable { Variable parent = getParent(graph); if (parent == null) // TODO: consider using a more suitable exception here to better convey the situation. - throw new MissingVariableException("no parent for variable " + this + " (URI=" + getPossibleURI(graph) + ")"); + throw new MissingVariableException("no parent for variable " + this + " (URI=" + getPossibleURI(graph) + ")", getPossibleRepresents(graph)); RVI base = graph.syncRequest(new VariableRVIRequest(parent)); RVIPart part = getRVIPart(graph); return new RVIBuilder(base).append(part).toRVI(); @@ -213,7 +213,7 @@ public abstract class AbstractVariable implements Variable { protected Variable getDomainProperty(ReadGraph graph, String name) throws DatabaseException { Variable property = getPossibleDomainProperty(graph, name); if(property == null) - throw new MissingVariableException(getIdentifier() + ": Didn't find property " + name + "."); + throw new MissingVariableException(getIdentifier() + ": Didn't find property " + name + ".", getPossibleRepresents(graph)); return property; } @@ -460,17 +460,20 @@ public abstract class AbstractVariable implements Variable { @SuppressWarnings("unchecked") @Override - public T getPropertyValue(ReadGraph graph, String name, Binding binding) - throws DatabaseException { - if(binding instanceof StringBinding) { - StringBinding sb = (StringBinding)binding; + public T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException { + if (binding instanceof StringBinding) { + StringBinding sb = (StringBinding) binding; try { - if(Variables.NAME.equals(name)) return (T)sb.create((String)checkNull(graph, getName(graph))); - if(Variables.LABEL.equals(name)) return (T)sb.create((String)checkNull(graph, getLabel(graph))); - if(Variables.URI.equals(name)) return (T)sb.create((String)checkNull(graph, getURI(graph))); -// if(Variables.SERIALISED.equals(name)) return (T)sb.create((String)checkNull(graph, getSerialized(graph))); - } catch(BindingException e) { - throw new DatabaseException(e); + if (Variables.NAME.equals(name)) + return (T) sb.create((String) checkNull(graph, getName(graph))); + if (Variables.LABEL.equals(name)) + return (T) sb.create((String) checkNull(graph, getLabel(graph))); + if (Variables.URI.equals(name)) + return (T) sb.create((String) checkNull(graph, getURI(graph))); + // if(Variables.SERIALISED.equals(name)) return + // (T)sb.create((String)checkNull(graph, getSerialized(graph))); + } catch (BindingException e) { + throw new org.simantics.db.exception.BindingException("Could not get value for property " + name + " with binding " + binding, e); } } Variable property = getPossibleExtraProperty(graph, name); @@ -478,7 +481,7 @@ public abstract class AbstractVariable implements Variable { return property.getValue(graph, binding); property = getPossibleDomainProperty(graph, name); if(property == null) - throw new MissingVariableException("Didn't find property " + name + " for " + this + "."); + throw new MissingVariableException("Didn't find property " + name + " for " + this + ".", getPossibleRepresents(graph)); return property.getValue(graph, binding); } @@ -499,7 +502,7 @@ public abstract class AbstractVariable implements Variable { if(Variables.URI.equals(name)) return (T)sb.create((String)getURI(graph)); // if(Variables.SERIALISED.equals(name)) return (T)sb.create((String)getSerialized(graph)); } catch(BindingException e) { - throw new DatabaseException(e); + throw new org.simantics.db.exception.BindingException("Could not get property value for " + name + " with binding " + binding, e); } } Variable property = getPossibleExtraProperty(graph, name); @@ -521,7 +524,7 @@ public abstract class AbstractVariable implements Variable { try { setValue(graph, value, Bindings.getBinding(value.getClass())); } catch (BindingConstructionException e) { - throw new DatabaseException(e); + throw new org.simantics.db.exception.BindingException("Could not set " + String.valueOf(value) + " value for " + getRepresents(graph), e); } } @@ -551,7 +554,7 @@ public abstract class AbstractVariable implements Variable { throws DatabaseException { Variable child = getPossibleChild(graph, name); if(child == null) - throw new MissingVariableException(getURI(graph) + ": didn't find child " + name + " for " + getIdentifier() + "."); + throw new MissingVariableException(getURI(graph) + ": didn't find child " + name + " for " + getIdentifier() + ".", getPossibleRepresents(graph)); return child; } @@ -559,7 +562,7 @@ public abstract class AbstractVariable implements Variable { public Variable getProperty(ReadGraph graph, String name) throws DatabaseException { Variable result = getPossibleProperty(graph, name); if(result == null) - throw new MissingVariableException(getClass().getSimpleName() + ": Didn't find property " + name + " for " + getPossibleURI(graph) + "."); + throw new MissingVariableException(getClass().getSimpleName() + ": Didn't find property " + name + " for " + getPossibleURI(graph) + ".", getPossibleRepresents(graph)); return result; } @@ -578,7 +581,7 @@ public abstract class AbstractVariable implements Variable { case '.': { Variable parent = getParent(graph); if(parent == null) - throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ")."); + throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph)); return parent.browse(graph, suffix.substring(1)); } case '#': { @@ -586,7 +589,7 @@ public abstract class AbstractVariable implements Variable { Variable property = getProperty(graph, decodeString(suffix.substring(1, segmentEnd))); if(property == null) - throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ")."); + throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph)); return property.browse(graph, suffix.substring(segmentEnd)); } case '/': { @@ -594,11 +597,11 @@ public abstract class AbstractVariable implements Variable { Variable child = getChild(graph, decodeString(suffix.substring(1, segmentEnd))); if(child == null) - throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ")."); + throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph)); return child.browse(graph, suffix.substring(segmentEnd)); } default: - throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ")."); + throw new MissingVariableException("Didn't find " + suffix + " for " + this + " (" + getPossibleURI(graph) + ").", getPossibleRepresents(graph)); } } @@ -652,7 +655,7 @@ public abstract class AbstractVariable implements Variable { Variable variable = browsePossible(graph, config); if(variable == null) throw new MissingVariableException("Didn't find a variable related to " + - NameUtils.getSafeName(graph, config) + "."); + NameUtils.getSafeName(graph, config) + ".", config); return variable; } @@ -722,7 +725,7 @@ public abstract class AbstractVariable implements Variable { try { binding = Bindings.OBJECT.getContentBinding(value); } catch (BindingException e) { - throw new DatabaseException(e); + throw new org.simantics.db.exception.BindingException("Could not bind variant value " + String.valueOf(value) + " for " + getRepresents(graph), e); } return new Variant(binding, value); } @@ -836,7 +839,7 @@ public abstract class AbstractVariable implements Variable { if(Role.CHILD.equals(grp.getRole())) return resolveChild(graph, grp); else if(Role.PROPERTY.equals(grp.getRole())) return resolveProperty(graph, grp); } - throw new DatabaseException("Unrecognized RVIPart: " + part); + throw new MissingVariableException("Unrecognized RVIPart: " + part, getPossibleRepresents(graph)); } @Override @@ -854,12 +857,12 @@ public abstract class AbstractVariable implements Variable { if(Role.CHILD.equals(grp.getRole())) return resolvePossibleChild(graph, grp); else if(Role.PROPERTY.equals(grp.getRole())) return resolvePossibleProperty(graph, grp); } - throw new DatabaseException("Unrecognized RVIPart: " + part); + throw new MissingVariableException("Unrecognized RVIPart: " + part, getPossibleRepresents(graph)); } @Override public Datatype getDatatype(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("No data type."); + throw new InvalidVariableException("No data type."); } public Binding getDefaultBinding(ReadGraph graph) throws DatabaseException { @@ -905,7 +908,7 @@ public abstract class AbstractVariable implements Variable { @Override public Variable getPredicate(ReadGraph graph) throws DatabaseException { - throw new DatabaseException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph)); + throw new MissingVariableException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph), getPossibleRepresents(graph)); } @Override @@ -916,14 +919,15 @@ public abstract class AbstractVariable implements Variable { return null; } } - - @Override - public Resource getPredicateResource(ReadGraph graph) throws DatabaseException { - Variable predicate = getPredicate(graph); - if(predicate == null) throw new DatabaseException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph)); - return predicate.getRepresents(graph); - } - + + @Override + public Resource getPredicateResource(ReadGraph graph) throws DatabaseException { + Variable predicate = getPredicate(graph); + if (predicate == null) + throw new MissingVariableException(getClass().getSimpleName() + ": No predicate property for " + getPossibleURI(graph), getPossibleRepresents(graph)); + return predicate.getRepresents(graph); + } + @Override public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException { Variable predicate = getPossiblePredicate(graph); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java index 5d4915d94..082caa603 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/SCLValueAccessor.java @@ -5,6 +5,9 @@ import org.simantics.databoard.type.Datatype; import org.simantics.db.ReadGraph; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.DatatypeNotFoundException; +import org.simantics.db.layer0.exception.MissingVariableValueException; +import org.simantics.db.layer0.exception.NonWritableVariableException; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function1; import org.simantics.scl.runtime.function.Function2; @@ -35,7 +38,7 @@ public class SCLValueAccessor implements ValueAccessor { try { return getValue1.apply(context); } catch (Throwable t) { - throw new DatabaseException(t); + throw new MissingVariableValueException("Could not get value for " + String.valueOf(context.getRepresents(graph)), t); } finally { sclContext.put("graph", oldGraph); } @@ -48,7 +51,7 @@ public class SCLValueAccessor implements ValueAccessor { try { return getValue2.apply(context, binding); } catch (Throwable t) { - throw new DatabaseException(t); + throw new MissingVariableValueException("Could not get value for " + String.valueOf(context.getRepresents(graph)) + " with binding " + binding, t); } finally { sclContext.put("graph", oldGraph); } @@ -61,7 +64,7 @@ public class SCLValueAccessor implements ValueAccessor { try { setValue2.apply(context, value); } catch (Throwable t) { - throw new DatabaseException(t); + throw new NonWritableVariableException("Could not write value " + String.valueOf(value) + " for " + String.valueOf(context.getRepresents(graph)), t); } finally { sclContext.put("graph", oldGraph); } @@ -74,7 +77,7 @@ public class SCLValueAccessor implements ValueAccessor { try { setValue3.apply(context, value, binding); } catch (Throwable t) { - throw new DatabaseException(t); + throw new NonWritableVariableException("Could not write value " + String.valueOf(value) + " for " + String.valueOf(context.getRepresents(graph)) + " with binding " + binding, t); } finally { sclContext.put("graph", oldGraph); } @@ -87,7 +90,7 @@ public class SCLValueAccessor implements ValueAccessor { try { return getDatatype.apply(context); } catch (Throwable t) { - throw new DatabaseException(t); + throw new DatatypeNotFoundException("Could not find datatype for " + String.valueOf(context.getRepresents(graph)), t); } finally { sclContext.put("graph", oldGraph); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java index cffd74727..78fff71c2 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphChildVariable.java @@ -12,8 +12,8 @@ import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.exception.AssumptionException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.VariableException; import org.simantics.db.layer0.exception.InvalidVariableException; -import org.simantics.db.layer0.exception.VariableException; import org.simantics.db.layer0.function.All; import org.simantics.db.layer0.request.ClassificationsRequest; import org.simantics.db.layer0.request.VariableURI; @@ -150,7 +150,7 @@ public class StandardGraphChildVariable extends AbstractChildVariable { @Override final public Resource getRepresents(ReadGraph graph) throws DatabaseException { if(resource == null) - throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); + throw new InvalidVariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); return resource; // Layer0X L0X = Layer0X.getInstance(graph); // Resource represents = graph.getPossibleObject(resource, L0X.Represents); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java index 582277c90..2dcb6e00a 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphPropertyVariable.java @@ -17,10 +17,12 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.validation.L0Validations; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.DatatypeNotFoundException; import org.simantics.db.exception.ValidationException; +import org.simantics.db.exception.VariableException; +import org.simantics.db.layer0.exception.InvalidVariableException; import org.simantics.db.layer0.exception.MissingVariableValueException; import org.simantics.db.layer0.exception.PendingVariableException; -import org.simantics.db.layer0.exception.VariableException; import org.simantics.db.layer0.function.All; import org.simantics.db.layer0.request.PropertyInfo; import org.simantics.db.layer0.request.PropertyInfoRequest; @@ -159,7 +161,7 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { @Override public Resource getRepresents(ReadGraph graph) throws DatabaseException { if(represents == null) - throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); + throw new InvalidVariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); return represents; // return graph.getSingleObject(parentResource, property.predicate); } @@ -233,9 +235,9 @@ public class StandardGraphPropertyVariable extends AbstractPropertyVariable { if (type == null) { String uri = this.getPossibleURI(graph); if (uri != null) - throw new DatabaseException("No data type for " + uri); + throw new DatatypeNotFoundException("No data type for " + uri); else - throw new DatabaseException("No data type for " + this.getIdentifier()); + throw new DatatypeNotFoundException("No data type for " + this.getIdentifier()); } return type; diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java index 0159e7ac6..6fa5127db 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardGraphResourcePropertyVariable.java @@ -7,10 +7,13 @@ import org.simantics.db.Resource; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.NoSingleResultException; import org.simantics.db.layer0.exception.MissingVariableValueException; -import org.simantics.db.layer0.exception.VariableException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StandardGraphResourcePropertyVariable extends StandardGraphPropertyVariable { - + + private static final Logger LOGGER = LoggerFactory.getLogger(StandardGraphResourcePropertyVariable.class); + public StandardGraphResourcePropertyVariable(ReadGraph graph, Variable parent, Resource parentResource, Resource property) throws DatabaseException { super(graph, parent, null, parentResource, property); } @@ -18,24 +21,24 @@ public class StandardGraphResourcePropertyVariable extends StandardGraphProperty @Override public T getValue(ReadGraph graph) throws DatabaseException { if (parentResource == null) - throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); + throw new MissingVariableValueException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); try { return (T)graph.getSingleObject(parentResource, property.predicate); } catch (NoSingleResultException e) { - System.err.println("No object for " + parentResource + " " + property); - throw new MissingVariableValueException(getPossibleURI(graph)); + LOGGER.error("No object for " + parentResource + " " + property); + throw new MissingVariableValueException(getPossibleURI(graph), e); } } @Override public T getValue(ReadGraph graph, Binding binding) throws DatabaseException { if (parentResource == null) - throw new VariableException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); + throw new MissingVariableValueException("Variable is not represented by any resource (URI=" + getPossibleURI(graph) + ")."); try { return (T)graph.getSingleObject(parentResource, property.predicate); } catch (NoSingleResultException e) { - System.err.println("No object for " + parentResource + " " + property); - throw new MissingVariableValueException(getPossibleURI(graph)); + LOGGER.error("No object for " + parentResource + " " + property); + throw new MissingVariableValueException(getPossibleURI(graph), e); } } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardRVIResolver.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardRVIResolver.java index b01aeb32b..7c7ba292d 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardRVIResolver.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/StandardRVIResolver.java @@ -40,7 +40,7 @@ public class StandardRVIResolver implements RVIResolver { Variable parent = variable.getParent(graph); if (parent == null) // TODO: consider using a more suitable exception here to better convey the situation. - throw new MissingVariableException("no parent for variable " + variable + " (URI=" + variable.getURI(graph) + ")"); + throw new MissingVariableException("no parent for variable " + variable + " (URI=" + variable.getURI(graph) + ")", variable.getPossibleRepresents(graph)); RVI base = graph.syncRequest(new VariableRVIRequest(parent)); RVIPart part = getRVIPart(graph, variable); return new RVIBuilder(base).append(part).toRVI(); @@ -90,7 +90,7 @@ public class StandardRVIResolver implements RVIResolver { return child; } } - throw new DatabaseException("Could not resolve child " + part); + throw new MissingVariableException("Could not resolve child " + part, variable.getPossibleRepresents(graph)); } public static Variable resolvePropertyDefault(ReadGraph graph, Variable variable, GuidRVIPart part) throws DatabaseException { @@ -102,7 +102,7 @@ public class StandardRVIResolver implements RVIResolver { return child; } } - throw new DatabaseException("Could not resolve property " + part); + throw new MissingVariableException("Could not resolve property " + part, variable.getPossibleRepresents(graph)); } @Override @@ -120,7 +120,7 @@ public class StandardRVIResolver implements RVIResolver { if(Role.CHILD.equals(grp.getRole())) return resolveChild(graph, context, grp); else if(Role.PROPERTY.equals(grp.getRole())) return resolveProperty(graph, context, grp); } - throw new DatabaseException("Unrecognized RVIPart: " + part); + throw new MissingVariableException("Unrecognized RVIPart: " + part, context.getPossibleRepresents(graph)); } } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java index 1f6b18030..d2d4ebef0 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java @@ -12,6 +12,10 @@ import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.InvalidVariableException; +import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.exception.MissingVariableValueException; +import org.simantics.db.layer0.exception.NonWritableVariableException; import org.simantics.db.layer0.request.PropertyInfo; import org.simantics.db.layer0.variable.RVI.RVIPart; import org.simantics.db.layer0.variable.Variables.Role; @@ -40,37 +44,37 @@ public abstract class ValueProxyVariable implements Variable { @Override public T getPropertyValue(ReadGraph graph, String name) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); + throw new MissingVariableValueException("Could not resolve property " + name); } @Override public T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); + throw new MissingVariableValueException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); } @Override public T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); + throw new MissingVariableValueException("Could not resolve property " + name); } @Override public T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); + throw new MissingVariableValueException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); } @Override public T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); + throw new MissingVariableValueException("Could not resolve property " + name); } @Override public T getPropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); + throw new MissingVariableValueException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); } @Override public T getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); + throw new MissingVariableValueException("Could not resolve property " + name); } @Override @@ -102,37 +106,37 @@ public abstract class ValueProxyVariable implements Variable { @Override public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException { - throw new DatabaseException("Not supported"); + throw new NonWritableVariableException("Not supported"); } @Override public void setValue(WriteGraph graph, Object value) throws DatabaseException { - throw new DatabaseException("Not supported"); + throw new NonWritableVariableException("Not supported"); } @Override public void setPropertyValue(WriteGraph graph, String name, Object value, Binding binding) throws DatabaseException { - throw new DatabaseException("Not supported"); + throw new NonWritableVariableException("Not supported"); } @Override public void setPropertyValue(WriteGraph graph, Resource property, Object value, Binding binding) throws DatabaseException { - throw new DatabaseException("Not supported"); + throw new NonWritableVariableException("Not supported"); } @Override public void setPropertyValue(WriteGraph graph, String name, Object value) throws DatabaseException { - throw new DatabaseException("Not supported"); + throw new NonWritableVariableException("Not supported"); } @Override public void setPropertyValue(WriteGraph graph, Resource property, Object value) throws DatabaseException { - throw new DatabaseException("Not supported"); + throw new NonWritableVariableException("Not supported"); } @Override public Variable getChild(ReadGraph graph, String name) throws DatabaseException { - throw new DatabaseException("Could not resolve child " + name); + throw new MissingVariableException("Could not resolve child " + name, getPossibleRepresents(graph)); } @Override @@ -142,12 +146,12 @@ public abstract class ValueProxyVariable implements Variable { @Override public Variable getProperty(ReadGraph graph, String name) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); + throw new MissingVariableException("Could not resolve property " + name, getPossibleRepresents(graph)); } @Override public Variable getProperty(ReadGraph graph, Resource property) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); + throw new MissingVariableException("Could not resolve property " + NameUtils.getSafeName(graph, property, true), getPossibleRepresents(graph)); } @Override @@ -194,7 +198,7 @@ public abstract class ValueProxyVariable implements Variable { public Variable browse(ReadGraph graph, String suffix) throws DatabaseException { if (suffix.isEmpty()) return this; - throw new DatabaseException("Could not browse with suffix '" + suffix + "'"); + throw new MissingVariableException("Could not browse with suffix '" + suffix + "'", getPossibleRepresents(graph)); } @Override @@ -206,7 +210,7 @@ public abstract class ValueProxyVariable implements Variable { @Override public Variable browse(ReadGraph graph, Resource config) throws DatabaseException { - throw new DatabaseException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'"); + throw new MissingVariableException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'", getPossibleRepresents(graph)); } @Override @@ -240,7 +244,7 @@ public abstract class ValueProxyVariable implements Variable { @Override public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException { - throw new DatabaseException("not supported"); + throw new InvalidVariableException("not supported"); } @Override @@ -253,7 +257,7 @@ public abstract class ValueProxyVariable implements Variable { @Override public String getLabel(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("not supported"); + throw new InvalidVariableException("not supported"); } @Override @@ -270,17 +274,17 @@ public abstract class ValueProxyVariable implements Variable { @Override public Variable getPredicate(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("not supported"); + throw new InvalidVariableException("not supported"); } @Override public Variable getPossiblePredicate(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("not supported"); + throw new InvalidVariableException("not supported"); } @Override public Resource getPredicateResource(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("not supported"); + throw new InvalidVariableException("not supported"); } @Override @@ -299,7 +303,7 @@ public abstract class ValueProxyVariable implements Variable { @Override public Resource getRepresents(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("no resource representation"); + throw new InvalidVariableException("no resource representation"); } @Override @@ -309,7 +313,7 @@ public abstract class ValueProxyVariable implements Variable { @Override public Resource getType(ReadGraph graph) throws DatabaseException { - throw new DatabaseException("not supported"); + throw new InvalidVariableException("not supported"); } @Override @@ -319,7 +323,7 @@ public abstract class ValueProxyVariable implements Variable { @Override public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException { - throw new DatabaseException("not supported"); + throw new InvalidVariableException("not supported"); } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableRepository.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableRepository.java index 48062205c..bcb207e9e 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableRepository.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableRepository.java @@ -36,12 +36,11 @@ final public class VariableRepository { return e.getValue().browse(graph, uri.substring(e.getKey().length())); } } - throw new MissingVariableException(uri); + throw new MissingVariableException(uri, null); } - + public static void clear() { repository.clear(); } } - diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java index 5fb0636a0..610e0013c 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/Variables.java @@ -32,7 +32,9 @@ import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.TernaryRead; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.InvalidVariableException; import org.simantics.db.layer0.exception.MissingVariableException; +import org.simantics.db.layer0.exception.MissingVariableValueException; import org.simantics.db.layer0.request.Model; import org.simantics.db.layer0.request.PossibleActiveVariableFromVariable; import org.simantics.db.layer0.request.PossibleVariableIndexRoot; @@ -406,7 +408,8 @@ final public class Variables { public static Variable getContext(ReadGraph graph, Variable variable) throws DatabaseException { Variable context = getPossibleContext(graph, variable); - if(context == null) throw new DatabaseException("No context found for " + variable.getURI(graph)); + if (context == null) + throw new MissingVariableException("No context found for " + variable.getURI(graph), variable.getPossibleRepresents(graph)); else return context; } @@ -425,7 +428,7 @@ final public class Variables { public static String getRVI(ReadGraph graph, Variable variable) throws DatabaseException { Resource realizationResource = getRealization(graph, variable); if (realizationResource == null) - throw new DatabaseException("No realization found for " + variable.getURI(graph)); + throw new InvalidVariableException("No realization found for " + variable.getURI(graph)); return variable.getURI(graph).substring(graph.getURI(realizationResource).length()); } @@ -471,7 +474,8 @@ final public class Variables { public static Variable switchRealization(ReadGraph graph, Variable variable, Resource realization) throws DatabaseException { Resource current = getRealization(graph, variable); - if(current == null) throw new DatabaseException("No current realization found for variable"); + if (current == null) + throw new InvalidVariableException("No current realization found for variable"); return switchRealization(graph, variable, current, realization); } @@ -545,13 +549,13 @@ final public class Variables { } public static String appendRVI(ReadGraph graph, String modelURI, String rvi, Resource configuration) throws DatabaseException { - Layer0 L0 = Layer0.getInstance(graph); String partName = graph.getPossibleRelatedValue(configuration, L0.HasName); - if(partName == null) throw new MissingVariableException("Can not append a child corresponding to " + configuration + " to rvi '" + rvi + "' since there is no name."); + if (partName == null) + throw new MissingVariableException("Can not append a child corresponding to " + configuration + " to rvi '" + + rvi + "' since there is no name.", configuration); String escaped = URIStringUtils.escape(partName); return rvi + "/" + escaped; - } public static boolean isValid(ReadGraph graph, Variable variable) { @@ -627,7 +631,7 @@ final public class Variables { } if (getter.exception != null) - throw new DatabaseException(getter.exception); + throw new MissingVariableValueException("No value for node " + node, getter.exception); return getter.result; } @@ -671,7 +675,8 @@ final public class Variables { public static NodeStructure requestNodeStructure(ReadGraph graph, VariableNode node) throws DatabaseException { NodeStructure value = graph.syncRequest(new NodeStructureRequest(node)); - if (value == null) throw new DatabaseException("External data access error"); + if (value == null) + throw new InvalidVariableException("External data access error " + String.valueOf(node)); if(PENDING_NODE_STRUCTURE == value && graph.getSynchronous()) { // In this case a PENDING value was previously cached but now the value needs to be obtained for real. @@ -680,13 +685,13 @@ final public class Variables { node.support.manager.getRealm().syncExec(getter); } catch (InterruptedException e) { Logger.defaultLogError(e); - throw new DatabaseException("External data access error", e); + throw new InvalidVariableException("External data access error " + String.valueOf(node), e); } if (getter.exception != null) - throw new DatabaseException("External data access error", getter.exception); + throw new InvalidVariableException("External data access error " + String.valueOf(node), getter.exception); if (getter.result == null) - throw new DatabaseException("External data access error"); + throw new InvalidVariableException("External data access error " + String.valueOf(node)); return getter.result; diff --git a/bundles/org.simantics.db/src/org/simantics/db/exception/DatabaseException.java b/bundles/org.simantics.db/src/org/simantics/db/exception/DatabaseException.java index 5a64bd010..591361c9b 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/exception/DatabaseException.java +++ b/bundles/org.simantics.db/src/org/simantics/db/exception/DatabaseException.java @@ -18,25 +18,27 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; /** - * - * A base class for exceptions in org.simantics.db. - * - * There are three classes of DatabaseException - *
    - *
  • ServiceException is a class of serious failures e.g. (connection failure, database corruption) - *
  • ValidationException is a class of exceptions due to invalid semantic graph - *
  • AssumptionException is a class of exceptions due to unsatisfied user assumptions (e.g. user assumes a single result or existence of an adapter) - *
- * - * The resources related to an exception are available for pretty printing uses. - * - * @author Antti Villberg - * @version 0.7 - * @see ValidationException - * @see ServiceException - * @see AssumptionException - * - */ +* +* A base class for exceptions in org.simantics.db. +* +* There are three classes of DatabaseException +*
    +*
  • ServiceException is a class of serious failures e.g. (connection failure, database corruption) +*
  • ValidationException is a class of exceptions due to invalid semantic graph +*
  • AssumptionException is a class of exceptions due to unsatisfied user assumptions (e.g. user assumes a single result or existence of an adapter) +*
  • VariableException is a class of exceptions related to Simantics Variable-interface operations +*
+* +* The resources related to an exception are available for pretty printing uses. +* +* @author Antti Villberg +* @version 0.7 +* @see ValidationException +* @see ServiceException +* @see AssumptionException +* @see VariableException +* +*/ public class DatabaseException extends Exception { private static final long serialVersionUID = -6234485044648476711L; diff --git a/bundles/org.simantics.db/src/org/simantics/db/exception/DatatypeNotFoundException.java b/bundles/org.simantics.db/src/org/simantics/db/exception/DatatypeNotFoundException.java new file mode 100644 index 000000000..593c1fa16 --- /dev/null +++ b/bundles/org.simantics.db/src/org/simantics/db/exception/DatatypeNotFoundException.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2018 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.db.exception; + +import org.simantics.db.Resource; + +/** + * @author Jani Simomaa + * @since 1.36.0 + */ +public class DatatypeNotFoundException extends AssumptionException { + + private static final long serialVersionUID = -5566773896759186602L; + + public DatatypeNotFoundException(Throwable cause) { + super(cause); + } + + public DatatypeNotFoundException(String message, Throwable cause, Resource... rs) { + super(message, cause, rs); + } + + public DatatypeNotFoundException(String message, Resource... resources) { + super(message, resources); + } + + public DatatypeNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public DatatypeNotFoundException(String message, int... args) { + super(message, args); + } + + public DatatypeNotFoundException(String message) { + super(message); + } + +} diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/VariableException.java b/bundles/org.simantics.db/src/org/simantics/db/exception/VariableException.java similarity index 86% rename from bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/VariableException.java rename to bundles/org.simantics.db/src/org/simantics/db/exception/VariableException.java index 4576391e9..64b5b8d7b 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/exception/VariableException.java +++ b/bundles/org.simantics.db/src/org/simantics/db/exception/VariableException.java @@ -9,11 +9,13 @@ * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ -package org.simantics.db.layer0.exception; +package org.simantics.db.exception; -import org.simantics.db.exception.DatabaseException; - -public class VariableException extends DatabaseException { +/** + * @author Tuukka Lehtonen + * + */ +public abstract class VariableException extends DatabaseException { private static final long serialVersionUID = -1479596137621167295L; diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/ResolveMonitorVariable.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/ResolveMonitorVariable.java index 9c55fdfec..ad8216d75 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/ResolveMonitorVariable.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/diagram/monitor/ResolveMonitorVariable.java @@ -18,7 +18,7 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.BinaryRead; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.VariableException; +import org.simantics.db.exception.VariableException; import org.simantics.db.layer0.variable.RVI; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/Removers.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/Removers.java index 90ee3db2f..3d0499612 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/Removers.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/adapters/Removers.java @@ -27,7 +27,7 @@ import org.simantics.db.common.request.PossibleIndexRoot; import org.simantics.db.common.request.PossibleObjectWithType; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.VariableException; +import org.simantics.db.exception.VariableException; import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.layer0.request.PossibleModel; import org.simantics.db.layer0.variable.RVI; diff --git a/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/ScenegraphLoaderUtils.java b/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/ScenegraphLoaderUtils.java index b4b68a002..da1e7d8eb 100644 --- a/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/ScenegraphLoaderUtils.java +++ b/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/ScenegraphLoaderUtils.java @@ -22,7 +22,7 @@ import org.simantics.db.common.request.ResourceRead; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.exception.AssumptionException; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.VariableException; +import org.simantics.db.layer0.exception.InvalidVariableException; import org.simantics.db.layer0.request.VariableName; import org.simantics.db.layer0.request.VariableURI; import org.simantics.db.layer0.variable.Variable; @@ -294,11 +294,13 @@ public class ScenegraphLoaderUtils { } public static Resource getRuntime(ReadGraph graph, Variable context) throws DatabaseException { - SceneGraphContext vc = getContext(graph, context); - if(vc != null) return vc.getRuntime(); - Variable parent = context.getParent(graph); - if(parent == null) throw new DatabaseException("Runtime resource was not found from context Variable."); - return getRuntime(graph, parent); + SceneGraphContext vc = getContext(graph, context); + if (vc != null) + return vc.getRuntime(); + Variable parent = context.getParent(graph); + if (parent == null) + throw new InvalidVariableException("Runtime resource was not found from context Variable. " + context.getURI(graph)); + return getRuntime(graph, parent); } public static SceneGraphContext getContext(ReadGraph graph, Variable context) throws DatabaseException { @@ -382,29 +384,25 @@ public class ScenegraphLoaderUtils { } - public static Variable getVariableSelection(ReadGraph graph, Variable context) throws DatabaseException { - - Variable runtimeVariable = getRuntimeVariable(graph, context); - if (runtimeVariable == null) - throw new VariableException("no runtime variable for context " + context.getURI(graph)); - return runtimeVariable.getPropertyValue(graph, "variable"); - - } - - public static Variable getPossibleVariableSelection(ReadGraph graph, Variable context) throws DatabaseException { - Variable runtimeVariable = getRuntimeVariable(graph, context); - return runtimeVariable == null ? null : (Variable) runtimeVariable.getPossiblePropertyValue(graph, "variable"); - } - - public static Resource getResourceSelection(ReadGraph graph, Variable context) throws DatabaseException { + public static Variable getVariableSelection(ReadGraph graph, Variable context) throws DatabaseException { + Variable runtimeVariable = getRuntimeVariable(graph, context); + if (runtimeVariable == null) + throw new InvalidVariableException("no runtime variable for context " + context.getURI(graph)); + return runtimeVariable.getPropertyValue(graph, "variable"); + } - Variable runtimeVariable = getRuntimeVariable(graph, context); - if (runtimeVariable == null) - throw new VariableException("no runtime variable for context " + context.getURI(graph)); - Resource sel = runtimeVariable.getPropertyValue(graph, "resource"); - return sel; + public static Variable getPossibleVariableSelection(ReadGraph graph, Variable context) throws DatabaseException { + Variable runtimeVariable = getRuntimeVariable(graph, context); + return runtimeVariable == null ? null : (Variable) runtimeVariable.getPossiblePropertyValue(graph, "variable"); + } - } + public static Resource getResourceSelection(ReadGraph graph, Variable context) throws DatabaseException { + Variable runtimeVariable = getRuntimeVariable(graph, context); + if (runtimeVariable == null) + throw new InvalidVariableException("no runtime variable for context " + context.getURI(graph)); + Resource sel = runtimeVariable.getPropertyValue(graph, "resource"); + return sel; + } public static Resource getPossibleResourceSelection(ReadGraph graph, Variable context) throws DatabaseException { diff --git a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/util/SpreadsheetUtils.java b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/util/SpreadsheetUtils.java index e3de813b4..4d6715dc5 100644 --- a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/util/SpreadsheetUtils.java +++ b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/util/SpreadsheetUtils.java @@ -22,7 +22,6 @@ import org.simantics.databoard.binding.error.BindingException; import org.simantics.databoard.binding.mutable.MutableVariant; import org.simantics.databoard.binding.mutable.Variant; import org.simantics.datatypes.utils.BTree; -import org.simantics.datatypes.utils.BTreeUtils; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; @@ -30,8 +29,9 @@ import org.simantics.db.common.request.PossibleChild; import org.simantics.db.common.request.WriteRequest; import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; +import org.simantics.db.exception.AssumptionException; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.VariableException; +import org.simantics.db.exception.VariableException; import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.ProxyVariables; import org.simantics.db.layer0.variable.Variable; @@ -48,8 +48,8 @@ import org.simantics.scl.runtime.function.Function1; import org.simantics.scl.runtime.tuple.Tuple; import org.simantics.spreadsheet.CellEditor; import org.simantics.spreadsheet.CellEditor.Transaction; -import org.simantics.spreadsheet.ClientModel.OperationMode; import org.simantics.spreadsheet.ClientModel; +import org.simantics.spreadsheet.ClientModel.OperationMode; import org.simantics.spreadsheet.Range; import org.simantics.spreadsheet.common.TableCell; import org.simantics.spreadsheet.common.cell.StringCellParser; @@ -660,7 +660,7 @@ public class SpreadsheetUtils { int w = 0; // name + fields int h = 0; // number or rows excluding headers - if(columns < 2) throw new DatabaseException("organizeCells: number of columns needs to be greater than 1"); + if(columns < 2) throw new AssumptionException("organizeCells: number of columns needs to be greater than 1"); for(TableCell cell : cells) { if((cell.column+1)>w) w = cell.column+1; diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java index 8cf61b3e0..672edfca6 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java @@ -127,16 +127,20 @@ public class StructuralRVIResolver extends StandardRVIResolver { @Override protected Variable resolveChild(ReadGraph graph, Variable variable, Resource resource) throws DatabaseException { Collection path = getRVIPath(graph, variable, resource); - if(path == null) throw new MissingVariableException("Didn't find a variable related to " + resource + ".", resource); - for(Resource r : path) variable = variable.browse(graph, r); + if (path == null) + throw new MissingVariableException("Didn't find a variable related to " + resource + ".", resource); + for (Resource r : path) + variable = variable.browse(graph, r); return variable; } - + @Override protected Variable resolveChild(ReadGraph graph, Variable variable, GuidRVIPart part) throws DatabaseException { Collection path = getRVIPath(graph, variable, part); - if(path == null) throw new MissingVariableException("Didn't find a variable related to " + part + "."); - for(Resource r : path) variable = variable.browse(graph, r); + if (path == null) + throw new MissingVariableException("Didn't find a variable related to " + part + ".", variable.getPossibleRepresents(graph)); + for (Resource r : path) + variable = variable.browse(graph, r); return variable; } -- 2.47.1