diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioAbstract.java b/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioAbstract.java index 8e1267d76..a95901904 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioAbstract.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioAbstract.java @@ -1,14 +1,9 @@ package com.rjconsultores.ventaboletos.relatorios.render; -import java.io.InputStream; import java.sql.Connection; import java.util.HashMap; import java.util.Map; -import net.sf.jasperreports.engine.JRDataSource; -import net.sf.jasperreports.engine.JasperFillManager; -import net.sf.jasperreports.engine.JasperPrint; - import com.rjconsultores.ventaboletos.relatorios.utilitarios.IDataSource; import com.rjconsultores.ventaboletos.relatorios.utilitarios.IRenderRelatorio; import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio; @@ -25,9 +20,7 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio { protected Relatorio relatorio; protected IDataSource datasource; protected Connection connection; - private Map parametros = new HashMap(); - protected JasperPrint jasperPrint; - + protected Map parametros = new HashMap(); /** * @param relatorio @@ -39,7 +32,7 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio { this.connection = connection; this.relatorio = relatorio; } - + /** * Renderiza o relatório solicitado * @@ -51,7 +44,6 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio { */ protected abstract byte[] render(SaidaRelatorio saida) throws Exception; - /** * @param relatorio * Enum do tipo Relatorio contendo as configurações de geração de todos os relatórios @@ -77,30 +69,8 @@ public abstract class RenderRelatorioAbstract implements IRenderRelatorio { @Override public byte[] getConteudo(SaidaRelatorio saida) throws Exception { - - if(this.jasperPrint == null){ - - if(this.relatorio.getParametros()!=null) - this.relatorio.getParametros().initParametros(this.parametros, this.connection); - - InputStream iStemplate = this.getClass().getResourceAsStream("/com/rjconsultores/ventaboletos/relatorios/templates/"+this.relatorio.getTemplate()); - - - if (this.relatorio.getDatasource() != null) - this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), (JRDataSource) this.datasource); - else - this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), this.connection); - - } - - - - - return this.render(saida); } - - } diff --git a/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java b/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java index a66510941..d8fd4e8a9 100644 --- a/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java +++ b/src/java/com/rjconsultores/ventaboletos/relatorios/render/RenderRelatorioJasper.java @@ -5,7 +5,6 @@ import java.io.InputStream; import java.sql.Connection; import net.sf.jasperreports.engine.JRDataSource; -import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JasperExportManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; @@ -23,6 +22,8 @@ import com.rjconsultores.ventaboletos.relatorios.utilitarios.SaidaRelatorio; */ public class RenderRelatorioJasper extends RenderRelatorioAbstract { + protected JasperPrint jasperPrint; + /** * @param relatorio * Enum do tipo Relatorio contendo as configurações de geração de todos os relatórios @@ -59,16 +60,29 @@ public class RenderRelatorioJasper extends RenderRelatorioAbstract { * @see com.rjconsultores.ventaboletos.relatorios.utilitarios.IRenderRelatorio#render() */ @Override - protected byte[] render(SaidaRelatorio saida) throws JRException { + protected byte[] render(SaidaRelatorio saida) throws Exception { byte[] conteudo = null; - + + if (this.jasperPrint == null) { + + if (this.relatorio.getParametros() != null) + this.relatorio.getParametros().initParametros(this.parametros, this.connection); + + InputStream iStemplate = this.getClass().getResourceAsStream("/com/rjconsultores/ventaboletos/relatorios/templates/" + this.relatorio.getTemplate()); + + if (this.relatorio.getDatasource() != null) + this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), (JRDataSource) this.datasource); + else + this.jasperPrint = JasperFillManager.fillReport(iStemplate, this.getParametros(), this.connection); + + } switch (saida) { case PDF: conteudo = JasperExportManager.exportReportToPdf(this.jasperPrint); break; - + case XLS: JRXlsExporter exporterXLS = new JRXlsExporter(); ByteArrayOutputStream output = new ByteArrayOutputStream();