Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsOverview.java @ 3143:29022c93027d
FixA: Create a cached GaugeFinderFactory to access the gauge along a river
flys-artifacts/trunk@4751 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 21 Jun 2012 16:46:05 +0000 |
parents | 9aed2e4de3ca |
children | 086326be721c |
comparison
equal
deleted
inserted
replaced
3142:9aed2e4de3ca | 3143:29022c93027d |
---|---|
34 " id AS river_id," + | 34 " id AS river_id," + |
35 " km_up " + | 35 " km_up " + |
36 "FROM rivers " + | 36 "FROM rivers " + |
37 "WHERE" + | 37 "WHERE" + |
38 " name = :name"; | 38 " name = :name"; |
39 | |
40 public static final String SQL_GAUGES = | |
41 "SELECT" + | |
42 " g.id AS gauge_id," + | |
43 " r.a AS a," + | |
44 " r.b AS b " + | |
45 "FROM gauges g" + | |
46 " JOIN ranges r ON g.range_id = r.id " + | |
47 "WHERE" + | |
48 " g.river_id = :river_id " + | |
49 "ORDER BY r.a"; | |
50 | 39 |
51 public static final String SQL_FIXINGS = | 40 public static final String SQL_FIXINGS = |
52 "SELECT" + | 41 "SELECT" + |
53 " id AS wst_id," + | 42 " id AS wst_id," + |
54 " description " + | 43 " description " + |
380 isKmUp = (Boolean)row[1]; | 369 isKmUp = (Boolean)row[1]; |
381 | 370 |
382 return true; | 371 return true; |
383 } | 372 } |
384 | 373 |
385 protected GaugeFinder loadGauges(Session session) { | |
386 SQLQuery query = session.createSQLQuery(SQL_GAUGES) | |
387 .addScalar("gauge_id", StandardBasicTypes.INTEGER) | |
388 .addScalar("a", StandardBasicTypes.DOUBLE) | |
389 .addScalar("b", StandardBasicTypes.DOUBLE); | |
390 | |
391 query.setInteger("river_id", riverId); | |
392 | |
393 List<Object []> list = query.list(); | |
394 | |
395 if (list.isEmpty()) { | |
396 log.warn("River " + riverId + " has no gauges."); | |
397 return null; | |
398 } | |
399 | |
400 List<GaugeRange> gauges = new ArrayList<GaugeRange>(); | |
401 | |
402 for (Object [] row: list) { | |
403 int gaugeId = (Integer)row[0]; | |
404 double start = (Double) row[1]; | |
405 double end = (Double) row[2]; | |
406 GaugeRange gauge = new GaugeRange(start, end, gaugeId); | |
407 gauges.add(gauge); | |
408 } | |
409 | |
410 return new GaugeFinder(gauges, isKmUp); | |
411 } | |
412 | |
413 | |
414 protected void loadFixings(Session session) { | 374 protected void loadFixings(Session session) { |
415 SQLQuery query = session.createSQLQuery(SQL_FIXINGS) | 375 SQLQuery query = session.createSQLQuery(SQL_FIXINGS) |
416 .addScalar("wst_id", StandardBasicTypes.INTEGER) | 376 .addScalar("wst_id", StandardBasicTypes.INTEGER) |
417 .addScalar("description", StandardBasicTypes.STRING); | 377 .addScalar("description", StandardBasicTypes.STRING); |
418 | 378 |
478 | 438 |
479 if (!loadRiver(session)) { | 439 if (!loadRiver(session)) { |
480 return false; | 440 return false; |
481 } | 441 } |
482 | 442 |
483 GaugeFinder gaugeFinder = loadGauges(session); | 443 GaugeFinderFactory gff = GaugeFinderFactory.getInstance(); |
484 | 444 |
485 if (gaugeFinder == null | 445 GaugeFinder gaugeFinder = gff.getGaugeFinder(riverId, isKmUp); |
486 || !gaugeFinder.loadDischargeSectors(session, riverId)) { | 446 |
447 if (gaugeFinder == null) { | |
487 return false; | 448 return false; |
488 } | 449 } |
489 | 450 |
490 loadFixings(session); | 451 loadFixings(session); |
491 loadFixingsColumns(session); | 452 loadFixingsColumns(session); |