X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fgraph%2FReadGraphImpl.java;h=614a96df3c47d29ea45e249dfb10df9653aaedf4;hp=ff127a09b93fae51ac2c3793e7169f417b444d5e;hb=bc5e6cb19f6af5f67bc5cfaad7d602841b8fdd0b;hpb=91682baa9a8252390f09b80fd724f47e5957b234 diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index ff127a09b..614a96df3 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -283,7 +283,7 @@ public class ReadGraphImpl implements ReadGraph { } catch (ResourceNotFoundException e) { - throw new ResourceNotFoundException(e); + throw new ResourceNotFoundException(id, e); } catch (ValidationException e) { @@ -347,7 +347,7 @@ public class ReadGraphImpl implements ReadGraph { } catch (ResourceNotFoundException e) { - throw new ResourceNotFoundException(e); + throw new ResourceNotFoundException(id, e); } catch (ServiceException e) { @@ -900,83 +900,57 @@ public class ReadGraphImpl implements ReadGraph { if( relation == null) throw new IllegalArgumentException("relation can not be null"); try { - int single = processor.getSingleObject(this, subject, relation); - if(single == 0) throw new NoSingleResultException("subject=" + subject + " relation="+relation); + if (single == 0) { + if (EMPTY_RESOURCE_CHECK) { + if (!hasStatement(subject)) { + throw new EmptyResourceException("Resource " + debugString(subject)); + } + } + throw new NoSingleResultException("No single object for subject " + debugString(subject) + + " and relation " + debugString(relation), single); + } return processor.querySupport.getResource(single); - } catch (NoSingleResultException e) { - - if(EMPTY_RESOURCE_CHECK) { - if(!hasStatement(subject)) throw new EmptyResourceException("Resource " + debugString(subject)); - } - - throw new NoSingleResultException("No single object for subject " - + debugString(subject) + " and relation " - + debugString(relation), e); - + throw e; } catch (DatabaseException e) { - throw new ServiceException(e); - } - } @Override - final public Statement getSingleStatement(final Resource subject, - final Resource relation) throws NoSingleResultException, - ManyObjectsForFunctionalRelationException, ServiceException { - + final public Statement getSingleStatement(final Resource subject, final Resource relation) throws NoSingleResultException, ManyObjectsForFunctionalRelationException, ServiceException { assert (subject != null); assert (relation != null); - try { - Collection statements = getStatements(subject, relation); - if(statements.size() == 1) return statements.iterator().next(); - else throw new NoSingleResultException(""); - - } catch (NoSingleResultException e) { - - if(EMPTY_RESOURCE_CHECK) { - if(!hasStatement(subject)) throw new EmptyResourceException("Resource " + debugString(subject)); - } - - throw new NoSingleResultException("No single statement for subject " - + debugString(subject) + " and relation " - + debugString(relation), e); - - } catch (DatabaseException e) { - - throw new ServiceException(e); - - } - + if (statements.size() == 1) { + return statements.iterator().next(); + } else { + if (EMPTY_RESOURCE_CHECK) + if (!hasStatement(subject)) + throw new EmptyResourceException("Resource " + debugString(subject)); + throw new NoSingleResultException("No single statement for subject " + debugString(subject) + + " and relation " + debugString(relation), statements.size()); + } + } catch (ServiceException e) { + throw new ServiceException(e); + } } @Override - final public Resource getSingleType(final Resource subject) throws NoSingleResultException, - ServiceException { - + final public Resource getSingleType(final Resource subject) throws NoSingleResultException, ServiceException { assert (subject != null); - try { - ArrayList principalTypes = (ArrayList)getPrincipalTypes(subject); - if(principalTypes.size() == 1) return principalTypes.get(0); - else throw new NoSingleResultException(""); - - } catch (NoSingleResultException e) { - - throw new NoSingleResultException(e); - + if (principalTypes.size() == 1) { + return principalTypes.get(0); + } else { + throw new NoSingleResultException("No single type for subject " + debugString(subject), principalTypes.size()); + } } catch (ServiceException e) { - throw new ServiceException(e); - } - } @Override @@ -988,23 +962,10 @@ public class ReadGraphImpl implements ReadGraph { assert (baseType != null); try { - return syncRequest(new SingleType(subject, baseType)); - - } catch (NoSingleResultException e) { - - throw new NoSingleResultException(new NoSingleResultException("subject=" + subject + ", baseType=" + baseType, e)); - - } catch (ServiceException e) { - - throw new ServiceException(e); - } catch (DatabaseException e) { - - throw new ServiceException(INTERNAL_ERROR_STRING, e); - + throw new NoSingleResultException("subject=" + subject + ", baseType=" + baseType, 0, e); } - } @Override @@ -1142,16 +1103,11 @@ public class ReadGraphImpl implements ReadGraph { assert (relation != null); try { - Resource object = getSingleObject(subject, relation); return getValue(object); - } catch (NoSingleResultException e) { - - throw new NoSingleResultException(e); - + throw new NoSingleResultException("No single value found for subject " + debugString(subject) + " and relation " + debugString(relation), e.getResultCount(), e); } catch (DoesNotContainValueException e) { - try { Layer0 L0 = processor.getL0(this); Resource object = getPossibleObject(subject, relation); @@ -1159,23 +1115,19 @@ public class ReadGraphImpl implements ReadGraph { if(isInstanceOf(object, L0.Literal)) { throw new DoesNotContainValueException(e); } else { - throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)"); + throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)", e); } } else { - throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value"); + throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value", e); } } catch (DoesNotContainValueException e2) { throw e2; } catch (DatabaseException e2) { throw new InternalException("The client failed to analyse the cause of the following exception", e); } - } catch (ServiceException e) { - throw new ServiceException(e); - - } - + } } @Override @@ -1186,16 +1138,11 @@ public class ReadGraphImpl implements ReadGraph { assert (relation != null); try { - Resource object = getSingleObject(subject, relation); return getVariantValue(object); - } catch (NoSingleResultException e) { - - throw new NoSingleResultException(e); - + throw new NoSingleResultException("No single object for subject " + debugString(subject) + " and relation " + debugString(relation), e.getResultCount(), e); } catch (DoesNotContainValueException e) { - try { Layer0 L0 = processor.getL0(this); Resource object = getPossibleObject(subject, relation); @@ -1203,23 +1150,19 @@ public class ReadGraphImpl implements ReadGraph { if(isInstanceOf(object, L0.Literal)) { throw new DoesNotContainValueException(e); } else { - throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)"); + throw new InvalidLiteralException("The object " + object + " is not an instance of L0.Literal (use getRelatedValue2 instead)", e); } } else { - throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value"); + throw new DoesNotContainValueException("The object " + object + " is not an instance of L0.Value", e); } } catch (DoesNotContainValueException e2) { throw e2; } catch (DatabaseException e2) { throw new InternalException("The client failed to analyse the cause of the following exception", e); } - } catch (ServiceException e) { - throw new ServiceException(e); - } - } @Override @@ -1230,40 +1173,23 @@ public class ReadGraphImpl implements ReadGraph { assert (relation != null); try { - Resource object = getSingleObject(subject, relation); return getValue(object, binding); - } catch (NoSingleResultException e) { - String message = ""; - try { - String subjectName = NameUtils.getSafeName(this, subject, true); String relationName = NameUtils.getSafeName(this, relation, true); message = "Subject: " + subjectName + ", Relation: " + relationName; - } catch (DatabaseException e2) { } - - throw new NoSingleResultException(message); - + throw new NoSingleResultException(message, e.getResultCount(), e); } catch (DoesNotContainValueException e) { - throw new DoesNotContainValueException(e); - } catch (ServiceException e) { - throw new ServiceException(e); - - } catch (DatabaseException e) { - - throw new ServiceException(INTERNAL_ERROR_STRING, e); - } - } @Override