1 28 package net.sf.jasperreports.olap; 29 30 import java.util.Map ; 31 32 import mondrian.olap.Connection; 33 import mondrian.olap.Query; 34 import mondrian.olap.Result; 35 import net.sf.jasperreports.engine.JRDataSource; 36 import net.sf.jasperreports.engine.JRDataset; 37 import net.sf.jasperreports.engine.JRException; 38 import net.sf.jasperreports.engine.query.JRAbstractQueryExecuter; 39 40 import org.apache.commons.logging.Log; 41 import org.apache.commons.logging.LogFactory; 42 43 44 48 public class JRMondrianQueryExecuter extends JRAbstractQueryExecuter 49 { 50 private static final Log log = LogFactory.getLog(JRMondrianQueryExecuter.class); 51 52 private Connection connection; 53 private Result result; 54 55 public JRMondrianQueryExecuter(JRDataset dataset, Map parametersMap) 56 { 57 super(dataset, parametersMap); 58 59 connection = (Connection) getParameterValue(JRMondrianQueryExecuterFactory.PARAMETER_MONDRIAN_CONNECTION); 60 61 if (connection == null) 62 { 63 log.warn("The supplied mondrian.olap.Connection object is null."); 64 } 65 66 parseQuery(); 67 } 68 69 protected String getParameterReplacement(String parameterName) 70 { 71 return String.valueOf(getParameterValue(parameterName)); 72 } 73 74 public JRDataSource createDatasource() throws JRException 75 { 76 JRDataSource dataSource = null; 77 78 String queryStr = getQueryString(); 79 if (connection != null && queryStr != null) 80 { 81 if (log.isDebugEnabled()) 82 { 83 log.debug("MDX query: " + queryStr); 84 } 85 86 Query query = connection.parseQuery(queryStr); 87 result = connection.execute(query); 88 89 dataSource = new JRMondrianDataSource(dataset, result); 90 } 91 92 return dataSource; 93 } 94 95 public void close() 96 { 97 if (result != null) 98 { 99 result.close(); 100 result = null; 101 } 102 } 103 104 public boolean cancelQuery() throws JRException 105 { 106 return false; 107 } 108 } 109 | Popular Tags |