Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/backend/SpatialInfo.java @ 2877:f0a67bc0e777 2.7
merged flys-backend/2.7
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:31 +0200 |
parents | d183ae164cfc |
children | 8df746f374cc |
comparison
equal
deleted
inserted
replaced
2793:6310b1582f2d | 2877:f0a67bc0e777 |
---|---|
1 package de.intevation.flys.backend; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.hibernate.Query; | |
8 import org.hibernate.Session; | |
9 | |
10 import de.intevation.flys.backend.SessionFactoryProvider; | |
11 import de.intevation.flys.model.Building; | |
12 import de.intevation.flys.model.CrossSectionTrack; | |
13 import de.intevation.flys.model.Fixpoint; | |
14 import de.intevation.flys.model.Line; | |
15 import de.intevation.flys.model.River; | |
16 import de.intevation.flys.model.RiverAxis; | |
17 | |
18 | |
19 public class SpatialInfo { | |
20 | |
21 private static Logger logger = Logger.getLogger(SpatialInfo.class); | |
22 | |
23 protected static String RIVERNAME = System.getProperty( | |
24 "flys.backend.spatial.river", "Saar"); | |
25 | |
26 protected Session session; | |
27 | |
28 | |
29 public static void main(String[] args) { | |
30 logger.info("Start SpatialInfo application."); | |
31 | |
32 SpatialInfo spatial = null; | |
33 | |
34 try { | |
35 spatial = new SpatialInfo(); | |
36 | |
37 River river = spatial.getRiver(RIVERNAME); | |
38 if (river == null) { | |
39 logger.warn("Could not find river '" + RIVERNAME + "'!"); | |
40 return; | |
41 } | |
42 | |
43 logger.info("Spatial information of River '" + RIVERNAME + "'"); | |
44 spatial.doRiverAxisInfo(river); | |
45 spatial.doCrossSectionTracksInfo(river); | |
46 spatial.doLinesInfo(river); | |
47 spatial.doBuildingsInfo(river); | |
48 spatial.doFixpointsInfo(river); | |
49 } | |
50 finally { | |
51 if (spatial != null) { | |
52 spatial.close(); | |
53 } | |
54 } | |
55 | |
56 logger.info("Finish SpatialInfo application."); | |
57 } | |
58 | |
59 | |
60 public SpatialInfo() { | |
61 session = SessionFactoryProvider | |
62 .createSessionFactory() | |
63 .openSession(); | |
64 } | |
65 | |
66 | |
67 public void close() { | |
68 session.close(); | |
69 } | |
70 | |
71 | |
72 protected River getRiver(String rivername) { | |
73 Query query = session.createQuery( | |
74 "from River where name =:name"); | |
75 query.setParameter("name", rivername); | |
76 | |
77 List<River> list = query.list(); | |
78 | |
79 if (list == null || list.size() == 0) { | |
80 logger.warn("No river '" + rivername + "' found!"); | |
81 return null; | |
82 } | |
83 | |
84 return list.get(0); | |
85 } | |
86 | |
87 | |
88 protected void doRiverAxisInfo(River river) { | |
89 List<RiverAxis> axis = RiverAxis.getRiverAxis(river.getName()); | |
90 if (axis != null && axis.size() > 0) { | |
91 logger.debug("TODO: Compute length and boundary."); | |
92 } | |
93 else { | |
94 logger.warn("River has no RiverAxis."); | |
95 } | |
96 } | |
97 | |
98 | |
99 protected void doCrossSectionTracksInfo(River river) { | |
100 Query query = session.createQuery( | |
101 "from CrossSectionTrack where river =:river"); | |
102 query.setParameter("river", river); | |
103 | |
104 List<CrossSectionTrack> list = query.list(); | |
105 | |
106 if (list == null || list.size() == 0) { | |
107 logger.warn("No CrossSectionTracks for '" + river.getName() + "' found!"); | |
108 return; | |
109 } | |
110 else { | |
111 logger.info("River contains " + list.size() + " CrossSectionTracks."); | |
112 } | |
113 } | |
114 | |
115 | |
116 protected void doLinesInfo(River river) { | |
117 Query query = session.createQuery( | |
118 "from Line where river =:river"); | |
119 query.setParameter("river", river); | |
120 | |
121 List<Line> list = query.list(); | |
122 | |
123 if (list == null || list.size() == 0) { | |
124 logger.warn("No Lines for '" + river.getName() + "' found!"); | |
125 return; | |
126 } | |
127 else { | |
128 logger.info("River contains " + list.size() + " Lines."); | |
129 } | |
130 } | |
131 | |
132 | |
133 protected void doBuildingsInfo(River river) { | |
134 Query query = session.createQuery( | |
135 "from Building where river =:river"); | |
136 query.setParameter("river", river); | |
137 | |
138 List<Building> list = query.list(); | |
139 | |
140 if (list == null || list.size() == 0) { | |
141 logger.warn("No Buildings for '" + river.getName() + "' found!"); | |
142 return; | |
143 } | |
144 else { | |
145 logger.info("River contains " + list.size() + " Buildings."); | |
146 } | |
147 } | |
148 | |
149 | |
150 protected void doFixpointsInfo(River river) { | |
151 Query query = session.createQuery( | |
152 "from Fixpoint where river =:river"); | |
153 query.setParameter("river", river); | |
154 | |
155 List<Fixpoint> list = query.list(); | |
156 | |
157 if (list == null || list.size() == 0) { | |
158 logger.warn("No Fixpoints for '" + river.getName() + "' found!"); | |
159 return; | |
160 } | |
161 else { | |
162 logger.info("River contains " + list.size() + " Fixpoints."); | |
163 } | |
164 } | |
165 } | |
166 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |