comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFactory.java @ 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
parents e71615d95afb
children ef337d9fa5ea
comparison
equal deleted inserted replaced
2038:f73036b991e2 2039:f7e2a84a6d88
49 query.setParameter("rivername", riverName); 49 query.setParameter("rivername", riverName);
50 return query.list(); 50 return query.list();
51 } 51 }
52 52
53 53
54 /** Get a specific CrossSection from db. */ 54 /**
55 * True if the given section is the "newest" for that river.
56 * @param section Given section
57 * @return true if the section has the most advanced end of its validity interval
58 * or the most advanced start of its validity interval.
59 */
60 public static boolean isNewest(CrossSection section) {
61 Session session = SessionHolder.HOLDER.get();
62 Query query = session.createQuery(
63 "from CrossSection where river.id = :riverid "
64 + " order by timeInterval.stopTime desc, timeInterval.startTime desc");
65 query.setParameter("riverid", section.getRiver().getId());
66
67 CrossSection cs = (CrossSection) query.list().get(0);
68 return section.getId().equals(cs.getId());
69 }
70
71
72 /**
73 * Get a specific CrossSection from db.
74 * @param id The dbid of the cross-section to load.
75 */
55 public static CrossSection getCrossSection(int id) { 76 public static CrossSection getCrossSection(int id) {
56 Cache cache = CacheFactory.getCache(CACHE_NAME); 77 Cache cache = CacheFactory.getCache(CACHE_NAME);
57 if (cache != null) { 78 if (cache != null) {
58 Element element = cache.get(Integer.valueOf(id)); 79 Element element = cache.get(Integer.valueOf(id));
59 if (element != null) { 80 if (element != null) {

http://dive4elements.wald.intevation.org