# HG changeset patch # User Felix Wolfsteller # Date 1324558252 0 # Node ID f7e2a84a6d88224b85956b4dd00b7265230bcfe2 # Parent f73036b991e2d364b48f42d7ddf05338a2ee5784 Added function to check whether a CrossSection is the 'newest' for its river. flys-artifacts/trunk@3525 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r f73036b991e2 -r f7e2a84a6d88 flys-artifacts/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added a diff -r f73036b991e2 -r f7e2a84a6d88 flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java --- 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) {