1 22 23 package org.efs.openreports.engine; 24 25 import org.efs.openreports.providers.DataSourceProvider; 26 import org.efs.openreports.providers.ProviderException; 27 import org.apache.log4j.Logger; 28 29 import java.sql.Connection ; 30 import java.sql.SQLException ; 31 import java.util.List ; 32 import java.util.Map ; 33 34 61 public class JXLSReportManagerImpl extends net.sf.jxls.report.ReportManagerImpl { 62 63 protected static Logger log = Logger.getLogger(JXLSReportManagerImpl.class); 64 65 DataSourceProvider dataSourceProvider = null; 66 67 public JXLSReportManagerImpl(Connection connection, Map beans, DataSourceProvider dataSourceProvider) throws SQLException { 68 super( connection, beans ); 69 this.dataSourceProvider = dataSourceProvider; 70 } 71 72 public List exec(String datasourceName, String sql) throws SQLException , ProviderException { 76 List results = null; 77 log.debug("JXLS exec invoked for datasourceName=[" + datasourceName +"]"); 78 try { 79 results = exec(dataSourceProvider.getDataSource(datasourceName).getId(), sql); 80 } catch( Exception e ) { 81 String msg = "Unable to complete query against datasourceName=[" + datasourceName +"]." + 82 " Please ensure the datasourceName in your xls template is valid." + 83 " Caught exception is " + e.getClass().getName() + ", message is " + e.getMessage(); 84 log.error(msg); 85 throw new ProviderException(msg); 86 } 87 return results; 88 } 89 90 public List exec(Integer datasourceId, String sql) throws SQLException , ProviderException { 94 Connection defaultConnection=super.getConnection(); 95 List list = null; 96 try { 97 super.setConnection(dataSourceProvider.getConnection(datasourceId)); 98 log.debug("JXLS exec sql=[" + sql + "] against datasourceId=[" + datasourceId +"]"); 99 list = super.exec(sql); } catch( Exception e ) { 101 String msg = "Unable to execute sql=[" + sql + "] against datasourceId=[" + datasourceId +"]." + 102 " Please ensure the dataSourceId and SQL in your xls template are valid." + 103 " Caught exception is " + e.getClass().getName() + ", message is " + e.getMessage(); 104 log.error(msg); 105 throw new ProviderException(msg); 106 } finally { 107 super.setConnection(defaultConnection); 108 } 109 return list; 110 } 111 112 113 } 114 | Popular Tags |