fixes issue 14818: Check for views on each dal-startup are to 'verbose'
authorMartin Taal <martin.taal@openbravo.com>
Thu, 14 Oct 2010 19:34:11 +0200
changeset 8556 8f1e3114223e
parent 8555 ff88423ee721
child 8557 c4a8d1ac4bd7
fixes issue 14818: Check for views on each dal-startup are to 'verbose'
src/build.xml
src/org/openbravo/base/gen/GenerateEntitiesTask.java
src/org/openbravo/base/gen/ModelProviderComponent.java
src/org/openbravo/base/gen/gen_entity.oaw
src/org/openbravo/base/model/Column.java
src/org/openbravo/base/model/ModelProvider.java
src/org/openbravo/base/model/domaintype/BaseForeignKeyDomainType.java
src/org/openbravo/base/session/OBPropertiesProvider.java
--- a/src/build.xml	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/build.xml	Thu Oct 14 19:34:11 2010 +0200
@@ -243,9 +243,10 @@
     <taskdef name="workflow" classpathref="project.class.path" classname="org.openbravo.base.gen.GenerateEntitiesTask" />
     <!-- debug="true" will perform the in-memory model initialization before generating entities
 	if an error occurs then, then a stacktrace is printed. -->
-    <workflow debug="false" srcGenPath="${base.src.gen}" propertiesFile="${base.config}/Openbravo.properties" file="${base.src}/org/openbravo/base/gen/gen_entity.oaw" fork="true" maxmemory="${build.maxmemory}">
+    <workflow debug="false" friendlyWarnings="${friendlyWarnings}" srcGenPath="${base.src.gen}" propertiesFile="${base.config}/Openbravo.properties" file="${base.src}/org/openbravo/base/gen/gen_entity.oaw" fork="true" maxmemory="${build.maxmemory}">
       <param name="ob.properties.location" value="${base.config}/Openbravo.properties" />
       <param name="base.src.gen" value="${base.src.gen}" />
+      <param name="friendlyWarnings" value="${friendlyWarnings}"/>
       <classpath>
         <path refid="project.class.path" />
       </classpath>
@@ -279,9 +280,10 @@
     <taskdef name="workflow" classpathref="project.class.path" classname="org.openbravo.base.gen.GenerateEntitiesTask" />
     <!-- debug="true" will perform the in-memory model initialization before generating entities
 	if an error occurs then, then a stacktrace is printed. -->
-    <workflow debug="false" srcGenPath="${base.src.gen}" propertiesFile="${base.config}/Openbravo.properties" file="${base.src}/org/openbravo/base/gen/gen_entity.oaw" fork="true" maxmemory="${build.maxmemory}">
+    <workflow debug="false" friendlyWarnings="${friendlyWarnings}" srcGenPath="${base.src.gen}" propertiesFile="${base.config}/Openbravo.properties" file="${base.src}/org/openbravo/base/gen/gen_entity.oaw" fork="true" maxmemory="${build.maxmemory}">
       <param name="ob.properties.location" value="${base.config}/Openbravo.properties" />
       <param name="base.src.gen" value="${base.src.gen}" />
+      <param name="friendlyWarnings" value="${friendlyWarnings}"/>
       <syspropertyset>
          <propertyref name="java.security.egd" />
       </syspropertyset>
--- a/src/org/openbravo/base/gen/GenerateEntitiesTask.java	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/org/openbravo/base/gen/GenerateEntitiesTask.java	Thu Oct 14 19:34:11 2010 +0200
@@ -54,6 +54,14 @@
   private String providerConfigDirectory;
   private boolean debug;
 
+  public boolean getFriendlyWarnings() {
+    return OBPropertiesProvider.isFriendlyWarnings();
+  }
+
+  public void setFriendlyWarnings(boolean doFriendlyWarnings) {
+    OBPropertiesProvider.setFriendlyWarnings(doFriendlyWarnings);
+  }
+
   public String getPropertiesFile() {
     return propertiesFile;
   }
--- a/src/org/openbravo/base/gen/ModelProviderComponent.java	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/org/openbravo/base/gen/ModelProviderComponent.java	Thu Oct 14 19:34:11 2010 +0200
@@ -53,6 +53,14 @@
     wc.set("model", ModelProvider.getInstance());
   }
 
+  public boolean getFriendlyWarnings() {
+    return OBPropertiesProvider.isFriendlyWarnings();
+  }
+
+  public void setFriendlyWarnings(boolean doFriendlyWarnings) {
+    OBPropertiesProvider.setFriendlyWarnings(doFriendlyWarnings);
+  }
+
   public void setContainer(CompositeComponent arg0) {
   }
 
--- a/src/org/openbravo/base/gen/gen_entity.oaw	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/org/openbravo/base/gen/gen_entity.oaw	Thu Oct 14 19:34:11 2010 +0200
@@ -23,6 +23,7 @@
 	<!-- sets the list of Tables in the model slot -->
 	<component class="org.openbravo.base.gen.ModelProviderComponent">
 		<propFile value="${ob.properties.location}" />
+    <friendlyWarnings value="${friendlyWarnings}" />
 	</component>	
 	<component class="oaw.xpand2.Generator">
 		 <metaModel class="oaw.type.impl.java.JavaMetaModel"/>
