view gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileMeshVectorOutputState.java @ 1072:6f35dcd81418

Added an output state for verticalprofiles with vector charts on meshes. gnv-artifacts/trunk@1169 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 07 Jun 2010 17:11:48 +0000
parents
children f953c9a559d8
line wrap: on
line source
package de.intevation.gnv.state.profile.vertical;

import de.intevation.artifacts.CallContext;

import de.intevation.gnv.artifacts.cache.CacheFactory;

import de.intevation.gnv.geobackend.base.Result;

import de.intevation.gnv.utils.VectorDataProcessor;

import java.util.Collection;

import net.sf.ehcache.Cache;

import org.apache.log4j.Logger;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class VerticalProfileMeshVectorOutputState
extends      VerticalProfileVectorOutputState
{
    public static final String[] RESULT_COLUMNS = {
        "YORDINATE", "XORDINATE", "KPOSITION",
        "GROUP1",    "GROUP2",    "GROUP3",
        "DATAID",    "FEATUREID", "MESHID",
        "SERIES"
    };

    private static Logger logger =
        Logger.getLogger(VerticalProfileMeshVectorOutputState.class);


    @Override
    protected Object getChartResult(String uuid, CallContext callContext) {
        logger.debug("Fetch chart data for vertical profile with vector data.");
        CacheFactory factory = CacheFactory.getInstance();

        if (factory.isInitialized()) {
            // we use a cache
            logger.info("Using cache.");
            Cache cache = factory.getCache();
            String key  = "chart_" + getHash();

            net.sf.ehcache.Element value = cache.get(key);
            if (value != null) {
                logger.debug("Found element in cache.");
                return value.getObjectValue();
            }
            else {
                logger.debug("Element not in cache, we ask the database");
                Collection<Result> res = (Collection<Result>)getData(queryID);
                logger.debug("Got " + res.size() + " elements from db.");

                res = VectorDataProcessor.process(res, RESULT_COLUMNS);
                cache.put(new net.sf.ehcache.Element(key, res));

                return res;
            }
        }
        else {
            // we don't use a cache, so we have to query the database every
            // single time
            logger.info("Not using a cache.");
            return VectorDataProcessor.process(
                getData(queryID), RESULT_COLUMNS);
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org