]> source.dussan.org Git - sonarqube.git/commitdiff
JpaDatabaseSession: Don't log and throw NonUniqueResultException - just throw
authorEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 8 Apr 2011 07:47:45 +0000 (11:47 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 8 Apr 2011 07:54:46 +0000 (11:54 +0400)
sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java

index 12c0f7c7a88ff3297503d28ed250ee7ed69c4691..09fb4894c8816153d448bac23bf24d7e977459db 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.jpa.session;
 
 import org.apache.commons.lang.StringUtils;
-import org.slf4j.LoggerFactory;
 import org.sonar.api.database.DatabaseSession;
 
 import java.util.*;
@@ -207,13 +206,10 @@ public class JpaDatabaseSession extends DatabaseSession {
       return getSingleResult(getQueryForCriterias(entityClass, true, criterias), (T) null);
 
     } catch (NonUniqueResultException ex) {
-      /*
-       * TODO Log and throw is anti-pattern ( see http://today.java.net/article/2006/04/04/exception-handling-antipatterns#logAndThrow ),
-       * but NonUniqueResultException doesn't have a constructor with cause
-       */
-      LoggerFactory.getLogger(JpaDatabaseSession.class).warn("NonUniqueResultException on entity {} with criterias : {}",
-          entityClass.getSimpleName(), StringUtils.join(criterias, ","));
-      throw ex;
+      NonUniqueResultException e = new NonUniqueResultException("Expected single result for entitiy " + entityClass.getSimpleName()
+          + " with criterias : " + StringUtils.join(criterias, ","));
+      e.initCause(ex);
+      throw e;
     }
   }