wilian 2016-05-10 18:44:18 +00:00
parent 8e06490399
commit a6e42ca262
3 changed files with 33 additions and 15 deletions

View File

@ -29,7 +29,15 @@ public class ArrayDataSource implements IDataSource {
public ArrayDataSource(Relatorio relatorio) throws Exception {
this.relatorio = relatorio;
this.dados = new ArrayList<Map<String, Object>>();
this.initDados();
try {
this.initDados();
} catch (Exception e) {
throw e;
} finally {
if(this.relatorio != null) {
this.relatorio.closeConnection();
}
}
this.rowNum = -1;
}

View File

@ -25,7 +25,15 @@ public class DataSource implements IDataSource {
public DataSource(Relatorio relatorio) throws Exception {
this.relatorio = relatorio;
this.initDados();
try {
this.initDados();
} catch (Exception e) {
throw e;
} finally {
if(this.relatorio != null) {
this.relatorio.closeConnection();
}
}
this.rowNum = -1;
}

View File

@ -1,17 +1,16 @@
package com.rjconsultores.ventaboletos.relatorios.utilitarios;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.apache.log4j.Logger;
import com.rjconsultores.ventaboletos.relatorios.render.RenderRelatorioJasper;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
/**
* @author Bruno H. G. Gouvêa <bruno@rjconsultores.com.br>
*
@ -90,12 +89,7 @@ public abstract class Relatorio {
public void setCustomDataSource(boolean closeConnection,IDataSource iDataSource) {
this.customDataSource = iDataSource;
if (closeConnection){
try {
if (!this.conexao.isClosed())
this.conexao.close();
} catch (SQLException e) {
log.error("Erro ao fechar a conexion", e);
}
closeConnection();
}
}
@ -126,12 +120,9 @@ public abstract class Relatorio {
conteudo = this.render.render(saida);
} catch (Exception e) {
if (!this.conexao.isClosed())
this.conexao.close();
throw e;
} finally {
if (!this.conexao.isClosed())
this.conexao.close();
closeConnection();
}
return conteudo;
@ -153,5 +144,16 @@ public abstract class Relatorio {
public void setNomeSubReporte(String[] nomeSubReporte) {
this.nomeSubReporte = nomeSubReporte;
}
public void closeConnection() {
try {
if(getConexao() != null && !getConexao().isClosed()) {
getConexao().close();
log.info("Conexão relatorio fechada");
}
} catch (Exception e) {
log.error("Erro ao fechar a conexion", e);
}
}
}