ReportEngine:

* BF [ 1874419 ] JDBC Statement not close in a finally block
* organized imports
This commit is contained in:
teo_sarca 2008-02-18 11:00:41 +00:00
parent f56ca3c2fb
commit 6d57f81797
1 changed files with 90 additions and 39 deletions

View File

@ -16,25 +16,61 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.print; package org.compiere.print;
import java.awt.print.*; import java.awt.print.PrinterJob;
import java.io.*; import java.io.BufferedWriter;
import java.net.*; import java.io.File;
import java.sql.*; import java.io.FileNotFoundException;
import java.util.*; import java.io.FileOutputStream;
import java.util.logging.*; import java.io.IOException;
import javax.print.*; import java.io.OutputStream;
import javax.print.attribute.*; import java.io.OutputStreamWriter;
import javax.print.attribute.standard.*; import java.io.PrintWriter;
import javax.print.event.*; import java.io.Writer;
import javax.xml.transform.stream.*; import java.net.URI;
import org.apache.ecs.*; import java.sql.PreparedStatement;
import org.apache.ecs.xhtml.*; import java.sql.ResultSet;
import org.compiere.model.*; import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.Level;
import javax.print.DocFlavor;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;
import javax.print.attribute.standard.JobName;
import javax.print.event.PrintServiceAttributeEvent;
import javax.print.event.PrintServiceAttributeListener;
import javax.xml.transform.stream.StreamResult;
import org.adempiere.pdf.Document;
import org.adempiere.print.export.PrintDataExcelExporter; import org.adempiere.print.export.PrintDataExcelExporter;
import org.compiere.print.layout.*; import org.apache.ecs.XhtmlDocument;
import org.compiere.process.*; import org.apache.ecs.xhtml.table;
import org.compiere.util.*; import org.apache.ecs.xhtml.td;
import org.adempiere.pdf.*; import org.apache.ecs.xhtml.th;
import org.apache.ecs.xhtml.tr;
import org.compiere.model.MClient;
import org.compiere.model.MQuery;
import org.compiere.model.PrintInfo;
import org.compiere.model.X_C_DunningRunEntry;
import org.compiere.model.X_C_Invoice;
import org.compiere.model.X_C_Order;
import org.compiere.model.X_C_PaySelectionCheck;
import org.compiere.model.X_C_Project;
import org.compiere.model.X_C_RfQResponse;
import org.compiere.model.X_M_InOut;
import org.compiere.print.layout.LayoutEngine;
import org.compiere.process.ProcessInfo;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Language;
import org.compiere.util.Util;
/** /**
* Report Engine. * Report Engine.
@ -879,12 +915,14 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
+ " LEFT OUTER JOIN AD_PrintFormat pf ON (p.AD_ReportView_ID=pf.AD_ReportView_ID AND pf.AD_Client_ID IN (0,?)) " + " LEFT OUTER JOIN AD_PrintFormat pf ON (p.AD_ReportView_ID=pf.AD_ReportView_ID AND pf.AD_Client_ID IN (0,?)) "
+ "WHERE pi.AD_PInstance_ID=? " // #2 + "WHERE pi.AD_PInstance_ID=? " // #2
+ "ORDER BY pf.AD_Client_ID DESC, pf.IsDefault DESC"; // own first + "ORDER BY pf.AD_Client_ID DESC, pf.IsDefault DESC"; // own first
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Client_ID); pstmt.setInt(1, AD_Client_ID);
pstmt.setInt(2, pi.getAD_PInstance_ID()); pstmt.setInt(2, pi.getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
// Just get first // Just get first
if (rs.next()) if (rs.next())
{ {
@ -899,13 +937,15 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
IsForm = "Y".equals(rs.getString(6)); // required IsForm = "Y".equals(rs.getString(6)); // required
Client_ID = rs.getInt(7); Client_ID = rs.getInt(7);
} }
rs.close();
pstmt.close();
} }
catch (SQLException e1) catch (SQLException e1)
{ {
log.log(Level.SEVERE, "(1) - " + sql, e1); log.log(Level.SEVERE, "(1) - " + sql, e1);
} }
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Nothing found // Nothing found
if (AD_ReportView_ID == 0) if (AD_ReportView_ID == 0)
{ {
@ -918,9 +958,9 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
+ "WHERE pi.AD_PInstance_ID=?"; + "WHERE pi.AD_PInstance_ID=?";
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, pi.getAD_PInstance_ID()); pstmt.setInt(1, pi.getAD_PInstance_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
whereClause = ""; whereClause = "";
@ -930,13 +970,15 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
IsForm = "Y".equals(rs.getString(4)); // required IsForm = "Y".equals(rs.getString(4)); // required
Client_ID = AD_Client_ID; Client_ID = AD_Client_ID;
} }
rs.close();
pstmt.close();
} }
catch (SQLException e1) catch (SQLException e1)
{ {
log.log(Level.SEVERE, "(2) - " + sql, e1); log.log(Level.SEVERE, "(2) - " + sql, e1);
} }
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (AD_PrintFormat_ID == 0) if (AD_PrintFormat_ID == 0)
{ {
log.log(Level.SEVERE, "Report Info NOT found AD_PInstance_ID=" + pi.getAD_PInstance_ID() log.log(Level.SEVERE, "Report Info NOT found AD_PInstance_ID=" + pi.getAD_PInstance_ID()
@ -1131,11 +1173,13 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
+ " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) " + " AND pf.AD_Org_ID IN (0,d.AD_Org_ID) "
+ "ORDER BY pf.AD_Org_ID DESC"; + "ORDER BY pf.AD_Org_ID DESC";
// //
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, Record_ID); pstmt.setInt(1, Record_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) // first record only if (rs.next()) // first record only
{ {
if (type == CHECK || type == DUNNING || type == REMITTANCE if (type == CHECK || type == DUNNING || type == REMITTANCE
@ -1171,13 +1215,15 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
DocumentNo = rs.getString(11); DocumentNo = rs.getString(11);
} }
} }
rs.close();
pstmt.close();
} }
catch (Exception e) catch (Exception e)
{ {
log.log(Level.SEVERE, "Record_ID=" + Record_ID + ", SQL=" + sql, e); log.log(Level.SEVERE, "Record_ID=" + Record_ID + ", SQL=" + sql, e);
} }
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (AD_PrintFormat_ID == 0) if (AD_PrintFormat_ID == 0)
{ {
log.log(Level.SEVERE, "No PrintFormat found for Type=" + type + ", Record_ID=" + Record_ID); log.log(Level.SEVERE, "No PrintFormat found for Type=" + type + ", Record_ID=" + Record_ID);
@ -1226,21 +1272,25 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
+ "WHERE o.C_DocType_ID=dt.C_DocType_ID" + "WHERE o.C_DocType_ID=dt.C_DocType_ID"
+ " AND o.C_Order_ID=?"; + " AND o.C_Order_ID=?";
String DocSubTypeSO = null; String DocSubTypeSO = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_Order_ID); pstmt.setInt(1, C_Order_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
DocSubTypeSO = rs.getString(1); DocSubTypeSO = rs.getString(1);
rs.close();
pstmt.close();
} }
catch (SQLException e1) catch (SQLException e1)
{ {
log.log(Level.SEVERE, "(1) - " + sql, e1); log.log(Level.SEVERE, "(1) - " + sql, e1);
return null; // error return null; // error
} }
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (DocSubTypeSO == null) if (DocSubTypeSO == null)
DocSubTypeSO = ""; DocSubTypeSO = "";
// WalkIn Receipt, WalkIn Invoice, // WalkIn Receipt, WalkIn Invoice,
@ -1262,9 +1312,9 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
+ " ORDER BY M_InOut_ID DESC"; + " ORDER BY M_InOut_ID DESC";
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(sql, null); pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_Order_ID); pstmt.setInt(1, C_Order_ID);
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
{ {
// if (i == 1 && ADialog.ask(0, null, what[0] == INVOICE ? "PrintOnlyRecentInvoice?" : "PrintOnlyRecentShipment?")) break; // if (i == 1 && ADialog.ask(0, null, what[0] == INVOICE ? "PrintOnlyRecentInvoice?" : "PrintOnlyRecentShipment?")) break;
@ -1272,15 +1322,16 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
} }
else // No Document Found else // No Document Found
what[0] = ORDER; what[0] = ORDER;
rs.close();
pstmt.close();
} }
catch (SQLException e2) catch (SQLException e2)
{ {
log.log(Level.SEVERE, "(2) - " + sql, e2); log.log(Level.SEVERE, "(2) - " + sql, e2);
return null; return null;
} }
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
log.fine("Order => " + what[0] + " ID=" + what[1]); log.fine("Order => " + what[0] + " ID=" + what[1]);
return what; return what;
} // getDocumentWhat } // getDocumentWhat