1 13 package com.tonbeller.jpivot.olap.model; 14 15 import org.apache.log4j.Logger; 16 17 import com.tonbeller.jpivot.core.Model; 18 import com.tonbeller.jpivot.core.ModelChangeEvent; 19 import com.tonbeller.jpivot.core.ModelChangeListener; 20 21 26 public class CachingOlapModel extends OlapModelDecorator implements ModelChangeListener { 27 private static Logger logger = Logger.getLogger(CachingOlapModel.class); 28 Result result = null; 29 30 33 public void modelChanged(ModelChangeEvent e) { 34 result = null; 35 } 36 37 40 public void structureChanged(ModelChangeEvent e) { 41 result = null; 42 } 43 44 public Result getResult() throws OlapException { 45 logger.info("CachingOlapModel: " + ((result == null) ? "getting Result from OLAP Server" : "using cached result")); 46 if (result == null) { 47 long t1 = System.currentTimeMillis(); 48 result = super.getResult(); 49 long t2 = System.currentTimeMillis(); 50 logger.info("Execute Query took " + (t2 - t1) + " millisec"); 51 } 52 return result; 53 } 54 55 56 59 public Model decorate(Model modelToDecorate) { 60 modelToDecorate.addModelChangeListener(this); 61 return super.decorate(modelToDecorate); 62 } 63 64 } 65 | Popular Tags |