From c2a1aea45c9bebb742ff85634efb9c2ea3d8f6e1 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 6 Sep 2019 17:51:12 +0200 Subject: [PATCH] IDEMPIERE-4045 Allow to create model from view (FHCA-1057) --- .../src/org/adempiere/util/ModelClassGenerator.java | 12 ++++++++---- .../org/adempiere/util/ModelInterfaceGenerator.java | 11 ++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/util/ModelClassGenerator.java b/org.adempiere.base/src/org/adempiere/util/ModelClassGenerator.java index f0455b41a5..f38a2df671 100644 --- a/org.adempiere.base/src/org/adempiere/util/ModelClassGenerator.java +++ b/org.adempiere.base/src/org/adempiere/util/ModelClassGenerator.java @@ -895,20 +895,24 @@ public class ModelClassGenerator file.mkdirs(); // complete sql + String filterViews = null; + if (tableLike.toString().contains("%")) { + filterViews = "AND (TableName IN ('RV_WarehousePrice','RV_BPartner') OR IsView='N')"; // special views + } StringBuilder sql = new StringBuilder(); sql.append("SELECT AD_Table_ID ") .append("FROM AD_Table ") - .append("WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')") // special views - .append(" OR IsView='N')") - .append(" AND IsActive = 'Y' AND TableName NOT LIKE '%_Trl' "); + .append("WHERE IsActive = 'Y' AND TableName NOT LIKE '%_Trl' "); // Autodetect if we need to use IN or LIKE clause - teo_sarca [ 3020640 ] if (tableLike.indexOf(",") == -1) sql.append(" AND TableName LIKE ").append(tableLike); else sql.append(" AND TableName IN (").append(tableLike).append(")"); // only specific tables sql.append(" AND ").append(entityTypeFilter.toString()); + if (filterViews != null) { + sql.append(filterViews); + } sql.append(" ORDER BY TableName"); - // PreparedStatement pstmt = null; ResultSet rs = null; diff --git a/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java b/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java index e6b85f7f38..bac85f19c5 100644 --- a/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java +++ b/org.adempiere.base/src/org/adempiere/util/ModelInterfaceGenerator.java @@ -813,18 +813,23 @@ public class ModelInterfaceGenerator file.mkdirs(); // complete sql + String filterViews = null; + if (tableLike.toString().contains("%")) { + filterViews = "AND (TableName IN ('RV_WarehousePrice','RV_BPartner') OR IsView='N')"; // special views + } StringBuilder sql = new StringBuilder(); sql.append("SELECT AD_Table_ID ") .append("FROM AD_Table ") - .append("WHERE (TableName IN ('RV_WarehousePrice','RV_BPartner')") // special views - .append(" OR IsView='N')") - .append(" AND IsActive = 'Y' AND TableName NOT LIKE '%_Trl' "); + .append("WHERE IsActive = 'Y' AND TableName NOT LIKE '%_Trl' "); // Autodetect if we need to use IN or LIKE clause - teo_sarca [ 3020640 ] if (tableLike.indexOf(",") == -1) sql.append(" AND TableName LIKE ").append(tableLike); else sql.append(" AND TableName IN (").append(tableLike).append(")"); // only specific tables sql.append(" AND ").append(entityTypeFilter.toString()); + if (filterViews != null) { + sql.append(filterViews); + } sql.append(" ORDER BY TableName"); //