Mercurial > dive4elements > river
changeset 1231:22eea1c9e907
Added a function in RiverAxis to retrieve the RiverAxis of a given river.
flys-backend/trunk@2516 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 22 Aug 2011 09:10:08 +0000 |
parents | e2deda3b77a7 |
children | 3383e042a655 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java |
diffstat | 3 files changed, 28 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Thu Aug 18 15:03:20 2011 +0000 +++ b/flys-backend/ChangeLog Mon Aug 22 09:10:08 2011 +0000 @@ -1,3 +1,11 @@ +2011-08-22 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/model/RiverAxis.java: Added a function + that returns the RiverAxis for a given River. + + * src/main/java/de/intevation/flys/backend/SpatialInfo.java: Use the new + function of RiverAxis to retrieve the RiverAxis. + 2011-08-18 Ingo Weinzierl <ingo@intevation.de> * doc/schema/postgresql-spatial.sql: The PostGIS database schema for
--- a/flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java Thu Aug 18 15:03:20 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java Mon Aug 22 09:10:08 2011 +0000 @@ -88,21 +88,11 @@ protected void doRiverAxisInfo(River river) { - Query query = session.createQuery( - "from RiverAxis where river =:river"); - query.setParameter("river", river); - - List<RiverAxis> list = query.list(); - - if (list == null || list.size() == 0) { - logger.warn("No Riveraxis for '" + river.getName() + "' found!"); - return; - } - - RiverAxis axis = list.get(0); + RiverAxis axis = RiverAxis.getRiverAxis(river.getName()); if (axis != null) { LineString ls = axis.getGeom(); logger.info("River axis is " + ls.getLength() + " long."); + logger.info("River boundary: " + ls.getBoundary()); } else { logger.warn("River has no RiverAxis.");
--- a/flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java Thu Aug 18 15:03:20 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java Mon Aug 22 09:10:08 2011 +0000 @@ -1,6 +1,7 @@ package de.intevation.flys.model; import java.io.Serializable; +import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; @@ -9,10 +10,14 @@ import javax.persistence.OneToOne; import javax.persistence.Table; +import org.hibernate.Session; +import org.hibernate.Query; import org.hibernate.annotations.Type; import com.vividsolutions.jts.geom.LineString; +import de.intevation.flys.backend.SessionHolder; + @Entity @Table(name = "river_axes") @@ -73,5 +78,18 @@ public void setGeom(LineString geom) { this.geom = geom; } + + + public static RiverAxis getRiverAxis(String river) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from RiverAxis where river.name =:river"); + query.setParameter("river", river); + + List<RiverAxis> list = query.list(); + + return list.isEmpty() ? null : list.get(0); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :