comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java @ 8065:fdb26fe898dc

Sediment load: Cached sediment values dont depend on year. The cached object is an index over year so there is not need to ask the factory for this.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Jul 2014 19:06:35 +0200
parents 349730f8a49f
children e4606eae8ea5
comparison
equal deleted inserted replaced
8064:50102c41151e 8065:fdb26fe898dc
65 private SedimentDensityFactory() {} 65 private SedimentDensityFactory() {}
66 66
67 public static SedimentDensity getSedimentDensity( 67 public static SedimentDensity getSedimentDensity(
68 String river, 68 String river,
69 double startKm, 69 double startKm,
70 double endKm, 70 double endKm
71 int year
72 ) { 71 ) {
73 log.debug("getSedimentDensity"); 72 log.debug("getSedimentDensity");
74 Cache cache = CacheFactory.getCache(DENSITY_CACHE_NAME); 73 Cache cache = CacheFactory.getCache(DENSITY_CACHE_NAME);
75 74
76 if (cache == null) { 75 if (cache == null) {
77 log.debug("Cache not configured."); 76 log.debug("Cache not configured.");
78 return getSedimentDensityUncached(river, startKm, endKm, year); 77 return getSedimentDensityUncached(river, startKm, endKm);
79 } 78 }
80 79
81 String key = river + startKm + endKm; 80 String key = river + startKm + endKm;
82 Element element = cache.get(key); 81 Element element = cache.get(key);
83 if (element != null) { 82 if (element != null) {
84 log.debug("SedimentDensity found in cache!"); 83 log.debug("SedimentDensity found in cache!");
85 return (SedimentDensity)element.getValue(); 84 return (SedimentDensity)element.getValue();
86 } 85 }
87 SedimentDensity value = 86 SedimentDensity value =
88 getSedimentDensityUncached(river, startKm, endKm, year); 87 getSedimentDensityUncached(river, startKm, endKm);
89 88
90 if (value != null && key != null) { 89 if (value != null && key != null) {
91 log.debug("Store sediment density values in cache."); 90 log.debug("Store sediment density values in cache.");
92 element = new Element(key, value); 91 element = new Element(key, value);
93 cache.put(element); 92 cache.put(element);
96 } 95 }
97 96
98 private static SedimentDensity getSedimentDensityUncached( 97 private static SedimentDensity getSedimentDensityUncached(
99 String river, 98 String river,
100 double startKm, 99 double startKm,
101 double endKm, 100 double endKm
102 int year
103 ) { 101 ) {
104 log.debug("getSedimentDensityUncached"); 102 log.debug("getSedimentDensityUncached");
105 Session session = SessionHolder.HOLDER.get(); 103 Session session = SessionHolder.HOLDER.get();
106 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_DENSITY) 104 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_DENSITY)
107 .addScalar("km", StandardBasicTypes.DOUBLE) 105 .addScalar("km", StandardBasicTypes.DOUBLE)

http://dive4elements.wald.intevation.org