Mercurial > dive4elements > river
changeset 2039:f7e2a84a6d88
Added function to check whether a CrossSection is the 'newest' for its river.
flys-artifacts/trunk@3525 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 22 Dec 2011 12:50:52 +0000 (2011-12-22) |
parents | f73036b991e2 |
children | cd9bcdcf6597 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java |
diffstat | 2 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Dec 21 15:44:41 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Dec 22 12:50:52 2011 +0000 @@ -1,3 +1,9 @@ +2011-12-22 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java + (isNewest): New, query whether a CrossSection is the newest for its + river, doc. + 2011-12-21 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added a
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java Wed Dec 21 15:44:41 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java Thu Dec 22 12:50:52 2011 +0000 @@ -51,7 +51,28 @@ } - /** Get a specific CrossSection from db. */ + /** + * True if the given section is the "newest" for that river. + * @param section Given section + * @return true if the section has the most advanced end of its validity interval + * or the most advanced start of its validity interval. + */ + public static boolean isNewest(CrossSection section) { + Session session = SessionHolder.HOLDER.get(); + Query query = session.createQuery( + "from CrossSection where river.id = :riverid " + + " order by timeInterval.stopTime desc, timeInterval.startTime desc"); + query.setParameter("riverid", section.getRiver().getId()); + + CrossSection cs = (CrossSection) query.list().get(0); + return section.getId().equals(cs.getId()); + } + + + /** + * Get a specific CrossSection from db. + * @param id The dbid of the cross-section to load. + */ public static CrossSection getCrossSection(int id) { Cache cache = CacheFactory.getCache(CACHE_NAME); if (cache != null) {