details:   https://code.openbravo.com/erp/devel/pi/rev/a51489ce38ee
changeset: 33345:a51489ce38ee
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Thu Feb 01 09:24:58 2018 +0100
summary:   [ha] Added protection against ping disabling while processing import 
entries

details:   https://code.openbravo.com/erp/devel/pi/rev/e47e5333d83c
changeset: 33346:e47e5333d83c
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Thu Feb 01 09:35:21 2018 +0100
summary:   [ha] Reset processing attributes when a new node can take the 
leadership

details:   https://code.openbravo.com/erp/devel/pi/rev/38381d798fb9
changeset: 33347:38381d798fb9
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Thu Feb 01 09:54:23 2018 +0100
summary:   [ha] Added log info when disabling ping while processing

details:   https://code.openbravo.com/erp/devel/pi/rev/c6e764414f56
changeset: 33348:c6e764414f56
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Thu Feb 01 10:09:54 2018 +0100
summary:   [ha] typo

details:   https://code.openbravo.com/erp/devel/pi/rev/e8d5b3cd9f68
changeset: 33349:e8d5b3cd9f68
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Thu Feb 01 12:48:56 2018 +0100
summary:   [ha] Move the start/end processing notification into the 
ImportEntryProcessor

details:   https://code.openbravo.com/erp/devel/pi/rev/c0ea9ee48292
changeset: 33350:c0ea9ee48292
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Thu Feb 01 12:55:00 2018 +0100
summary:   [ha] Fix typo

details:   https://code.openbravo.com/erp/devel/pi/rev/f2657a28f21e
changeset: 33351:f2657a28f21e
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Thu Feb 01 16:54:27 2018 +0100
summary:   [ha] Added missing javadoc

details:   https://code.openbravo.com/erp/devel/pi/rev/0e1dbbcfee78
changeset: 33352:0e1dbbcfee78
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Fri Feb 02 15:15:14 2018 +0100
summary:   [ha] Show service name in log message

details:   https://code.openbravo.com/erp/devel/pi/rev/63b0c3659199
changeset: 33353:63b0c3659199
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Mon Feb 05 10:01:27 2018 +0100
summary:   related to issue 37734: Protection against ping disabling + minor 
improvements

diffstat:

 .hgsigs                                                                        
                                                 |    1 +
 .hgtags                                                                        
                                                 |    1 +
 legal/Licensing.txt                                                            
                                                 |    2 +-
 
modules/org.openbravo.apachejdbcconnectionpool/src/org/openbravo/apachejdbcconnectionpool/ConnectionInitializerInterceptor.java
 |   26 +-
 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java
            |    1 +
 
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
                |   32 +-
 src-core/src/org/openbravo/database/SessionInfo.java                           
                                                 |  110 ++++-
 src-db/database/sourcedata/AD_MENU.xml                                         
                                                 |   14 -
 src-db/database/sourcedata/AD_MESSAGE.xml                                      
                                                 |    4 +-
 src-db/database/sourcedata/AD_MODEL_OBJECT.xml                                 
                                                 |   12 -
 src-db/database/sourcedata/AD_PROCESS.xml                                      
                                                 |   27 -
 src-db/database/sourcedata/AD_TREENODE.xml                                     
                                                 |   11 -
 src-db/database/sourcedata/OBUISEL_SELECTOR.xml                                
                                                 |    2 +-
 src-test/src/org/openbravo/test/AllWebserviceTests.java                        
                                                 |    2 +-
 src-test/src/org/openbravo/test/datasource/LinkToParentTreeDataSourceTest.java 
                                                 |  135 ++++++--
 src/org/openbravo/base/secureApp/LoginHandler.java                             
                                                 |    4 +-
 src/org/openbravo/cluster/ClusterService.java                                  
                                                 |  153 +++++++++-
 src/org/openbravo/cluster/ClusterServiceManager.java                           
                                                 |    6 +-
 src/org/openbravo/cluster/ClusterService_data.xsql                             
                                                 |   13 +
 src/org/openbravo/cluster/JmxClusterServiceManager.java                        
                                                 |   31 +-
 src/org/openbravo/erpCommon/ad_callouts/SL_TableAudit.java                     
                                                 |   12 +-
 src/org/openbravo/erpCommon/ad_process/UpdateAuditTrail.java                   
                                                 |  162 ----------
 
