1 21 package com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl; 22 23 import java.sql.Connection ; 24 import java.sql.SQLException ; 25 import java.util.Map ; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 import net.sf.jasperreports.engine.JRParameter; 31 32 import com.jaspersoft.jasperserver.api.JSExceptionWrapper; 33 import com.jaspersoft.jasperserver.api.metadata.jasperreports.service.ReportDataSourceService; 34 35 39 public abstract class BaseJdbcDataSource implements ReportDataSourceService { 40 41 42 private static final Log log = LogFactory.getLog(BaseJdbcDataSource.class); 43 44 private Connection conn; 45 46 47 public void setReportParameterValues(Map parameterValues) { 48 conn = createConnection(); 49 parameterValues.put(JRParameter.REPORT_CONNECTION, conn); 50 } 51 52 public void closeConnection() { 53 if (conn != null) 54 { 55 try { 56 conn.close(); 57 } catch (SQLException e) { 58 log.error("Error closing connection.", e); 59 throw new JSExceptionWrapper(e); 60 } 61 62 conn = null; 63 } 64 } 65 66 67 protected abstract Connection createConnection(); 68 } 69 | Popular Tags |