--- a/src/org/openbravo/base/model/Column.java	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/org/openbravo/base/model/Column.java	Thu Oct 14 19:34:11 2010 +0200
@@ -30,6 +30,7 @@
 import org.openbravo.base.model.domaintype.PrimitiveDomainType;
 import org.openbravo.base.model.domaintype.StringDomainType;
 import org.openbravo.base.model.domaintype.StringEnumerateDomainType;
+import org.openbravo.base.session.OBPropertiesProvider;
 
 /**
  * Used by the {@link ModelProvider ModelProvider}, maps the AD_Column table in the application
@@ -280,9 +281,11 @@
       setReferenceType(((ForeignKeyDomainType) getDomainType())
           .getForeignKeyColumn(getColumnName()));
     } catch (final Exception e) {
-      log.error("No referenced column found: error >> tableName: " + table.getTableName()
-          + " - columnName: " + getColumnName(), e);
-      e.printStackTrace();
+      if (!OBPropertiesProvider.isFriendlyWarnings()) {
+        log.error("No referenced column found: error >> tableName: " + table.getTableName()
+            + " - columnName: " + getColumnName(), e);
+        e.printStackTrace();
+      }
     }
   }
 
--- a/src/org/openbravo/base/model/ModelProvider.java	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/org/openbravo/base/model/ModelProvider.java	Thu Oct 14 19:34:11 2010 +0200
@@ -38,6 +38,7 @@
 import org.openbravo.base.model.domaintype.StringDomainType;
 import org.openbravo.base.provider.OBProvider;
 import org.openbravo.base.provider.OBSingleton;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.base.session.SessionFactoryController;
 import org.openbravo.base.session.UniqueConstraintColumn;
 import org.openbravo.base.util.Check;
@@ -383,10 +384,12 @@
           log.debug("Setting targetEntity and reference Property for " + thisProp);
           final Column thatColumn = c.getReferenceType();
           if (thatColumn == null) {
-            log
-                .error("Property "
-                    + thisProp
-                    + " is mapped incorrectly, there is no reference column for it, removing from the mapping");
+            if (!OBPropertiesProvider.isFriendlyWarnings()) {
+              log
+                  .error("Property "
+                      + thisProp
+                      + " is mapped incorrectly, there is no referenced column for it, removing from the mapping");
+            }
             thisProp.getEntity().getProperties().remove(thisProp);
             if (thisProp.getEntity().getIdProperties().remove(thisProp)) {
               Check.fail("Incorrect mapping for property " + thisProp
@@ -667,8 +670,15 @@
       getModel();
     // search case insensitive!
     final Table table = tablesByTableName.get(tableName.toLowerCase());
-    if (table == null)
-      Check.fail("Table: " + tableName + " not found in runtime model, is it maybe inactive?");
+    if (table == null) {
+      if (OBPropertiesProvider.isFriendlyWarnings()) {
+        // this error won't be logged...
+        throw new IllegalArgumentException("Table: " + tableName
+            + " not found in runtime model, is it maybe inactive?");
+      } else {
+        Check.fail("Table: " + tableName + " not found in runtime model, is it maybe inactive?");
+      }
+    }
     return table;
   }
 
--- a/src/org/openbravo/base/model/domaintype/BaseForeignKeyDomainType.java	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/org/openbravo/base/model/domaintype/BaseForeignKeyDomainType.java	Thu Oct 14 19:34:11 2010 +0200
@@ -26,6 +26,7 @@
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
 import org.openbravo.base.model.Reference;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.base.validation.ValidationException;
 
 /**
@@ -48,9 +49,16 @@
       return getModelProvider().getTable(getReferedTableName(columnName)).getPrimaryKeyColumns()
           .get(0);
     } catch (final Exception e) {
-      throw new OBException("Reference column for " + columnName
-          + " not found in runtime model [ref: " + getReference().getId()
-          + ", encountered exception " + e.getMessage(), e);
+      if (OBPropertiesProvider.isFriendlyWarnings()) {
+        // won't be logged
+        throw new IllegalArgumentException("Reference column for " + columnName
+            + " not found in runtime model [ref: " + getReference().getId()
+            + ", encountered exception " + e.getMessage(), e);
+      } else {
+        throw new OBException("Reference column for " + columnName
+            + " not found in runtime model [ref: " + getReference().getId()
+            + ", encountered exception " + e.getMessage(), e);
+      }
     }
   }
 
--- a/src/org/openbravo/base/session/OBPropertiesProvider.java	Thu Oct 14 18:51:38 2010 +0200
+++ b/src/org/openbravo/base/session/OBPropertiesProvider.java	Thu Oct 14 19:34:11 2010 +0200
@@ -44,6 +44,16 @@
 
   private static OBPropertiesProvider instance = new OBPropertiesProvider();
 
+  private static boolean friendlyWarnings = false;
+
+  public static boolean isFriendlyWarnings() {
+    return friendlyWarnings;
+  }
+
+  public static void setFriendlyWarnings(boolean doFriendlyWarnings) {
+    friendlyWarnings = doFriendlyWarnings;
+  }
+
   private Properties obProperties = null;
   private Document formatXML;