comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/CrossSectionFactory.java @ 6538:de62db0f2035

issue1157: Let CrossSection be able to find out whether it should be active & master.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 04 Jul 2013 11:52:06 +0200
parents af13ceeba52a
children 675fa2d16544
comparison
equal deleted inserted replaced
6537:f2722602936c 6538:de62db0f2035
57 query.setParameter("rivername", riverName); 57 query.setParameter("rivername", riverName);
58 return query.list(); 58 return query.list();
59 } 59 }
60 60
61 61
62 /**
63 * True if the given section is the "newest" for that river.
64 * @param section Given section
65 * @return true if the section has the most advanced end of its validity interval
66 * or the most advanced start of its validity interval.
67 */
68 public static boolean isNewest(CrossSection section) {
69 Session session = SessionHolder.HOLDER.get();
70 Query query = session.createQuery(
71 "from CrossSection where river.id = :riverid "
72 + " order by timeInterval.stopTime desc, timeInterval.startTime desc");
73 query.setParameter("riverid", section.getRiver().getId());
74
75 List result = query.list();
76
77 if (result == null || result.isEmpty()) {
78 return true;
79 }
80 else {
81 CrossSection cs = (CrossSection) result.get(0);
82 return section.getId().equals(cs.getId());
83 }
84 }
85
86 62
87 /** 63 /**
88 * Get a specific CrossSection from db. 64 * Get a specific CrossSection from db.
89 * @param id The dbid of the cross-section to load. 65 * @param id The dbid of the cross-section to load.
90 */ 66 */

http://dive4elements.wald.intevation.org