comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportSQRelationValue.java @ 3329:cc8fc6b29649

Store sq relations into database after parsing. flys-backend/trunk@4647 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 13 Jun 2012 08:12:00 +0000
parents a41f279a66e2
children 13596605e81f
comparison
equal deleted inserted replaced
3328:a41f279a66e2 3329:cc8fc6b29649
1 package de.intevation.flys.importer; 1 package de.intevation.flys.importer;
2 2
3 import java.sql.SQLException; 3 import java.sql.SQLException;
4 import java.util.List;
4 5
5 import org.apache.log4j.Logger; 6 import org.apache.log4j.Logger;
6 7
8 import org.hibernate.Query;
9 import org.hibernate.Session;
7 import org.hibernate.exception.ConstraintViolationException; 10 import org.hibernate.exception.ConstraintViolationException;
8 11
9 import de.intevation.flys.model.SQRelation; 12 import de.intevation.flys.model.SQRelation;
10 import de.intevation.flys.model.SQRelationValue; 13 import de.intevation.flys.model.SQRelationValue;
11 14
44 47
45 48
46 public void storeDependencies(SQRelation owner) 49 public void storeDependencies(SQRelation owner)
47 throws SQLException, ConstraintViolationException 50 throws SQLException, ConstraintViolationException
48 { 51 {
49 log.info("store dependencies"); 52 getPeer(owner);
50 log.warn("TODO: IMPLEMENT 'storeDependencies()'");
51 } 53 }
52 54
53 55
54 public SQRelationValue getPeer() { 56 public SQRelationValue getPeer(SQRelation owner) {
55 log.debug("getPeer()"); 57 if (peer == null) {
58 Session session = ImporterSession.getInstance().getDatabaseSession();
56 59
57 if (peer == null) { 60 Query query = session.createQuery(
58 // TODO 61 "from SQRelationValue " +
62 " where sqRelation=:owner " +
63 " and parameter=:parameter" +
64 " and fraction=:fraction" +
65 " and function=:function" +
66 " and km=:km");
67
68 query.setParameter("owner", owner);
69 query.setString("parameter", parameter);
70 query.setString("fraction", fraction);
71 query.setString("function", function);
72 query.setDouble("km", km);
73
74 List<SQRelationValue> values = query.list();
75
76 if (values.isEmpty()) {
77 peer = new SQRelationValue(
78 owner,
79 parameter,
80 fraction,
81 function,
82 km,
83 a,
84 b
85 );
86
87 session.save(peer);
88 }
89 else {
90 peer = values.get(0);
91 }
59 } 92 }
60 93
61 return peer; 94 return peer;
62 } 95 }
63 } 96 }

http://dive4elements.wald.intevation.org