# HG changeset patch # User Tim Englich # Date 1254147435 0 # Node ID bb45c5097cb682aa035f1750587f40ad44be85cb # Parent 156db25ad4b4e382992373f7e1f1ba213d477324 ehcache Integration for storing the chartresultvalues gnv-artifacts/trunk@146 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/Changelog --- a/gnv-artifacts/Changelog Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/Changelog Mon Sep 28 14:17:15 2009 +0000 @@ -1,3 +1,32 @@ +2009-09-28 Tim Englich + + * pom.xml Edited: + Added the Dependeny to the ehcache-Library + * src/test/ressources/ehcache.xml Added: + The ehcache-Configuration. + * src/test/ressources/conf.xml Edited: + Added the Link to the ehcache-Configuration. + * src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java (createArtifactContext) Edited: + Added the Initialisation of the CacheManager. + + * src/main/java/de/intevation/gnv/artifacts/cache/CacheFactory.java Added: + An Fractoryimplementation for the central access to the Cache. + + * src/main/java/de/intevation/gnv/transition/MinMaxTransition.java (purifyResult) Edited, + * src/main/java/de/intevation/gnv/transition/SingleInputTransition.java (purifyResult) Edited, + * src/main/java/de/intevation/gnv/transition/Transition.java Edited, + * src/main/java/de/intevation/gnv/transition/TransitionBase.java Edited, + * src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Edited: + Signature of Methods purifyResults, advanced and feed Changed to put the uuid to the Transition + * src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java (createChart) Edited: + Methodsignatur of getChartResult change for putting the uuid of an Artifact into it + * src/main/java/de/intevation/gnv/transition/OutputTransition.java (out) Edited, + src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (out) Edited: + Method Signature Changed for putting the uuid of an Artifact to the Transition. + stored + * src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Edited: + removed the persitence of the Chartresults and put them into an Cache instance. + 2009-09-28 Tim Englich * src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java (getStatisticsGenerator) Edited: diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/pom.xml --- a/gnv-artifacts/pom.xml Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/pom.xml Mon Sep 28 14:17:15 2009 +0000 @@ -62,6 +62,11 @@ commons-math 1.1 + + net.sf.ehcache + ehcache + 1.6.2 + diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java Mon Sep 28 14:17:15 2009 +0000 @@ -92,6 +92,7 @@ @Override public Document advance(Document target, CallContext context) { log.debug("GNVArtifactBase.advance"); + String uuid = Config.getStringXPath(target, "action/uuid/@value"); Document result = XMLUtils.newDocument(); try { if (this.current != null){ @@ -103,10 +104,10 @@ try { Transition nextStep = this.transitions.get(transitionName); // 2.Ergebnisse Berechnen - this.current.advance(); + this.current.advance(uuid); // 3. Ergebnisse übergeben nextStep.setDescibeData(this.current.getDescibeData()); - nextStep.putInputData(this.current.getInputData()); + nextStep.putInputData(this.current.getInputData(),uuid); // 4. Umschalten auf neue Transistion this.current = nextStep; result = new ArtifactXMLUtilities().createSuccessReport("Advance success", XMLUtils.newDocument()); @@ -160,7 +161,8 @@ Document result = XMLUtils.newDocument(); try { if (this.current != null){ - this.current.putInputData(this.parseInputData(target, "/action/data/input")); + String uuid = Config.getStringXPath(target, "action/uuid/@value"); + this.current.putInputData(this.parseInputData(target, "/action/data/input"),uuid); result = new ArtifactXMLUtilities().createSuccessReport("Feed success", XMLUtils.newDocument()); }else{ String msg = "No Transition instantiated"; @@ -360,10 +362,7 @@ } return returnValue.values(); } - /** - * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, java.lang.Object) - */ - + /** * @see de.intevation.artifactdatabase.DefaultArtifact#out(org.w3c.dom.Document, java.io.OutputStream, de.intevation.artifacts.CallContext) @@ -375,8 +374,9 @@ try { if (current != null && current instanceof OutputTransition){ - ((OutputTransition)current).out(this.readOutputType(format),this.parseInputData(format, "/action/out/params/input"), outputStream); - context.afterCall(CallContext.STORE); // TODO: FIXME Schmutzige Lösung: Besser einen weiteren Transitionsschritt zwischenschalten. + String uuid = Config.getStringXPath(format, "action/uuid/@value"); + ((OutputTransition)current).out(this.readOutputType(format),this.parseInputData(format, "/action/out/params/input"), outputStream,uuid); + //context.afterCall(CallContext.STORE); // TODO: FIXME Schmutzige Lösung: Besser einen weiteren Transitionsschritt zwischenschalten. } } catch (TransitionException e) { log.error(e,e); diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/cache/CacheFactory.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/cache/CacheFactory.java Mon Sep 28 14:17:15 2009 +0000 @@ -0,0 +1,82 @@ +/** + * + */ +package de.intevation.gnv.artifacts.cache; + +import net.sf.ehcache.Cache; +import net.sf.ehcache.CacheManager; + +import org.apache.log4j.Logger; + +/** + * @author Tim Englich + * + */ +public class CacheFactory { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = Logger.getLogger(CacheFactory.class); + + private final static String CACHENAME = "artifactdata"; + + + /** + * The singleton Instance of this Factory. + */ + private static CacheFactory instance = null; + + /** + * + */ + private CacheManager cacheManager = null; + + /** + * Basic-Constructor of this Class + */ + private CacheFactory() { + super(); + } + + /** + * This Method provides an singleton Instance of this Class. + * @return an singleton Instance of this Class + */ + public static CacheFactory getInstance(){ + if (instance == null){ + instance = new CacheFactory(); + } + return instance; + } + + + /** + * Getting the ConnectionPool + * @return the ConnectionPool + */ + public Cache getCache(){ + return this.cacheManager.getCache(CACHENAME); + } + + /** + * Initializes the ConnectionPool. + * Should only be called once on system startup + * @param properties the Properties for the Individual Configuration of the ConnectionPool + */ + public void initializeCache(String configurationFileName){ + if (cacheManager == null){ + cacheManager = new CacheManager(configurationFileName); + cacheManager.addCache(CACHENAME); + } + } + + /** + * Checks if the ConnectionPool has already been initialized. + * @return true if the ConnectionPool is initialized. + */ + public boolean isInitialized(){ + return this.cacheManager != null; + } + +} diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/context/GNVArtifactContextFactory.java Mon Sep 28 14:17:15 2009 +0000 @@ -14,6 +14,7 @@ import de.intevation.artifactdatabase.Config; import de.intevation.artifacts.ArtifactContextFactory; +import de.intevation.gnv.artifacts.cache.CacheFactory; import de.intevation.gnv.geobackend.base.connectionpool.ConnectionPoolFactory; import de.intevation.gnv.geobackend.base.query.container.QueryContainerFactory; import de.intevation.gnv.geobackend.base.query.container.exception.QueryContainerException; @@ -32,6 +33,8 @@ public static final String XPATH_GEOBACKEND_QUERYCONFIGURATION= "artifact-database/geo-backend/query-configuration"; + private final static String CACHECONFIGNODEPATH = "/artifact-database/ehcache/configuration"; + /** * Constructor */ @@ -59,6 +62,12 @@ QueryContainerFactory qcf = QueryContainerFactory.getInstance(); qcf.initializeQueryContainer(queryProperties); + + log.info("Initialisation of the Cache"); + String cacheConfigurationFile = Config.getStringXPath(config, CACHECONFIGNODEPATH); + CacheFactory cf = CacheFactory.getInstance(); + cf.initializeCache(cacheConfigurationFile); + returnValue = new GNVArtifactContext(config); } catch (FileNotFoundException e) { log.error(e,e); diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/MinMaxTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/MinMaxTransition.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/MinMaxTransition.java Mon Sep 28 14:17:15 2009 +0000 @@ -32,11 +32,12 @@ public MinMaxTransition() { super(); } + /** - * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection) + * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, java.lang.String) */ @Override - protected void purifyResult(Collection result) { + protected void purifyResult(Collection result, String uuid) { log.debug("MinMaxTransition.purifyResult"); if (this.descibeData == null){ this.descibeData = new ArrayList(); diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransition.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransition.java Mon Sep 28 14:17:15 2009 +0000 @@ -20,7 +20,7 @@ * @return The Bytecode of the Result * @throws TransitionException */ - public void out( String outputMode, Collection inputData, OutputStream outputStream) throws TransitionException; + public void out( String outputMode, Collection inputData, OutputStream outputStream, String uuid) throws TransitionException; /** * Delivers the provided OutputModes of an Transition diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Mon Sep 28 14:17:15 2009 +0000 @@ -3,14 +3,18 @@ */ package de.intevation.gnv.transition; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; +import net.sf.ehcache.Element; + import org.apache.log4j.Logger; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import de.intevation.artifactdatabase.Config; +import de.intevation.gnv.artifacts.cache.CacheFactory; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.transition.exception.TransitionException; @@ -31,11 +35,7 @@ * the logger, used to log exceptions and additonaly information */ private static Logger log = Logger.getLogger(OutputTransitionBase.class); - /** - * The Results which should be used for Rendering the Charts or - * do other output - */ - protected Collection chartResult = null; + /** * The different Outputmodes which are provided by an OutputTransition @@ -108,21 +108,47 @@ * @see de.intevation.gnv.transition.TransitionBase#advance() */ @Override - public void advance() throws TransitionException { + public void advance(String uuid) throws TransitionException { log.debug("OutputTransitionBase.advance"); - if (this.chartResult == null){ - super.advance(); + if (this.getChartResult(uuid) == null){ + super.advance(uuid); } } /** - * @see de.intevation.gnv.transition.TransitionBase#getInputData() + * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, java.util.Collection, java.io.OutputStream) + */ + public void out(String outputMode, Collection inputData, + OutputStream outputStream) throws TransitionException { + } + + /** + * @return + */ + protected Collection getChartResult(String uuid) { + log.debug("OutputTransitionBase.getChartResult"); + if (CacheFactory.getInstance().isInitialized()){ + String key = uuid+super.getID(); + log.debug("Hash for Queryelements: "+key); + Element value = CacheFactory.getInstance().getCache().get(key); + if (value != null){ + return (Collection)(value.getObjectValue()); + } + } + return null; + } + + /** + * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, java.lang.String) */ @Override - public Collection getInputData() throws TransitionException { - log.debug("OutputTransitionBase.getInputData"); - this.chartResult = null; - return super.getInputData(); + protected void purifyResult(Collection result, String uuid) { + log.debug("OutputTransitionBase.purifyResult"); + if (CacheFactory.getInstance().isInitialized()){ + String key = uuid+super.getID(); + log.debug("Hash for Queryelements: "+key); + CacheFactory.getInstance().getCache().put(new Element(key, result)); + } } } diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/SingleInputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/SingleInputTransition.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/SingleInputTransition.java Mon Sep 28 14:17:15 2009 +0000 @@ -40,8 +40,11 @@ return true; } + /** + * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection, java.lang.String) + */ @Override - protected void purifyResult(Collection result) { + protected void purifyResult(Collection result, String uuid) { log.debug("SingleInputTransition.purifyResult"); if (this.descibeData == null){ this.descibeData = new ArrayList(); diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/Transition.java Mon Sep 28 14:17:15 2009 +0000 @@ -37,11 +37,11 @@ public Collection getRequiredInputValues(); - public void putInputData(Collection inputData) throws TransitionException; + public void putInputData(Collection inputData, String uuid) throws TransitionException; public Collection getInputData() throws TransitionException; - public void advance() throws TransitionException; + public void advance(String uuid) throws TransitionException; public Collection getDescibeData(); diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/TransitionBase.java Mon Sep 28 14:17:15 2009 +0000 @@ -70,7 +70,7 @@ private Transition parent = null; - private Map inputData = null; + protected Map inputData = null; protected Collection descibeData = null; @@ -180,7 +180,7 @@ /** * @see de.intevation.gnv.transition.Transition#putInputData(java.util.Collection) */ - public void putInputData(Collection inputData) throws TransitionException { + public void putInputData(Collection inputData, String uuid) throws TransitionException { log.debug("TransitionBase.putInputData"); if (inputData != null){ Iterator it = inputData.iterator(); @@ -284,7 +284,7 @@ /** * @see de.intevation.gnv.transition.Transition#advance() */ - public void advance() throws TransitionException { + public void advance(String uuid) throws TransitionException { log.debug("TransitionBase.advance"); try { List list = new ArrayList(); @@ -316,7 +316,7 @@ QueryExecutor queryExecutor = QueryExecutorFactory.getInstance().getQueryExecutor(); result = queryExecutor.executeQuery(this.queryID, filterValues); } - this.purifyResult(result); + this.purifyResult(result, uuid); } catch (RuntimeException e) { log.error(e,e); } @@ -362,7 +362,7 @@ /** * @param result */ - protected void purifyResult(Collection result) { + protected void purifyResult(Collection result, String uuid) { if (this.descibeData == null){ this.descibeData = new ArrayList(); } diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Mon Sep 28 14:17:15 2009 +0000 @@ -51,11 +51,11 @@ protected void createChart(OutputStream outputStream, Collection parameters, Collection measurements, - ChartStyle chartStyle, ChartLabels chartLables) throws IOException, TechnicalChartException { + ChartStyle chartStyle, ChartLabels chartLables,String uuid) throws IOException, TechnicalChartException { VerticalProfileChartFactory chartFactory = new VerticalProfileChartFactory(); chartFactory.createSimpleVerticalProfileChart(chartLables, chartStyle, parameters, measurements, - outputStream, this.chartResult); + outputStream, this.getChartResult(uuid)); } /** diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Mon Sep 28 14:17:15 2009 +0000 @@ -77,10 +77,12 @@ /** * @see de.intevation.gnv.transition.OutputTransition#out(java.lang.String, java.util.Collection, java.io.OutputStream) */ - public void out(String outputMode, Collection inputData, OutputStream outputStream) throws TransitionException { + public void out(String outputMode, Collection inputData, OutputStream outputStream, String uuid) throws TransitionException { log.debug("TimeSeriesOutputTransition.out"); try { - this.advance(); + + this.advance(uuid); + Collection chartResult = this.getChartResult(uuid); if (outputMode.equalsIgnoreCase("chart")){ log.debug("Chart will be generated."); int chartWidth = 600; @@ -106,12 +108,12 @@ ChartStyle chartStyle = this.creatStyle(chartWidth,chartHeight); ChartLabels chartLables = new ChartLabels(this.getSelectedFeatureName(),this.domainLable); this.createChart(outputStream, parameters, measurements, - chartStyle, chartLables); + chartStyle, chartLables,uuid); }else if (outputMode.equalsIgnoreCase("csv")){ log.debug("CSV-File will be generated."); - if(this.chartResult != null){ + if(chartResult != null){ CSVWriter writer = new CSVWriter(new OutputStreamWriter(outputStream,"ISO-8859-1"), ','); // USE THIS ENCODING BECAUSE OF PROBLEMS WITH EXCEL AND UTF-8 - Iteratorit = this.chartResult.iterator(); + Iteratorit = chartResult.iterator(); while (it.hasNext()){ Result result = it.next(); int i = 0; @@ -131,7 +133,7 @@ }else if (outputMode.equalsIgnoreCase("statistics")){ log.debug("Statistics will be generated."); Statistics s = getStatisticsGenerator(); - Collection statistics = s.calculateStatistics(this.chartResult); + Collection statistics = s.calculateStatistics(chartResult); Document doc = this.writeStatistics2XML(statistics); this.writeDocument2OutputStream(doc, outputStream); } @@ -219,20 +221,12 @@ protected void createChart(OutputStream outputStream, Collection parameters, Collection measurements, - ChartStyle chartStyle, ChartLabels chartLables) throws IOException, + ChartStyle chartStyle, ChartLabels chartLables, String uuid) throws IOException, TechnicalChartException { ChartFactory chartFactory = new ChartFactory(); chartFactory.createSimpleTimeSeriesChart(chartLables, chartStyle, parameters, measurements, - outputStream, this.chartResult); - } - - /** - * @see de.intevation.gnv.transition.TransitionBase#purifyResult(java.util.Collection) - */ - @Override - protected void purifyResult(Collection result) { - this.chartResult = result; + outputStream, this.getChartResult(uuid)); } protected ChartStyle creatStyle(int witdh, int height){ diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/test/ressources/conf.xml --- a/gnv-artifacts/src/test/ressources/conf.xml Mon Sep 28 10:20:41 2009 +0000 +++ b/gnv-artifacts/src/test/ressources/conf.xml Mon Sep 28 14:17:15 2009 +0000 @@ -479,6 +479,9 @@ + + src/test/ressources/ehcache.xml + ../geo-backend/src/test/ressources/ArcSDEConnectionPoolTestCase.properties src/test/ressources/queries.properties diff -r 156db25ad4b4 -r bb45c5097cb6 gnv-artifacts/src/test/ressources/ehcache.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/ressources/ehcache.xml Mon Sep 28 14:17:15 2009 +0000 @@ -0,0 +1,9 @@ + + + + +