src/org/openbravo/erpCommon/ad_reports/ReportInvoiceCustomerDimensionalAnalysesXLS.jrxml
                                        |    2 +-
 src/org/openbravo/service/importprocess/ImportEntryArchiveManager.java         
                                                 |    3 +
 src/org/openbravo/service/importprocess/ImportEntryManager.java                
                                                 |   18 +
 src/org/openbravo/service/importprocess/ImportEntryProcessor.java              
                                                 |    2 +
 src/org/openbravo/service/web/BaseWebServiceServlet.java                       
                                                 |   15 +-
 27 files changed, 451 insertions(+), 350 deletions(-)

diffs (truncated from 1345 to 300 lines):

diff -r 7afc62cc7b3c -r 63b0c3659199 .hgsigs
--- a/.hgsigs   Thu Jan 25 16:58:29 2018 +0100
+++ b/.hgsigs   Mon Feb 05 10:01:27 2018 +0100
@@ -222,4 +222,5 @@
 ff7be0e0ba8762069ad86523828a57139b396d39 0 
iEYEABECAAYFAlm/UPkACgkQCX/oGf+2qkM8UQCdGDxGviT6mh8nKnu2HP1qzZzX0cYAoJaBd9WSUNj2Dlh2yjJT+7zYxKcC
 54cdd8284122f787eac4b4ab67b4ab4584ddcccb 0 
iEYEABECAAYFAln8YP0ACgkQCX/oGf+2qkNbKACgxFsQqRE0goPX4VewSccTQcGZRVEAnitoyHAuUroUJpFUFLztc6pzkUL2
 bbeae307872835b1e84136c537adec44b7a0b3c1 0 
iEYEABECAAYFAlpDLAIACgkQCX/oGf+2qkNiugCgj1TTu2BeYoAqAqD08Gci3lHJvogAnAvmNL987nIAckknQ1CosIUDmA+K
+2e43174aba46ec6956a0e703bbb9bee5292c871a 0 
iEYEABECAAYFAlpuyUwACgkQCX/oGf+2qkPuJgCePIRg5ennwj6kgpOnyxZCPUV54Y0Ani30NnQNuNkXNkBMyykw2JfW21Vs
 43d95f7cb67084eb978752359847ab28b9aa14f6 0 
iEYEABECAAYFAlpEpSMACgkQCX/oGf+2qkNdMACdGNGo6rpHht3lNH3FmwtsNcIe65sAn1sM9rBx/Sm3ytwcL2C5irUyD05J
diff -r 7afc62cc7b3c -r 63b0c3659199 .hgtags
--- a/.hgtags   Thu Jan 25 16:58:29 2018 +0100
+++ b/.hgtags   Mon Feb 05 10:01:27 2018 +0100
@@ -233,4 +233,5 @@
 a8925ad2d61f4625aa62c1ee31babecaa73b787f 3.0PR17Q3
 452e6c576f1db52e686cf3138099790e242e7927 3.0PR17Q3.1
 f500d43a59bb69265a7aa704a9fd20bffd68c8a9 3.0PR17Q3.2
+dd65065492e55421c107be4c87894a508bb1244d 3.0PR17Q3.3
 a8b6912d30a34e4a7d0873fc0fe53df228417b49 3.0PR17Q4
