ingo@1230: package de.intevation.flys.backend; ingo@1230: ingo@1230: import java.util.List; ingo@1230: ingo@1230: import org.apache.log4j.Logger; ingo@1230: rrenkert@5181: import org.hibernate.HibernateException; ingo@1230: import org.hibernate.Query; ingo@1230: import org.hibernate.Session; ingo@1230: ingo@1230: import de.intevation.flys.model.Building; ingo@1230: import de.intevation.flys.model.CrossSectionTrack; ingo@1230: import de.intevation.flys.model.Fixpoint; ingo@1230: import de.intevation.flys.model.River; ingo@1230: import de.intevation.flys.model.RiverAxis; aheinecke@5092: import de.intevation.flys.model.HWSLine; ingo@1230: ingo@1230: ingo@1230: public class SpatialInfo { ingo@1230: ingo@1230: private static Logger logger = Logger.getLogger(SpatialInfo.class); ingo@1230: ingo@1230: protected static String RIVERNAME = System.getProperty( ingo@1230: "flys.backend.spatial.river", "Saar"); ingo@1230: ingo@1230: protected Session session; ingo@1230: ingo@1230: ingo@1230: public static void main(String[] args) { ingo@1230: logger.info("Start SpatialInfo application."); ingo@1230: ingo@1230: SpatialInfo spatial = null; ingo@1230: ingo@1230: try { ingo@1230: spatial = new SpatialInfo(); ingo@1230: ingo@1230: River river = spatial.getRiver(RIVERNAME); ingo@1230: if (river == null) { ingo@1230: logger.warn("Could not find river '" + RIVERNAME + "'!"); ingo@1230: return; ingo@1230: } ingo@1230: ingo@1230: logger.info("Spatial information of River '" + RIVERNAME + "'"); ingo@1230: spatial.doRiverAxisInfo(river); ingo@1230: spatial.doCrossSectionTracksInfo(river); ingo@1230: spatial.doBuildingsInfo(river); ingo@1230: spatial.doFixpointsInfo(river); ingo@1230: } ingo@1230: finally { ingo@1230: if (spatial != null) { ingo@1230: spatial.close(); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: logger.info("Finish SpatialInfo application."); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: public SpatialInfo() { ingo@1230: session = SessionFactoryProvider ingo@1230: .createSessionFactory() ingo@1230: .openSession(); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: public void close() { ingo@1230: session.close(); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected River getRiver(String rivername) { ingo@1230: Query query = session.createQuery( ingo@1230: "from River where name =:name"); ingo@1230: query.setParameter("name", rivername); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No river '" + rivername + "' found!"); ingo@1230: return null; ingo@1230: } ingo@1230: ingo@1230: return list.get(0); ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doRiverAxisInfo(River river) { rrenkert@5170: try { rrenkert@5170: List axis = RiverAxis.getRiverAxis(river.getName()); rrenkert@5170: if (axis != null && axis.size() > 0) { rrenkert@5170: logger.debug("TODO: Compute length and boundary."); rrenkert@5170: } rrenkert@5170: else { rrenkert@5170: logger.warn("River has no RiverAxis."); rrenkert@5170: } ingo@1230: } rrenkert@5181: catch(HibernateException iae) { rrenkert@5173: logger.warn("No vaild river axis found for " + river.getName()); rrenkert@5170: return; ingo@1230: } teichmann@5280: ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doCrossSectionTracksInfo(River river) { ingo@1230: Query query = session.createQuery( ingo@1230: "from CrossSectionTrack where river =:river"); ingo@1230: query.setParameter("river", river); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No CrossSectionTracks for '" + river.getName() + "' found!"); ingo@1230: return; ingo@1230: } ingo@1230: else { ingo@1230: logger.info("River contains " + list.size() + " CrossSectionTracks."); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doBuildingsInfo(River river) { ingo@1230: Query query = session.createQuery( ingo@1230: "from Building where river =:river"); ingo@1230: query.setParameter("river", river); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No Buildings for '" + river.getName() + "' found!"); ingo@1230: return; ingo@1230: } ingo@1230: else { ingo@1230: logger.info("River contains " + list.size() + " Buildings."); ingo@1230: } ingo@1230: } ingo@1230: ingo@1230: ingo@1230: protected void doFixpointsInfo(River river) { ingo@1230: Query query = session.createQuery( ingo@1230: "from Fixpoint where river =:river"); ingo@1230: query.setParameter("river", river); ingo@1230: ingo@1230: List list = query.list(); ingo@1230: ingo@1230: if (list == null || list.size() == 0) { ingo@1230: logger.warn("No Fixpoints for '" + river.getName() + "' found!"); ingo@1230: return; ingo@1230: } ingo@1230: else { ingo@1230: logger.info("River contains " + list.size() + " Fixpoints."); ingo@1230: } ingo@1230: } aheinecke@5092: aheinecke@5092: @Deprecated aheinecke@5092: protected void doLinesInfo(River river) { aheinecke@5092: doHWSLinesInfo(river); aheinecke@5092: } aheinecke@5092: aheinecke@5092: protected void doHWSLinesInfo(River river) { aheinecke@5092: Query query = session.createQuery( aheinecke@5092: "from hws_lines where river =:river"); aheinecke@5092: query.setParameter("river", river); aheinecke@5092: aheinecke@5092: List list = query.list(); aheinecke@5092: aheinecke@5092: if (list == null || list.size() == 0) { aheinecke@5092: logger.warn("No Lines for '" + river.getName() + "' found!"); aheinecke@5092: return; aheinecke@5092: } aheinecke@5092: else { aheinecke@5092: logger.info("River contains " + list.size() + " Lines."); aheinecke@5092: } aheinecke@5092: } ingo@1230: } ingo@1230: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :