]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Ignore NoSingleResultException in DependenciesRelation 29/1529/8
authorjsimomaa <jani.simomaa@gmail.com>
Wed, 7 Mar 2018 08:06:29 +0000 (10:06 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 8 Mar 2018 12:31:31 +0000 (14:31 +0200)
Some fixes for NoSingleResultException usage and introducing resultCount
field for more detailed exception messages

refs #7803

Change-Id: Id633dcfee66c44556de3943c5ec4454e9473f6f3

15 files changed:
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/wrapper/DeepSingleOrErrorProcedure.java
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/wrapper/NullSingleOrExceptionProcedure.java
bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/single/wrapper/SingleOrErrorProcedure.java
bundles/org.simantics.db.common/src/org/simantics/db/common/request/SingleObjectWithType.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/SingleObjectProcedure.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/SingleActiveModel.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ConstantChildVariable.java
bundles/org.simantics.db.procore/META-INF/MANIFEST.MF
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/DirectQuerySupportImpl.java
bundles/org.simantics.db/src/org/simantics/db/exception/NoSingleResultException.java
bundles/org.simantics.db/src/org/simantics/db/exception/ResourceNotFoundException.java
bundles/org.simantics.db/src/org/simantics/db/service/DebugSupport.java
bundles/org.simantics.structural2/src/org/simantics/structural2/variables/StandardProceduralChildVariable.java

index b1de8c25de531ed06548e2e20dc429ba94916244..739c03d1ea44f59260c4321b35b46be29e2d5643 100644 (file)
@@ -46,7 +46,7 @@ final public class DeepSingleOrErrorProcedure<Result> {
             if(done.compareAndSet(false, true)) {
                try {
                        if(found.compareAndSet(false, true)) {
             if(done.compareAndSet(false, true)) {
                try {
                        if(found.compareAndSet(false, true)) {
-                                       procedure.exception(graph, new NoSingleResultException("No results."));
+                                       procedure.exception(graph, new NoSingleResultException("No results.", -1));
                        } else {
                                        procedure.execute(graph, result);
                        }
                        } else {
                                        procedure.execute(graph, result);
                        }
@@ -66,7 +66,7 @@ final public class DeepSingleOrErrorProcedure<Result> {
                        // Shall fire exactly once!
                        if(done.compareAndSet(false, true)) {
                                try {
                        // Shall fire exactly once!
                        if(done.compareAndSet(false, true)) {
                                try {
-                                       procedure.exception(graph, new NoSingleResultException(this.result + " and " + result));
+                                       procedure.exception(graph, new NoSingleResultException(this.result + " and " + result, -1));
                                } catch (Throwable t) {
                                Logger.defaultLogError(t);
                                }
                                } catch (Throwable t) {
                                Logger.defaultLogError(t);
                                }
index 183859340a532f81facf26988a519973dd36e4be..d8cfe36072c6ae0c9ec74fc362c84a3e6cef8cad 100644 (file)
@@ -62,7 +62,7 @@ final public class NullSingleOrExceptionProcedure<Result> {
                        // Shall fire exactly once!
                        if(done.compareAndSet(false, true)) {
                                try {
                        // Shall fire exactly once!
                        if(done.compareAndSet(false, true)) {
                                try {
-                                       procedure.exception(graph, new NoSingleResultException(procedure.toString()));
+                                       procedure.exception(graph, new NoSingleResultException(procedure.toString(), -1));
                                } catch (Throwable t) {
                                Logger.defaultLogError(t);
                                }
                                } catch (Throwable t) {
                                Logger.defaultLogError(t);
                                }
index da542b4b356433430493fc62db0886a29c907040..826ca5987ac8aee65627d10c426349033a60859a 100644 (file)
@@ -37,7 +37,7 @@ final public class SingleOrErrorProcedure<Result> extends AsyncMultiProcedureAda
        if(done.compareAndSet(false, true)) {
                try {
                        if(result == null) {
        if(done.compareAndSet(false, true)) {
                try {
                        if(result == null) {
-                                       procedure.exception(graph, new NoSingleResultException("No items " + procedure));
+                                       procedure.exception(graph, new NoSingleResultException("No items " + procedure, 0));
                        } else {
                                procedure.execute(graph, result);
                        }
                        } else {
                                procedure.execute(graph, result);
                        }
@@ -56,7 +56,7 @@ final public class SingleOrErrorProcedure<Result> extends AsyncMultiProcedureAda
                        // Shall fire exactly once!
                        if(done.compareAndSet(false, true)) {
                                try {
                        // Shall fire exactly once!
                        if(done.compareAndSet(false, true)) {
                                try {
-                                       procedure.exception(graph, new NoSingleResultException("Multiple items " + this.result + " and " + result));
+                                       procedure.exception(graph, new NoSingleResultException("Multiple items " + this.result + " and " + result, -1));
                                } catch (Throwable t) {
                                Logger.defaultLogError(t);
                                }
                                } catch (Throwable t) {
                                Logger.defaultLogError(t);
                                }
index ae72985c4679b1dd691dde5c679613a899b239b2..a986034889963bf6eedcdd99ff17fc4c3d9d2aef 100644 (file)
@@ -29,23 +29,25 @@ public final class SingleObjectWithType extends ResourceRead3<Resource> {
     @Override
     public Resource perform(ReadGraph graph) throws DatabaseException {
         Resource result = null;
     @Override
     public Resource perform(ReadGraph graph) throws DatabaseException {
         Resource result = null;
+        int resultCount = 0;
         for (Resource object : graph.getObjects(resource, resource2)) {
             if (graph.isInstanceOf(object, resource3)) {
         for (Resource object : graph.getObjects(resource, resource2)) {
             if (graph.isInstanceOf(object, resource3)) {
-                if (result != null)
-                    throw new NoSingleResultException("More than 1 objects for relation "
-                            + NameUtils.getSafeName(graph, resource2) + " with type "
-                            + NameUtils.getSafeName(graph, resource3) + " at "
-                            + NameUtils.getSafeName(graph, resource));
-
-                result = object;
+                if (result == null) {
+                    result = object;
+                } else {
+                    // okay, too many results but lets calculate for debug
+                    resultCount++;
+                }
             }
         }
             }
         }
-
-        if (result == null)
-            throw new NoSingleResultException("No objects for relation "
+        
+        if (resultCount != 1) {
+            String reason = resultCount == 0 ? "No objects for relation " : "Multiple objects for relation ";
+            throw new NoSingleResultException(reason
                     + NameUtils.getSafeName(graph, resource2) + " with type "
                     + NameUtils.getSafeName(graph, resource3) + " at "
                     + NameUtils.getSafeName(graph, resource2) + " with type "
                     + NameUtils.getSafeName(graph, resource3) + " at "
-                    + NameUtils.getSafeName(graph, resource));
+                    + NameUtils.getSafeName(graph, resource), resultCount);
+        }
 
         return result;
     }
 
         return result;
     }
index ff127a09b93fae51ac2c3793e7169f417b444d5e..614a96df3c47d29ea45e249dfb10df9653aaedf4 100644 (file)
@@ -283,7 +283,7 @@ public class ReadGraphImpl implements ReadGraph {
 
                } catch (ResourceNotFoundException e) {
 
 
                } catch (ResourceNotFoundException e) {
 
-                       throw new ResourceNotFoundException(e);
+                       throw new ResourceNotFoundException(id, e);
 
                } catch (ValidationException e) {
 
 
                } catch (ValidationException e) {
 
@@ -347,7 +347,7 @@ public class ReadGraphImpl implements ReadGraph {
 
                } catch (ResourceNotFoundException e) {
 
 
                } catch (ResourceNotFoundException e) {
 
-                       throw new ResourceNotFoundException(e);
+                       throw new ResourceNotFoundException(id, e);
 
                } catch (ServiceException 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 {
                if( relation == null) throw new IllegalArgumentException("relation can not be null");
 
                try {
-
                        int single = processor.getSingleObject(this, subject, relation);
                        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);
                        return processor.querySupport.getResource(single);
-
                } catch (NoSingleResultException e) {
                } 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) {
                } catch (DatabaseException e) {
-                   
                        throw new ServiceException(e);
                        throw new ServiceException(e);
-                       
                } 
                } 
-               
        }
 
        @Override
        }
 
        @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);
                assert (subject != null);
                assert (relation != null);
-
                try {
                try {
-
                        Collection<Statement> statements = getStatements(subject, relation);
                        Collection<Statement> 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
        }
 
        @Override
-       final public Resource getSingleType(final Resource subject) throws NoSingleResultException,
-                       ServiceException {
-
+       final public Resource getSingleType(final Resource subject) throws NoSingleResultException, ServiceException {
                assert (subject != null);
                assert (subject != null);
-
                try {
                try {
-
                        ArrayList<Resource> principalTypes = (ArrayList<Resource>)getPrincipalTypes(subject);
                        ArrayList<Resource> principalTypes = (ArrayList<Resource>)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) {
                } catch (ServiceException e) {
-
                        throw new ServiceException(e);
                        throw new ServiceException(e);
-
                } 
                } 
-
        }
 
        @Override
        }
 
        @Override
@@ -988,23 +962,10 @@ public class ReadGraphImpl implements ReadGraph {
                assert (baseType != null);
 
                try {
                assert (baseType != null);
 
                try {
-
                        return syncRequest(new SingleType(subject, baseType));
                        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) {
                } catch (DatabaseException e) {
-
-                       throw new ServiceException(INTERNAL_ERROR_STRING, e);
-
+                   throw new NoSingleResultException("subject=" + subject + ", baseType=" + baseType, 0, e);
                }
                }
-
        }
 
        @Override
        }
 
        @Override
@@ -1142,16 +1103,11 @@ public class ReadGraphImpl implements ReadGraph {
                assert (relation != null);
 
                try {
                assert (relation != null);
 
                try {
-
                        Resource object = getSingleObject(subject, relation);
                        return getValue(object);
                        Resource object = getSingleObject(subject, relation);
                        return getValue(object);
-                       
                } catch (NoSingleResultException e) {
                } 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) {
                } catch (DoesNotContainValueException e) {
-
                        try {
                                Layer0 L0 = processor.getL0(this);
                                Resource object = getPossibleObject(subject, relation);
                        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 {
                                        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 {
                                        }
                                } 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 (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) {
                } catch (ServiceException e) {
-
                        throw new ServiceException(e);
                        throw new ServiceException(e);
-
-               } 
-               
+               }
        }
 
     @Override
        }
 
     @Override
@@ -1186,16 +1138,11 @@ public class ReadGraphImpl implements ReadGraph {
         assert (relation != null);
 
         try {
         assert (relation != null);
 
         try {
-
             Resource object = getSingleObject(subject, relation);
             return getVariantValue(object);
             Resource object = getSingleObject(subject, relation);
             return getVariantValue(object);
-            
         } catch (NoSingleResultException e) {
         } 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) {
         } catch (DoesNotContainValueException e) {
-
             try {
                 Layer0 L0 = processor.getL0(this);
                 Resource object = getPossibleObject(subject, relation);
             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 {
                     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 {
                     }
                 } 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 (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) {
         } catch (ServiceException e) {
-
             throw new ServiceException(e);
             throw new ServiceException(e);
-
         } 
         } 
-        
     }
     
        @Override
     }
     
        @Override
@@ -1230,40 +1173,23 @@ public class ReadGraphImpl implements ReadGraph {
                assert (relation != null);
 
                try {
                assert (relation != null);
 
                try {
-
                        Resource object = getSingleObject(subject, relation);
                        return getValue(object, binding);
                        Resource object = getSingleObject(subject, relation);
                        return getValue(object, binding);
-
                } catch (NoSingleResultException e) {
                } catch (NoSingleResultException e) {
-
                    String message = "";
                    String message = "";
-                   
                    try {
                    try {
-                   
                    String subjectName = NameUtils.getSafeName(this, subject, true);
                    String relationName = NameUtils.getSafeName(this, relation, true);
                    message = "Subject: " + subjectName + ", Relation: " + relationName;
                    String subjectName = NameUtils.getSafeName(this, subject, true);
                    String relationName = NameUtils.getSafeName(this, relation, true);
                    message = "Subject: " + subjectName + ", Relation: " + relationName;
-
                    } catch (DatabaseException e2) {
                        
                    }
                    } catch (DatabaseException e2) {
                        
                    }
-
-            throw new NoSingleResultException(message);
-                   
+            throw new NoSingleResultException(message, e.getResultCount(), e);
                } catch (DoesNotContainValueException e) {
                } catch (DoesNotContainValueException e) {
-
                        throw new DoesNotContainValueException(e);
                        throw new DoesNotContainValueException(e);
-
                } catch (ServiceException e) {
                } catch (ServiceException e) {
-
                        throw new ServiceException(e);
                        throw new ServiceException(e);
-
-               } catch (DatabaseException e) {
-
-                       throw new ServiceException(INTERNAL_ERROR_STRING, e);
-
                }
                }
-
        }
 
        @Override
        }
 
        @Override
index 06823b09f5c95795a22e8549d368c80274bc41ca..662d2d32dfc49cd53c42dafbfa5344e988ff770e 100644 (file)
@@ -20,7 +20,7 @@ public class SingleObjectProcedure implements IntProcedure {
        public void execute(ReadGraphImpl graph, int i) {
                Resource resource = processor.querySupport.getResource(i);
                if(result != null) {
        public void execute(ReadGraphImpl graph, int i) {
                Resource resource = processor.querySupport.getResource(i);
                if(result != null) {
-                       exception = new NoSingleResultException("");
+                       exception = new NoSingleResultException("", 2);
                } else {
                        result = resource;
                }
                } else {
                        result = resource;
                }
@@ -28,7 +28,7 @@ public class SingleObjectProcedure implements IntProcedure {
 
        @Override
        public void finished(ReadGraphImpl graph) {
 
        @Override
        public void finished(ReadGraphImpl graph) {
-               if(result == null) exception = new NoSingleResultException("");
+               if(result == null) exception = new NoSingleResultException("", 0);
        }
 
        @Override
        }
 
        @Override
index 333f3771c843c636e2838b51b0d32488edf6e7fa..fc32222084c0f7e08509c152a882b893e7bd5b61 100644 (file)
@@ -43,6 +43,7 @@ import org.simantics.db.common.request.UnaryRead;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.event.ChangeListener;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.event.ChangeListener;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.layer0.adapter.GenericRelation;
 import org.simantics.db.layer0.adapter.GenericRelationIndex;
 import org.simantics.db.layer0.genericrelation.DependencyChanges.Change;
 import org.simantics.db.layer0.adapter.GenericRelation;
 import org.simantics.db.layer0.adapter.GenericRelationIndex;
 import org.simantics.db.layer0.genericrelation.DependencyChanges.Change;
@@ -151,7 +152,13 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic
 
                                @Override
                                public void exception(AsyncReadGraph graph, Throwable throwable) {
 
                                @Override
                                public void exception(AsyncReadGraph graph, Throwable throwable) {
-                                       LOGGER.error("Could not compile for resource {}", resource, throwable);
+                                   if (throwable instanceof NoSingleResultException) {
+                                       // Ignore
+                                       if (LOGGER.isDebugEnabled())
+                                           LOGGER.debug("Could not compile for resource {}", resource, throwable);
+                                   } else {
+                                       LOGGER.error("Could not compile for resource {}", resource, throwable);
+                                   }
                                }
 
                        });
                                }
 
                        });
index 411388f7e89c7ff4df1e84a52611acd3acff820b..bff9a22137a80489369f09f144504421f2e7bf5f 100644 (file)
@@ -25,9 +25,9 @@ public class SingleActiveModel extends ResourceRead<Resource> {
             return actives.iterator().next();
 
         if (actives.size() == 0) 
             return actives.iterator().next();
 
         if (actives.size() == 0) 
-               throw new NoSingleResultException("There are no active models."); 
+               throw new NoSingleResultException("There are no active models.", actives.size()); 
 
 
-       throw new NoSingleResultException("There are many active models: " + NameUtils.getSafeName(graph, actives)); 
+       throw new NoSingleResultException("There are many active models: " + NameUtils.getSafeName(graph, actives), actives.size()); 
         
     }
 
         
     }
 
index f5bdd79360644e5b291a07bc7eff19fce1a90ab6..918101fe25d9deef50ad5231192c465630d0a9e2 100644 (file)
@@ -125,7 +125,7 @@ public class ConstantChildVariable extends AbstractChildVariable {
        Resource type = getPossibleType(graph, baseType);
        if (type != null)
                return type;
        Resource type = getPossibleType(graph, baseType);
        if (type != null)
                return type;
-       throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type");
+       throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type", -1);
     }
 
     @Override
     }
 
     @Override
index 107581f6b0a5db6476e3ae0c9fa34811ddc53ea7..9a5daf404f8ab1deebfdcd5d43ae0632e24e29b6 100644 (file)
@@ -10,7 +10,8 @@ Require-Bundle: org.apache.log4j;visibility:=reexport,
  gnu.trove3;bundle-version="3.0.0",
  org.simantics.db.impl;bundle-version="0.8.0",
  org.simantics.lz4,
  gnu.trove3;bundle-version="3.0.0",
  org.simantics.db.impl;bundle-version="0.8.0",
  org.simantics.lz4,
- org.simantics.compressions
+ org.simantics.compressions,
+ org.slf4j.api
 Export-Package: fi.vtt.simantics.procore,
  fi.vtt.simantics.procore.internal,
  org.simantics.db.procore,
 Export-Package: fi.vtt.simantics.procore,
  fi.vtt.simantics.procore.internal,
  org.simantics.db.procore,
index a0f6c1d1eb3cd437a65a340083c4d1ed1f6c241b..7f27a0261a0dd97f45cca02e79da1e5805fcd2af 100644 (file)
@@ -8,6 +8,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure;
 import org.simantics.db.common.procedure.wrapper.SyncToAsyncProcedure;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.NoSingleResultException;
 import org.simantics.db.impl.ClusterI;
 import org.simantics.db.impl.ClusterI.ClusterTypeEnum;
 import org.simantics.db.impl.ForEachObjectContextProcedure;
 import org.simantics.db.impl.ClusterI;
 import org.simantics.db.impl.ClusterI.ClusterTypeEnum;
 import org.simantics.db.impl.ForEachObjectContextProcedure;
@@ -30,9 +31,13 @@ import org.simantics.db.procore.cluster.ResourceTableSmall;
 import org.simantics.db.procore.cluster.ValueTableSmall;
 import org.simantics.db.request.AsyncRead;
 import org.simantics.db.service.DirectQuerySupport;
 import org.simantics.db.procore.cluster.ValueTableSmall;
 import org.simantics.db.request.AsyncRead;
 import org.simantics.db.service.DirectQuerySupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DirectQuerySupportImpl implements DirectQuerySupport {
 
 
 public class DirectQuerySupportImpl implements DirectQuerySupport {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DirectQuerySupportImpl.class);
+
        final private SessionImplSocket session;
        
        DirectQuerySupportImpl(SessionImplSocket session) {
        final private SessionImplSocket session;
        
        DirectQuerySupportImpl(SessionImplSocket session) {
@@ -775,7 +780,7 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                        int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
                        if(so == 0) {
                                if(result == 0) {
                        int so = cluster.getSingleObject(subject, procedure, session.clusterTranslator);
                        if(so == 0) {
                                if(result == 0) {
-                                       procedure.exception(graph, new DatabaseException("No objects " + subject + " " + procedure.predicateKey));
+                                       procedure.exception(graph, new NoSingleResultException("No objects " + subject + " " + procedure.predicateKey, result));
 //                                     graph.dec();
                                } else {
                                        getValue4(graph, cluster, result, context, procedure);
 //                                     graph.dec();
                                } else {
                                        getValue4(graph, cluster, result, context, procedure);
@@ -784,13 +789,13 @@ public class DirectQuerySupportImpl implements DirectQuerySupport {
                                if(result == 0) {
                                        getValue4(graph, cluster, so, context, procedure);
                                } else {
                                if(result == 0) {
                                        getValue4(graph, cluster, so, context, procedure);
                                } else {
-                                       procedure.exception(graph, new DatabaseException("Multiple objects"));
+                                       procedure.exception(graph, new NoSingleResultException("Multiple objects for " + subject + " " + procedure.predicateKey, result));
 //                                     graph.dec();
                                }
                        }
 
                } catch (DatabaseException e) {
 //                                     graph.dec();
                                }
                        }
 
                } catch (DatabaseException e) {
-                       e.printStackTrace();
+                       LOGGER.error("Could not compute related value for subject {} with predicate {}", subject, procedure.predicateKey);
                }
                
        }
                }
                
        }
index 8c3e9dbe3ff0e0dfc6d5e537d06a4d4ffc44fdd5..500964242d1a9db2724a6f567777ff2d9debd02b 100644 (file)
@@ -17,32 +17,29 @@ public class NoSingleResultException extends AssumptionException {
 
     private static final long serialVersionUID = 1647209154838034514L;
 
 
     private static final long serialVersionUID = 1647209154838034514L;
 
-    public NoSingleResultException(NoSingleResultException cause) {
-        super(cause.getMessage());
-    }
-    
-    public NoSingleResultException(DatabaseException cause) {
-        super(cause.getMessage());
-    }
+    private final int resultCount;
 
 
-    public NoSingleResultException(String message, Throwable cause) {
-        super(message, cause);
+    public NoSingleResultException(String message, int resultCount, Throwable cause) {
+        super(message + " [resultCount=" + resultCount + "]", cause);
+        this.resultCount = resultCount;
     }
 
     }
 
-    public NoSingleResultException(String message, int ... rs) {
-        super(message, rs);
-    }
-    
-    public NoSingleResultException(String message) {
-        super(message);
+    public NoSingleResultException(String message, int resultCount, int ... rs) {
+        super(message + " [resultCount=" + resultCount + "]", rs);
+        this.resultCount = resultCount;
     }
 
     }
 
-    public NoSingleResultException(String message, DatabaseException cause) {
-        super(message, cause);
+    public NoSingleResultException(String message, int resultCount) {
+        super(message + " [resultCount=" + resultCount + "]");
+        this.resultCount = resultCount;
     }
 
     }
 
-    public NoSingleResultException(String message, Resource ... resources) {
-        super(message, resources);
+    public NoSingleResultException(String message, int resultCount, Resource ... resources) {
+        super(message + " [resultCount=" + resultCount + "]", resources);
+        this.resultCount = resultCount;
     }
 
     }
 
+    public int getResultCount() {
+        return resultCount;
+    }
 }
 }
index 63ad77f86f9f5161744fb0642da0aaf299a8ab10..f883cf2df256b768bf868cc5fb76c94bef04245d 100644 (file)
@@ -15,16 +15,12 @@ public class ResourceNotFoundException extends AssumptionException {
 
     private static final long serialVersionUID = 1647209154838034514L;
 
 
     private static final long serialVersionUID = 1647209154838034514L;
 
-    public ResourceNotFoundException(ResourceNotFoundException cause) {
-        super(cause.getMessage());
-    }
-
     public ResourceNotFoundException(long id) {
         super("Could not find [" + id + "].");
     }
 
     public ResourceNotFoundException(long id, Throwable cause) {
     public ResourceNotFoundException(long id) {
         super("Could not find [" + id + "].");
     }
 
     public ResourceNotFoundException(long id, Throwable cause) {
-        super("Could not find [" + id + "].");
+        super("Could not find [" + id + "].", cause);
     }
 
     public ResourceNotFoundException(String uri) {
     }
 
     public ResourceNotFoundException(String uri) {
@@ -34,9 +30,5 @@ public class ResourceNotFoundException extends AssumptionException {
     public ResourceNotFoundException(String uri, Throwable cause) {
         super("Could not find <" + uri + ">.", cause);
     }
     public ResourceNotFoundException(String uri, Throwable cause) {
         super("Could not find <" + uri + ">.", cause);
     }
-    
-    public DatabaseException newStack() {
-       return new ResourceNotFoundException(this);
-    }
 
 }
 
 }
index d3cfd364d24fd268d2b8363f7f4fcf618df05d54..c43138025180af71a50cc258573a4ec2c4cc13b7 100644 (file)
@@ -7,6 +7,5 @@ public interface DebugSupport {
 
        <T> T query(WriteGraph graph, String command);
        <T> T query(Session session, String command);
 
        <T> T query(WriteGraph graph, String command);
        <T> T query(Session session, String command);
-       
-       
+
 }
 }
index a5b50f6f36bc5dc7f1368ff0acc80d9ea4a46e23..f133adee02e3c783b7e7fe5b8dc12ef93a6a4d5a 100644 (file)
@@ -271,7 +271,7 @@ public class StandardProceduralChildVariable extends AbstractChildVariable {
        public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
                if (graph.isInheritedFrom(type, baseType))
                        return type;
        public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
                if (graph.isInheritedFrom(type, baseType))
                        return type;
-               throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type");
+               throw new NoSingleResultException("variable " + getPossibleURI(graph) + " has no type", -1);
        }
        
        @Override
        }
        
        @Override