diff -r 7afc62cc7b3c -r 63b0c3659199 legal/Licensing.txt
--- a/legal/Licensing.txt       Thu Jan 25 16:58:29 2018 +0100
+++ b/legal/Licensing.txt       Mon Feb 05 10:01:27 2018 +0100
@@ -3,7 +3,7 @@
 This license file applies to the Openbravo ERP software (the "Openbravo
 Software"), except as described below.
 
-This product is Copyright 2001-2017 Openbravo S.L.U.  For other detailed 
notice,
+This product is Copyright 2001-2018 Openbravo S.L.U.  For other detailed 
notice,
 see the "NOTICE" file with this distribution.
 
 This product is free software; you can redistribute it and/or modify
diff -r 7afc62cc7b3c -r 63b0c3659199 
modules/org.openbravo.apachejdbcconnectionpool/src/org/openbravo/apachejdbcconnectionpool/ConnectionInitializerInterceptor.java
--- 
a/modules/org.openbravo.apachejdbcconnectionpool/src/org/openbravo/apachejdbcconnectionpool/ConnectionInitializerInterceptor.java
   Thu Jan 25 16:58:29 2018 +0100
+++ 
b/modules/org.openbravo.apachejdbcconnectionpool/src/org/openbravo/apachejdbcconnectionpool/ConnectionInitializerInterceptor.java
   Mon Feb 05 10:01:27 2018 +0100
@@ -38,7 +38,8 @@
 public class ConnectionInitializerInterceptor extends JdbcInterceptor 
implements
     PoolInterceptorProvider {
 
-  private static final String INITIALIZED = "OB_INITIALIZED";
+  private static final String SESSION_CONFIG_APPLIED = "OB_INITIALIZED";
+  private static final String SESSION_INFO_APPLIED = 
"SESSION_INFO_INITIALIZED";
 
   String rbdms = (String) 
OBPropertiesProvider.getInstance().getOpenbravoProperties()
       .get("bbdd.rdbms");
@@ -51,11 +52,8 @@
   public void reset(ConnectionPool parent, PooledConnection con) {
     if (con != null) {
       HashMap<Object, Object> attributes = con.getAttributes();
-      Boolean connectionInitialized = (Boolean) attributes.get(INITIALIZED);
-      if (connectionInitialized == null || connectionInitialized == false) {
-        if (!isReadOnlyPool(parent)) {
-          SessionInfo.initDB(con.getConnection(), rbdms);
-        }
+      Boolean sessionInfoApplied = (Boolean) 
attributes.get(SESSION_CONFIG_APPLIED);
+      if (sessionInfoApplied == null || !sessionInfoApplied) {
         PreparedStatement pstmt = null;
         try {
           final Properties props = 
OBPropertiesProvider.getInstance().getOpenbravoProperties();
@@ -73,7 +71,21 @@
             throw new OBException(e);
           }
         }
-        attributes.put(INITIALIZED, true);
+        attributes.put(SESSION_CONFIG_APPLIED, true);
+      }
+
+      Boolean sessionInfoInitialized = (Boolean) 
attributes.get(SESSION_INFO_APPLIED);
+      if (sessionInfoInitialized == null || !sessionInfoInitialized) {
+        boolean initialized = false;
+        if (isReadOnlyPool(parent)) {
+          initialized = true;
+        } else {
+          if (SessionInfo.isInitialized()) {
+            SessionInfo.initDB(con.getConnection(), rbdms);
+            initialized = true;
+          }
+        }
+        attributes.put(SESSION_INFO_APPLIED, initialized);
       }
     }
   }
diff -r 7afc62cc7b3c -r 63b0c3659199 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java
--- 
a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java
      Thu Jan 25 16:58:29 2018 +0100
+++ 
b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java
      Mon Feb 05 10:01:27 2018 +0100
@@ -429,6 +429,7 @@
     }
     final OBQuery<BaseOBObject> query = 
OBDal.getInstance().createQuery(entity.getName(),
         whereClause.toString());
+    query.setFilterOnActive(false);
 
     final List<Object> parameters = new ArrayList<Object>();
     parameters.add(nodeIdStr);
diff -r 7afc62cc7b3c -r 63b0c3659199 
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
--- 
a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
  Thu Jan 25 16:58:29 2018 +0100
+++ 
b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
  Mon Feb 05 10:01:27 2018 +0100
@@ -774,18 +774,42 @@
       delete target.view.isRefreshing;
       target.view.toolBar.updateButtonState();
     }
+
+    // in case of response timeout, show the error in the view if possible
+    if (this.isServerTimeoutResponse(response) && 
this.canShowErrorMessage(target)) {
+      target.view.setErrorMessageFromResponse(response, response.data, 
request);
+    }
+
     if (!request.willHandleError) {
       this._originalhandleError(response, request);
     }
   },
 
+  isServerTimeoutResponse: function (response) {
+    return response.status === isc.RPCResponse.STATUS_SERVER_TIMEOUT;
+  },
+
+  canShowErrorMessage: function (target) {
+    return target && target.view && 
isc.isA.Function(target.view.setErrorMessageFromResponse);
+  },
+
   _originalEvalResult: isc.RPCManager.evalResult,
   evalResult: function (request, response, results) {
-    // if the response contains an error status, call the errorCallback
-    if (response.status !== isc.RPCResponse.STATUS_SUCCESS && 
isc.isA.Function(request.errorCallback)) {
-      request.errorCallback(request, response);
+    if (response.status !== isc.RPCResponse.STATUS_SUCCESS) {
+      if (isc.isA.Function(request.errorCallback)) {
+        // if the response contains an error status, call the errorCallback
+        request.errorCallback(request, response);
+      } else {
+        // try to handle the error in the standard way
+        this.handleError(response, request);
+      }
     }
-    return this._originalEvalResult(request, response, results);
+
+    return this._originalEvalResult(request, response, 
this.sanitizeResults(results));
+  },
+
+  sanitizeResults: function (results) {
+    return isc.isA.Object(results) ? JSON.stringify(results) : results;
   },
 
   // Escape characters that are not properly handled in JavaScript's eval. See 
issue #36788.
diff -r 7afc62cc7b3c -r 63b0c3659199 
src-core/src/org/openbravo/database/SessionInfo.java
--- a/src-core/src/org/openbravo/database/SessionInfo.java      Thu Jan 25 
16:58:29 2018 +0100
+++ b/src-core/src/org/openbravo/database/SessionInfo.java      Mon Feb 05 
10:01:27 2018 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2009-2017 Openbravo SLU
+ * All portions are Copyright (C) 2009-2018 Openbravo SLU
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -31,6 +31,8 @@
  * 
  */
 public class SessionInfo {
+  private static final String JDBC_CONNECTION_POOL_CLASS_NAME = 
"org.openbravo.apachejdbcconnectionpool.JdbcExternalConnectionPool";
+
   private static final Logger log4j = Logger.getLogger(SessionInfo.class);
 
   public static final String IMPORT_ENTRY_PROCESS = "IE";
@@ -40,6 +42,7 @@
    */
   private static boolean isAuditActive = false;
   private static boolean usageAuditActive = false;
+  private static boolean initialized = false;
 
   /*
    * The following variables track per thread the information about the 
current 'user' of the thread
@@ -110,38 +113,80 @@
    *          Database, only action is take for POSTGRESQL
    */
   public static void initDB(Connection conn, String rdbms) {
+    if (adContextInfoShouldBeCreated(conn, rdbms)) {
+      createAdContextInfoTable(conn);
+    }
+  }
 
-    if (rdbms != null && rdbms.equals("POSTGRE")) {
-      // Create temporary table
-      PreparedStatement psQuery = null;
-      PreparedStatement psCreate = null;
-      try {
-        if (conn.isReadOnly()) {
-          return;
-        }
+  private static void createAdContextInfoTable(Connection conn) {
+    // Create temporary table
+    PreparedStatement psCreate = null;
+    try {
+      StringBuffer sql = new StringBuffer();
+      sql.append("CREATE TEMPORARY TABLE AD_CONTEXT_INFO");
+      sql.append("(AD_USER_ID VARCHAR(32), ");
+      sql.append("  AD_SESSION_ID VARCHAR(32),");
+      sql.append("  PROCESSTYPE VARCHAR(60), ");
+      sql.append("  PROCESSID VARCHAR(32)) on commit preserve rows");
+      psCreate = getPreparedStatement(conn, sql.toString());
+      psCreate.execute();
+    } catch (Exception e) {
+      log4j.error("Error initializating audit infrastructure", e);
+    } finally {
+      releasePreparedStatement(psCreate);
+    }
+  }
 
-        psQuery = getPreparedStatement(
-            conn,
-            "select count(*) from information_schema.tables where 
table_name='ad_context_info' and table_type = 'LOCAL TEMPORARY'");
-        ResultSet rs = psQuery.executeQuery();
+  private static boolean adContextInfoShouldBeCreated(Connection conn, String 
rdbms) {
+    if (!isAuditActive || !isPosgreSQL(rdbms) || isReadOnly(conn)) {
+      return false;
+    }
+    if (usingJdbcConnectionPool()) {
+      // if this pool is used , the initDB method will only be called when 
creating a new
+      // connection, there is need to check if the ad_context_info has already 
been created
+      return true;
+    } else {
+      return !adContextInfoExists(conn);
+    }
+  }
 
-        if (rs.next() && rs.getString(1).equals("0")) {
-          StringBuffer sql = new StringBuffer();
-          sql.append("CREATE TEMPORARY TABLE AD_CONTEXT_INFO");
-          sql.append("(AD_USER_ID VARCHAR(32), ");
-          sql.append("  AD_SESSION_ID VARCHAR(32),");
-          sql.append("  PROCESSTYPE VARCHAR(60), ");
-          sql.append("  PROCESSID VARCHAR(32)) on commit preserve rows");
-          psCreate = getPreparedStatement(conn, sql.toString());
-          psCreate.execute();
-        }
-      } catch (Exception e) {
-        log4j.error("Error initializating audit infrastructure", e);
-      } finally {
-        releasePreparedStatement(psQuery);
-        releasePreparedStatement(psCreate);
-      }
+  private static boolean isReadOnly(Connection conn) {
+    boolean readOnly = false;
+    try {
+      readOnly = conn.isReadOnly();
+    } catch (SQLException e) {
+      log4j.error("Error checking if the connection is read only", e);
     }
+    return readOnly;
+  }
+
+  private static boolean isPosgreSQL(String rdbms) {
+    return rdbms != null && rdbms.equals("POSTGRE");
+  }
+
+  private static boolean usingJdbcConnectionPool() {
+    if (ExternalConnectionPool.getInstance() == null) {
+      return false;
+    }
+    return 
JDBC_CONNECTION_POOL_CLASS_NAME.equals(ExternalConnectionPool.getInstance().getClass()
+        .getName());
+  }
+
+  private static boolean adContextInfoExists(Connection conn) {
+    PreparedStatement psQuery = null;
+    boolean alreadyExists = false;
+    try {
+      psQuery = getPreparedStatement(
+          conn,
+          "select count(*) from information_schema.tables where 
table_name='ad_context_info' and table_type = 'LOCAL TEMPORARY'");
+      ResultSet rs = psQuery.executeQuery();
+      alreadyExists = rs.next() && !rs.getString(1).equals("0");
+    } catch (SQLException e) {
+      log4j.error("Error checking if the ad_context_info table exists", e);
+    } finally {
+      releasePreparedStatement(psQuery);
+    }
+    return alreadyExists;
   }
 
   /**
@@ -197,7 +242,7 @@
       // autocommit true.
       boolean infoModified = Boolean.TRUE.equals(changedInfo.get())
           || sessionConnection.get() == null || 
!conn.equals(sessionConnection.get());
-      if (!infoModified || Boolean.FALSE.equals(auditThisThread.get()) || 
conn.isReadOnly()) {
+      if (!infoModified || Boolean.FALSE.equals(auditThisThread.get()) || 
isReadOnly(conn)) {
         return;
       }
 
@@ -373,6 +418,11 @@
 
   public static void setAuditActive(boolean isAuditActive) {
     SessionInfo.isAuditActive = isAuditActive;
+    SessionInfo.initialized = true;
+  }
+
+  public static boolean isInitialized() {
+    return initialized;
   }
 
   static void setSessionConnection(Connection conn) {

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to