Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java @ 7819:b468dc65154a minfo-opt
Use the sediment yield kind to get data to avoid mixing epoch with off. epoch data.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 12 Mar 2014 11:16:45 +0100 |
parents | 6bfa19119040 |
children | 963ede7b32bb |
comparison
equal
deleted
inserted
replaced
7809:521865ad8512 | 7819:b468dc65154a |
---|---|
114 " JOIN sediment_yield_values syv ON sy.id = syv.sediment_yield_id " + | 114 " JOIN sediment_yield_values syv ON sy.id = syv.sediment_yield_id " + |
115 " JOIN time_intervals ti ON sy.time_interval_id = ti.id " + | 115 " JOIN time_intervals ti ON sy.time_interval_id = ti.id " + |
116 " JOIN units u ON u.id = sy.unit_id " + | 116 " JOIN units u ON u.id = sy.unit_id " + |
117 " WHERE r.name = :name " + | 117 " WHERE r.name = :name " + |
118 " AND ti.stop_time IS NOT NULL " + | 118 " AND ti.stop_time IS NOT NULL " + |
119 " AND sy.kind = 0" + | |
119 " AND syv.station BETWEEN :startKm AND :endKm"; | 120 " AND syv.station BETWEEN :startKm AND :endKm"; |
120 | 121 |
121 public static final String SQL_SELECT_SINGLES_DATA_BY_ID = | 122 public static final String SQL_SELECT_SINGLES_DATA_BY_ID = |
122 "SELECT" + | 123 "SELECT" + |
123 " sy.description AS description, " + | 124 " sy.description AS description, " + |
167 " JOIN grain_fraction gf ON sy.grain_fraction_id = gf.id " + | 168 " JOIN grain_fraction gf ON sy.grain_fraction_id = gf.id " + |
168 " JOIN units u ON u.id = sy.unit_id" + | 169 " JOIN units u ON u.id = sy.unit_id" + |
169 " WHERE r.name = :name " + | 170 " WHERE r.name = :name " + |
170 " AND sy.description = :descr " + | 171 " AND sy.description = :descr " + |
171 " AND gf.name = 'unknown' " + | 172 " AND gf.name = 'unknown' " + |
173 " AND sy.kind = :type" + | |
172 " ORDER BY syv.station"; | 174 " ORDER BY syv.station"; |
173 | 175 |
174 public static final String SQL_SELECT_UNKNOWN = | 176 public static final String SQL_SELECT_UNKNOWN = |
175 "SELECT DISTINCT " + | 177 "SELECT DISTINCT " + |
176 " sy.description AS description, " + | 178 " sy.description AS description, " + |
815 } | 817 } |
816 } | 818 } |
817 | 819 |
818 public static SedimentLoad getLoadUnknown( | 820 public static SedimentLoad getLoadUnknown( |
819 String river, | 821 String river, |
820 String description | 822 String description, |
823 String type | |
821 ) { | 824 ) { |
822 log.debug("SedimentLoadFactory.getLoadWithData"); | 825 log.debug("SedimentLoadFactory.getLoadWithData"); |
823 Cache cache = CacheFactory.getCache(LOAD_DATA_CACHE_NAME); | 826 Cache cache = CacheFactory.getCache(LOAD_DATA_CACHE_NAME); |
824 | 827 |
825 if (cache == null) { | 828 if (cache == null) { |
826 log.debug("Cache not configured."); | 829 log.debug("Cache not configured."); |
827 return getSedimentLoadUnknownUncached(river, description); | 830 return getSedimentLoadUnknownUncached(river, description, type); |
828 } | 831 } |
829 | 832 |
830 StaticSedimentLoadCacheKey key = | 833 StaticSedimentLoadCacheKey key = |
831 new StaticSedimentLoadCacheKey(river, 0d, 0d, 0, 0); | 834 new StaticSedimentLoadCacheKey(river, 0d, 0d, 0, 0); |
832 | 835 |
835 if (element != null) { | 838 if (element != null) { |
836 log.debug("SedimentLoad found in cache"); | 839 log.debug("SedimentLoad found in cache"); |
837 return (SedimentLoad)element.getValue(); | 840 return (SedimentLoad)element.getValue(); |
838 } | 841 } |
839 | 842 |
840 SedimentLoad values = getSedimentLoadUnknownUncached(river, description); | 843 SedimentLoad values = |
844 getSedimentLoadUnknownUncached(river, description, type); | |
841 | 845 |
842 if (values != null && key != null) { | 846 if (values != null && key != null) { |
843 log.debug("Store static bed height values in cache."); | 847 log.debug("Store static bed height values in cache."); |
844 element = new Element(key, values); | 848 element = new Element(key, values); |
845 cache.put(element); | 849 cache.put(element); |
853 * @param type the sediment load type (year or epoch) | 857 * @param type the sediment load type (year or epoch) |
854 * @return according sediment loads. | 858 * @return according sediment loads. |
855 */ | 859 */ |
856 public static SedimentLoad getSedimentLoadUnknownUncached( | 860 public static SedimentLoad getSedimentLoadUnknownUncached( |
857 String river, | 861 String river, |
858 String description | 862 String description, |
863 String type | |
859 ) { | 864 ) { |
860 log.debug("SedimentLoadFactory.getSedimentLoadWithDataUncached"); | 865 log.debug("SedimentLoadFactory.getSedimentLoadWithDataUncached"); |
861 Session session = SessionHolder.HOLDER.get(); | 866 Session session = SessionHolder.HOLDER.get(); |
862 SQLQuery sqlQuery = null; | 867 SQLQuery sqlQuery = null; |
863 | 868 |
868 .addScalar("load", StandardBasicTypes.DOUBLE) | 873 .addScalar("load", StandardBasicTypes.DOUBLE) |
869 .addScalar("km", StandardBasicTypes.DOUBLE) | 874 .addScalar("km", StandardBasicTypes.DOUBLE) |
870 .addScalar("unit", StandardBasicTypes.STRING); | 875 .addScalar("unit", StandardBasicTypes.STRING); |
871 sqlQuery.setString("name", river); | 876 sqlQuery.setString("name", river); |
872 sqlQuery.setString("descr", description); | 877 sqlQuery.setString("descr", description); |
878 if (type.equals("off_epoch")) { | |
879 sqlQuery.setInteger("type", 1); | |
880 } | |
881 else { | |
882 sqlQuery.setInteger("type", 0); | |
883 } | |
873 List<Object []> results = sqlQuery.list(); | 884 List<Object []> results = sqlQuery.list(); |
874 SedimentLoad load = new SedimentLoad(); | 885 SedimentLoad load = new SedimentLoad(); |
875 if (results.isEmpty()) { | 886 if (results.isEmpty()) { |
876 return new SedimentLoad(); | 887 return new SedimentLoad(); |
877 } | 888 } |