[PATCH 2 of 2] Fixed condition for Query.list result (checking isEmpty added)

Wald Commits scm-commit at wald.intevation.org
Mon May 28 10:57:24 CEST 2018


# HG changeset patch
# User mschaefer
# Date 1527497817 -7200
# Node ID 32dd7e761e4e6374a885064e3abae67c32316c29
# Parent  82917e414d7610deb44261cd4bdfb98b9b2df270
Fixed condition for Query.list result (checking isEmpty added)

diff -r 82917e414d76 -r 32dd7e761e4e backend/src/main/java/org/dive4elements/river/model/BedHeight.java
--- a/backend/src/main/java/org/dive4elements/river/model/BedHeight.java	Mon May 28 10:54:41 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/BedHeight.java	Mon May 28 10:56:57 2018 +0200
@@ -240,7 +240,7 @@
 
         final List<BedHeight> singles = query.list();
 
-        return singles != null ? singles.get(0) : null;
+        return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null;
     }
 
     public static BedHeight getBedHeightByDescription(final River river, final String description) {
@@ -253,7 +253,7 @@
 
         final List<BedHeight> singles = query.list();
 
-        return singles != null ? singles.get(0) : null;
+        return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null;
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
\ No newline at end of file
diff -r 82917e414d76 -r 32dd7e761e4e backend/src/main/java/org/dive4elements/river/model/sinfo/FlowDepthColumn.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/FlowDepthColumn.java	Mon May 28 10:54:41 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/FlowDepthColumn.java	Mon May 28 10:56:57 2018 +0200
@@ -122,6 +122,6 @@
         final Query query = session.createQuery("FROM FlowDepthColumn WHERE id=:id");
         query.setParameter("id", id);
         final List<FlowDepthColumn> rows = query.list();
-        return (rows != null) ? rows.get(0) : null;
+        return ((rows != null) && !rows.isEmpty()) ? rows.get(0) : null;
     }
 }
diff -r 82917e414d76 -r 32dd7e761e4e backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java	Mon May 28 10:54:41 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/Tkh.java	Mon May 28 10:56:57 2018 +0200
@@ -237,6 +237,6 @@
         final Query query = session.createQuery("FROM Tkh WHERE id=:id");
         query.setParameter("id", id);
         final List<Tkh> rows = query.list();
-        return (rows != null) ? rows.get(0) : null;
+        return ((rows != null) && !rows.isEmpty()) ? rows.get(0) : null;
     }
 }
\ No newline at end of file
diff -r 82917e414d76 -r 32dd7e761e4e backend/src/main/java/org/dive4elements/river/model/sinfo/TkhColumn.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/TkhColumn.java	Mon May 28 10:54:41 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/TkhColumn.java	Mon May 28 10:56:57 2018 +0200
@@ -116,6 +116,6 @@
         final Query query = session.createQuery("FROM TkhColumn WHERE id=:id");
         query.setParameter("id", id);
         final List<TkhColumn> rows = query.list();
-        return (rows != null) ? rows.get(0) : null;
+        return ((rows != null) && !rows.isEmpty()) ? rows.get(0) : null;
     }
 }


More information about the Dive4Elements-commits mailing list