Mercurial > dive4elements > river
changeset 5278:3ddf5843ede3
correct session-handling for bed height import (made by S. Teichmann)
author | Tom Gottfried <tom.gottfried@intevation.de> |
---|---|
date | Wed, 13 Mar 2013 18:53:42 +0100 |
parents | 170f514a4f29 |
children | 8e66a200a0b9 |
files | flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java |
diffstat | 2 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java Wed Mar 13 18:39:28 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightParser.java Wed Mar 13 18:53:42 2013 +0100 @@ -31,7 +31,7 @@ import de.intevation.flys.importer.ImportTimeInterval; import de.intevation.flys.importer.ImportUnit; import de.intevation.flys.model.BedHeightType; - +import de.intevation.flys.importer.ImporterSession; public abstract class BedHeightParser { @@ -331,7 +331,8 @@ if (m.matches()) { String tmp = m.group(1).replace(";", ""); - BedHeightType bht = BedHeightType.fetchBedHeightTypeForType(tmp); + BedHeightType bht = BedHeightType.fetchBedHeightTypeForType( + tmp, ImporterSession.getInstance().getDatabaseSession()); if (bht != null) { obj.setType(new ImportBedHeightType(bht));
--- a/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java Wed Mar 13 18:39:28 2013 +0100 +++ b/flys-backend/src/main/java/de/intevation/flys/model/BedHeightType.java Wed Mar 13 18:53:42 2013 +0100 @@ -63,13 +63,20 @@ this.name = name; } - public static BedHeightType fetchBedHeightTypeForType(String type) { - Session session = SessionHolder.HOLDER.get(); + return fetchBedHeightTypeForType(type, null); + } + + public static BedHeightType fetchBedHeightTypeForType(String name, Session session) { + + if (session == null) { + session = SessionHolder.HOLDER.get(); + } + Query query = session.createQuery( - "from BedHeightType where type=:type"); + "from BedHeightType where name=:name"); - query.setParameter("type", type); + query.setParameter("name", name); List<Object> results = query.list();