[Lada-commits] [PATCH 06 of 13] Removed plain sql statements
Wald Commits
scm-commit at wald.intevation.org
Fri May 29 11:48:16 CEST 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1432300448 -7200
# Node ID 331cd2bb31099beb709005501b4ea341e968fa6a
# Parent d61f5ded953da474f053f9b43ab12380d53a9bd7
Removed plain sql statements.
diff -r d61f5ded953d -r 331cd2bb3109 src/main/java/de/intevation/lada/exporter/laf/LafCreator.java
--- a/src/main/java/de/intevation/lada/exporter/laf/LafCreator.java Fri May 22 15:13:44 2015 +0200
+++ b/src/main/java/de/intevation/lada/exporter/laf/LafCreator.java Fri May 22 15:14:08 2015 +0200
@@ -24,6 +24,11 @@
import de.intevation.lada.model.land.LProbe;
import de.intevation.lada.model.land.LZusatzWert;
import de.intevation.lada.model.land.ProbeTranslation;
+import de.intevation.lada.model.stamm.MessEinheit;
+import de.intevation.lada.model.stamm.Messgroesse;
+import de.intevation.lada.model.stamm.ProbenZusatz;
+import de.intevation.lada.model.stamm.Probenart;
+import de.intevation.lada.model.stamm.SOrt;
import de.intevation.lada.util.annotation.RepositoryConfig;
import de.intevation.lada.util.data.QueryBuilder;
import de.intevation.lada.util.data.Repository;
@@ -91,11 +96,16 @@
Response kommentar = repository.filter(kommBuilder.getQuery(), "land");
List<LKommentarP> kommentare = (List<LKommentarP>)kommentar.getData();
- String nativeQuery = "select probenart from stammdaten.probenart where id= '";
- nativeQuery += probe.getProbenartId() + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<String> result = query.getResultList();
- String probenart = result.get(0);//[0].toString();
+ QueryBuilder<Probenart> builder =
+ new QueryBuilder<Probenart>(
+ repository.entityManager("stamm"),
+ Probenart.class);
+ builder.and("id", probe.getProbenartId());
+ List<Probenart> probenarten =
+ (List<Probenart>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
+ String probenart = probenarten.get(0).getProbenart();
QueryBuilder<LZusatzWert> zusatzBuilder =
new QueryBuilder<LZusatzWert>(
@@ -163,14 +173,19 @@
*/
@SuppressWarnings("unchecked")
private String writeZusatzwert(LZusatzWert zw) {
- String nativeQuery = "select beschreibung, meh_id from stammdaten.proben_zusatz where pzs_id = '";
- nativeQuery += zw.getPzsId() + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object[]> result = query.getResultList();
+ QueryBuilder<ProbenZusatz> builder =
+ new QueryBuilder<ProbenZusatz>(
+ repository.entityManager("stamm"),
+ ProbenZusatz.class);
+ builder.and("id", zw.getPzsId());
+ List<ProbenZusatz> zusatz =
+ (List<ProbenZusatz>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
- String value = "\"" + result.get(0)[0].toString() + "\"";
+ String value = "\"" + zusatz.get(0).getBeschreibung() + "\"";
value += " " + zw.getMesswertPzs();
- value += " " + result.get(0)[1].toString();
+ value += " " + zusatz.get(0).getMehId();
value += " " + zw.getMessfehler();
return lafLine("PZB_S", value);
}
@@ -194,24 +209,29 @@
String laf = "";
for(LOrt o : orte) {
laf += "%ORT%\n";
- String nativeQuery = "select bezeichnung, staat_id, longitude, latitude, gem_id from stammdaten.ort where id = '";
- nativeQuery += o.getOrt() + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object[]> result = query.getResultList();
+ QueryBuilder<SOrt> oBuilder =
+ new QueryBuilder<SOrt>(
+ repository.entityManager("stamm"),
+ SOrt.class);
+ oBuilder.and("id", o.getOrt());
+ List<SOrt> sOrte=
+ (List<SOrt>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
laf += lafLine("ORT_CODE",
- "\"" + result.get(0)[0].toString() + "\"");
+ "\"" + sOrte.get(0).getBezeichnung() + "\"");
laf += lafLine("ORT_TYP", "\"" + o.getOrtsTyp() + "\"");
laf += o.getOrtszusatztext() == null ? "":
lafLine("ORT_ZUSATZTEXT", "\"" + o.getOrtszusatztext() + "\"");
- laf += lafLine("ORT_LAND_S", String.valueOf(result.get(0)[1].toString()));
+ laf += lafLine("ORT_LAND_S", String.valueOf(sOrte.get(0).getStaatId()));
String koord = "";
koord += "05 ";
- koord += result.get(0)[2].toString() + " ";
- koord += result.get(0)[3].toString();
+ koord += sOrte.get(0).getLongitude() + " ";
+ koord += sOrte.get(0).getLatitude();
//TODO: use table koordinatenart and koord*extern!
laf += lafLine("ORT_KOORDINATEN_S", koord);
- laf += lafLine("ORT_GEMEINDESCHLUESSEL", result.get(0)[4].toString());
+ laf += lafLine("ORT_GEMEINDESCHLUESSEL", sOrte.get(0).getVerwaltungseinheitId());
}
return laf;
}
@@ -303,17 +323,27 @@
*/
@SuppressWarnings("unchecked")
private String writeMesswert(LMesswert mw) {
- String nativeQuery = "select messgroesse from stammdaten.messgroesse where id = '";
- nativeQuery += mw.getMessgroesseId() + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object[]> result = query.getResultList();
+ QueryBuilder<Messgroesse> builder =
+ new QueryBuilder<Messgroesse>(
+ repository.entityManager("stamm"),
+ Messgroesse.class);
+ builder.and("id", mw.getMessgroesseId());
+ List<Messgroesse> groessen =
+ (List<Messgroesse>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
- String nativeQuery2 = "select einheit from stammdaten.mess_einheit where id = '";
- nativeQuery2 += mw.getMehId() + "'";
- Query query2 = repository.entityManager("land").createNativeQuery(nativeQuery2);
- List<Object[]> result2 = query2.getResultList();
+ QueryBuilder<MessEinheit> eBuilder =
+ new QueryBuilder<MessEinheit>(
+ repository.entityManager("stamm"),
+ MessEinheit.class);
+ eBuilder.and("id", mw.getMehId());
+ List<MessEinheit> einheiten =
+ (List<MessEinheit>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
- String value = "\"" + result.get(0) + "\"";
+ String value = "\"" + groessen.get(0).getMessgroesse() + "\"";
if (mw.getGrenzwertueberschreitung() != null &&
!mw.getGrenzwertueberschreitung()) {
value += " <";
@@ -322,7 +352,7 @@
value += " ";
}
value += mw.getMesswert();
- value += " \"" + result2.get(0) + "\"";
+ value += " \"" + einheiten.get(0).getEinheit() + "\"";
value += mw.getMessfehler() == null ? " NULL" : " " + mw.getMessfehler();
value += mw.getNwgZuMesswert() == null ? " NULL" : " " + mw.getNwgZuMesswert();
value += mw.getGrenzwertueberschreitung() == null ? " N" :
diff -r d61f5ded953d -r 331cd2bb3109 src/main/java/de/intevation/lada/importer/laf/AttributeMapper.java
--- a/src/main/java/de/intevation/lada/importer/laf/AttributeMapper.java Fri May 22 15:13:44 2015 +0200
+++ b/src/main/java/de/intevation/lada/importer/laf/AttributeMapper.java Fri May 22 15:14:08 2015 +0200
@@ -29,6 +29,12 @@
import de.intevation.lada.model.land.LZusatzWert;
import de.intevation.lada.model.land.MessungTranslation;
import de.intevation.lada.model.land.ProbeTranslation;
+import de.intevation.lada.model.stamm.Datenbasis;
+import de.intevation.lada.model.stamm.MessEinheit;
+import de.intevation.lada.model.stamm.Messgroesse;
+import de.intevation.lada.model.stamm.ProbenZusatz;
+import de.intevation.lada.model.stamm.Probenart;
+import de.intevation.lada.model.stamm.Umwelt;
import de.intevation.lada.util.annotation.RepositoryConfig;
import de.intevation.lada.util.data.QueryBuilder;
import de.intevation.lada.util.data.Repository;
@@ -89,12 +95,17 @@
}
if ("datenbasis".equals(key) && probe.getDatenbasisId() == null) {
- String nativeQuery = "select id from stammdaten.datenbasis where datenbasis = '";
- nativeQuery += value.toString() + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object[]> result = query.getResultList();
+ QueryBuilder<Datenbasis> builder =
+ new QueryBuilder<Datenbasis>(
+ repository.entityManager("stamm"),
+ Datenbasis.class);
+ builder.and("datenbasis", value.toString());
+ List<Datenbasis> datenbasis =
+ (List<Datenbasis>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
- Integer v = Integer.valueOf(result.get(0)[0].toString());
+ Integer v = datenbasis.get(0).getId();
probe.setDatenbasisId(v);
}
else if ("datenbasis".equals(key) && probe.getDatenbasisId() != null){
@@ -169,12 +180,17 @@
this.warnings.add(new ReportItem(key, value.toString(), 672));
}
if ("umweltbereich_c".equals(key) && probe.getUmwId() == null) {
- String nativeQuery = "select id from stammdaten.umwelt where umwelt_bereich= '";
+ QueryBuilder<Umwelt> builder =
+ new QueryBuilder<Umwelt>(
+ repository.entityManager("stamm"),
+ Umwelt.class);
int length = value.toString().length() > 80 ? 80 : value.toString().length();
- nativeQuery += value.toString().substring(0, length) + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object[]> result = query.getResultList();
- probe.setUmwId(result.get(0)[0].toString());
+ builder.and("umweltBereich", value.toString().substring(0, length));
+ List<Umwelt> umwelt =
+ (List<Umwelt>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
+ probe.setUmwId(umwelt.get(0).getId());
}
else if ("umweltbereich_c".equals(key) && probe.getUmwId() != null){
this.warnings.add(new ReportItem(key, value.toString(), 672));
@@ -198,11 +214,16 @@
}
if ("probenart".equals(key)) {
- String nativeQuery = "select id from stammdaten.probenart where probenart = '";
- nativeQuery += value.toString() + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object> result = query.getResultList();
- probe.setProbenartId(Integer.valueOf(result.get(0).toString()));
+ QueryBuilder<Probenart> builder =
+ new QueryBuilder<Probenart>(
+ repository.entityManager("stamm"),
+ Probenart.class);
+ builder.and("probenart", value.toString());
+ List<Probenart> probenart =
+ (List<Probenart>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
+ probe.setProbenartId(probenart.get(0).getId());
}
return probe;
}
@@ -399,30 +420,39 @@
float fWert = Float.valueOf(wert);
messwert.setMesswert(fWert);
- String nativeQuery = "select id from stammdaten.mess_einheit where einheit = '";
- nativeQuery += einheit + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object> result = query.getResultList();
-
- if (result.isEmpty()) {
+ QueryBuilder<MessEinheit> builder =
+ new QueryBuilder<MessEinheit>(
+ repository.entityManager("stamm"),
+ MessEinheit.class);
+ builder.and("einheit", einheit);
+ List<MessEinheit> messeinheit =
+ (List<MessEinheit>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
+ if (messeinheit.isEmpty()) {
this.errors.add(new ReportItem("messeinheit", "null", 673));
return null;
}
else {
- messwert.setMehId((Integer)result.get(0));
+ messwert.setMehId(messeinheit.get(0).getId());
}
- String nativeQuery2 = "select id from stammdaten.messgroesse where messgroesse = '";
- nativeQuery2 += messgroesse + "'";
- Query query2 = repository.entityManager("land").createNativeQuery(nativeQuery2);
- List<Object> result2 = query2.getResultList();
+ QueryBuilder<Messgroesse> mgBuilder =
+ new QueryBuilder<Messgroesse>(
+ repository.entityManager("stamm"),
+ Messgroesse.class);
+ mgBuilder.and("messgroesse", messgroesse);
+ List<Messgroesse> messgroessen =
+ (List<Messgroesse>)repository.filter(
+ mgBuilder.getQuery(),
+ "stamm").getData();
- if (result2.isEmpty()) {
+ if (messgroessen.isEmpty()) {
this.errors.add(new ReportItem("messgroesse", "null", 673));
return null;
}
else {
- messwert.setMessgroesseId((Integer)result2.get(0));
+ messwert.setMessgroesseId(messgroessen.get(0).getId());
}
}
return messwert;
@@ -508,16 +538,21 @@
ndx = v.indexOf("\"");
String fehler = v.substring(ndx + 2);
- String nativeQuery = "select id from stammdaten.probenzusatz where zusatzwert = '";
- nativeQuery += groesse + "'";
- Query query = repository.entityManager("land").createNativeQuery(nativeQuery);
- List<Object[]> result = query.getResultList();
+ QueryBuilder<ProbenZusatz> builder =
+ new QueryBuilder<ProbenZusatz>(
+ repository.entityManager("stamm"),
+ ProbenZusatz.class);
+ builder.and("zusatzwert", groesse);
+ List<ProbenZusatz> zusatz=
+ (List<ProbenZusatz>)repository.filter(
+ builder.getQuery(),
+ "stamm").getData();
- if (result == null || result.isEmpty()) {
+ if (zusatz == null || zusatz.isEmpty()) {
this.errors.add(new ReportItem(lKey, "zusatzwert", 673));
return null;
}
- wert.setPzsId(result.get(0)[0].toString());
+ wert.setPzsId(zusatz.get(0).getId());
wert.setMesswertPzs(Float.valueOf(w));
wert.setMessfehler(Float.valueOf(fehler));
return wert;
More information about the Lada-commits
mailing list