From c8f9f36295d4f8f48f2d4afe854e83aa81f6f040 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Thu, 21 Nov 2013 20:35:21 +0800 Subject: [PATCH] IDEMPIERE-1510 Exception when closing Report Wizard ( ticket #1003516 ) --- .../src/org/compiere/print/DataEngine.java | 10 ++++++-- .../src/org/compiere/print/ReportEngine.java | 5 ++-- .../src/org/compiere/util/DB.java | 24 +++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/DataEngine.java b/org.adempiere.base/src/org/compiere/print/DataEngine.java index 00c82ca7b4..9a09e332b9 100644 --- a/org.adempiere.base/src/org/compiere/print/DataEngine.java +++ b/org.adempiere.base/src/org/compiere/print/DataEngine.java @@ -191,8 +191,14 @@ public class DataEngine return null; } if (format.isTranslationView() && tableName.toLowerCase().endsWith("_v")) // _vt not just _v - tableName += "t"; - format.setTranslationViewQuery (query); + { + boolean hasVT = DB.isTableOrViewExists(tableName+"t"); + if (hasVT) + { + tableName += "t"; + format.setTranslationViewQuery (query); + } + } // PrintData pd = getPrintDataInfo (ctx, format, query, reportName, tableName); if (pd == null) diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index 5b24b3d986..e6d95f23a0 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -1244,6 +1244,8 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) if (format == null) return null; // + format.setTranslationLanguage(format.getLanguage()); + // PrintInfo info = new PrintInfo (pi); info.setAD_Table_ID(AD_Table_ID); @@ -1507,8 +1509,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) // Get Format & Data MPrintFormat format = MPrintFormat.get (ctx, AD_PrintFormat_ID, false); format.setLanguage(language); // BP Language if Multi-Lingual - // if (!Env.isBaseLanguage(language, DOC_TABLES[type])) - format.setTranslationLanguage(language); + format.setTranslationLanguage(language); // query MQuery query = new MQuery(format.getAD_Table_ID()); query.addRestriction(DOC_IDS[type], MQuery.EQUAL, Record_ID); diff --git a/org.adempiere.base/src/org/compiere/util/DB.java b/org.adempiere.base/src/org/compiere/util/DB.java index 1dd97303d1..67b82790de 100644 --- a/org.adempiere.base/src/org/compiere/util/DB.java +++ b/org.adempiere.base/src/org/compiere/util/DB.java @@ -22,6 +22,7 @@ import java.io.FileOutputStream; import java.math.BigDecimal; import java.sql.CallableStatement; import java.sql.Connection; +import java.sql.DatabaseMetaData; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -2319,4 +2320,27 @@ public final class DB } } + /** + * @param tableName + * @return true if table or view with name=tableName exists in db + */ + public static boolean isTableOrViewExists(String tableName) { + Connection conn = getConnectionRO(); + ResultSet rs = null; + try { + DatabaseMetaData metadata = conn.getMetaData(); + rs = metadata.getTables(null, null, (DB.isPostgreSQL() ? tableName.toLowerCase() : tableName.toUpperCase()), null); + if (rs.next()) { + return true; + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + DB.close(rs); + try { + conn.close(); + } catch (SQLException e) {} + } + return false; + } } // DB