diff backend/src/main/java/org/dive4elements/river/model/BedHeight.java @ 9245:f5cff8708531

bedheight datasource for salix.historical
author gernotbelger
date Wed, 11 Jul 2018 14:45:01 +0200
parents 8642a76f22be
children c08d5cfa4981
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/model/BedHeight.java	Wed Jul 11 13:42:29 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/BedHeight.java	Wed Jul 11 14:45:01 2018 +0200
@@ -207,11 +207,8 @@
     public static List<BedHeight> getBedHeights(final River river, final double kmLo, final double kmHi) {
         final Session session = SessionHolder.HOLDER.get();
 
-        final Query query = session.createQuery("from BedHeight"
-                + " where river=:river"
-                + " and id in (select bedHeight.id from BedHeightValue"
-                + " where station between :kmfrom and :kmto"
-                + " group by bedHeight.id)");
+        final Query query = session.createQuery("from BedHeight" + " where river=:river" + " and id in (select bedHeight.id from BedHeightValue"
+                + " where station between :kmfrom and :kmto" + " group by bedHeight.id)");
 
         query.setParameter("river", river);
         query.setParameter("kmfrom", kmLo);
@@ -238,11 +235,8 @@
 
         final Session session = SessionHolder.HOLDER.get();
 
-        final Query query = session.createQuery("FROM BedHeight"
-                + " WHERE (TRIM(description)=:description) AND river=:river"
-                + " AND id IN (SELECT bedHeight.id FROM BedHeightValue"
-                + " WHERE station BETWEEN :kmfrom AND :kmto"
-                + " GROUP BY bedHeight.id)");
+        final Query query = session.createQuery("FROM BedHeight" + " WHERE (TRIM(description)=:description) AND river=:river"
+                + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)");
         query.setParameter("river", river);
         query.setParameter("description", description);
         query.setParameter("kmfrom", startKm);
@@ -252,4 +246,36 @@
 
         return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null;
     }
+
+    public static List<BedHeight> getBedHeightEpochs(final River river, final double startKm, final double endKm) {
+
+        final Session session = SessionHolder.HOLDER.get();
+        final String description = "epoch";
+        final Query query = session.createQuery("FROM BedHeight" + " WHERE lower(description) LIKE :description AND " + "river=:river"
+                + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)");
+        query.setParameter("river", river);
+        query.setParameter("description", "%" + description + "%");
+        query.setParameter("kmfrom", startKm);
+        query.setParameter("kmto", endKm);
+
+        final List<BedHeight> singles = query.list();
+
+        return ((singles != null) && !singles.isEmpty()) ? singles : null;
+    }
+
+    public static List<BedHeight> getBedHeightYear(final River river, final double startKm, final double endKm) {
+
+        final Session session = SessionHolder.HOLDER.get();
+        final String description = "epoch";
+        final Query query = session.createQuery("FROM BedHeight" + " WHERE lower(description) NOT LIKE :description AND " + "river=:river"
+                + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)");
+        query.setParameter("river", river);
+        query.setParameter("description", "%" + description + "%");
+        query.setParameter("kmfrom", startKm);
+        query.setParameter("kmto", endKm);
+
+        final List<BedHeight> singles = query.list();
+
+        return ((singles != null) && !singles.isEmpty()) ? singles : null;
+    }
 }
\ No newline at end of file

http://dive4elements.wald.intevation.org