fixes issue 38749: InventoryCountProcess registers SQL functions in a non-standard way
authorCarlos Aristu <carlos.aristu@openbravo.com>
Wed, 13 Jun 2018 17:18:35 +0200
changeset 34193 12232bee10ef
parent 34192 6230cdf4f146
child 34194 3aea2ba95cc7
fixes issue 38749: InventoryCountProcess registers SQL functions in a non-standard way

Register in Hibernate the SQL functions required by the InventoryCountProcess class during the initialization of the DAL layer:

- get_uuid: being already registered in the KernelSQLFunctionRegister
- to_date: there is no need of explicitly registering it, it is already registered by the corresponding PostgreSQL and Oracle dialects
- to_timestamp: being registered by default with the PostgreSQL but not with the Oracle dialect. So for PostgreSQL we are overriding the registry of this function. For this reason we are registering it in the same way as done by the PostgreSQL dialect.
- now: the same as to_timestamp function
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelSQLFunctionRegister.java
src/org/openbravo/materialmgmt/InventoryCountProcess.java
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelSQLFunctionRegister.java	Tue Jun 12 12:08:11 2018 +0000
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/KernelSQLFunctionRegister.java	Wed Jun 13 17:18:35 2018 +0200
@@ -23,6 +23,7 @@
 
 import javax.enterprise.context.ApplicationScoped;
 
+import org.hibernate.dialect.function.NoArgSQLFunction;
 import org.hibernate.dialect.function.SQLFunction;
 import org.hibernate.dialect.function.StandardSQLFunction;
 import org.hibernate.type.StandardBasicTypes;
@@ -46,7 +47,9 @@
         StandardBasicTypes.STRING));
     sqlFunctions.put("m_getjsondescription", new StandardSQLFunction("m_getjsondescription",
         StandardBasicTypes.STRING));
-    sqlFunctions.put("now", new StandardSQLFunction("now", StandardBasicTypes.DATE));
+    sqlFunctions.put("now", new NoArgSQLFunction("now", StandardBasicTypes.TIMESTAMP));
+    sqlFunctions.put("to_timestamp", new StandardSQLFunction("to_timestamp",
+        StandardBasicTypes.TIMESTAMP));
     return sqlFunctions;
   }
 }
--- a/src/org/openbravo/materialmgmt/InventoryCountProcess.java	Tue Jun 12 12:08:11 2018 +0000
+++ b/src/org/openbravo/materialmgmt/InventoryCountProcess.java	Wed Jun 13 17:18:35 2018 +0200
@@ -24,7 +24,6 @@
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import javax.enterprise.inject.Any;
 import javax.enterprise.inject.Instance;
@@ -35,14 +34,7 @@
 import org.hibernate.Query;
 import org.hibernate.QueryTimeoutException;
 import org.hibernate.Session;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.dialect.function.StandardSQLFunction;
 import org.hibernate.exception.GenericJDBCException;
-import org.hibernate.impl.SessionFactoryImpl;
-import org.hibernate.impl.SessionImpl;
-import org.hibernate.type.DateType;
-import org.hibernate.type.StringType;
 import org.openbravo.advpaymentmngt.utility.FIN_Utility;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.dal.core.OBContext;
@@ -174,23 +166,6 @@
     msg.setTitle(OBMessageUtils.messageBD("Success"));
     runChecks(inventory);
 
-    // In case get_uuid is not already registered, it's registered now.
-    final Dialect dialect = ((SessionFactoryImpl) ((SessionImpl) OBDal.getInstance().getSession())
-        .getSessionFactory()).getDialect();
-    Map<String, SQLFunction> function = dialect.getFunctions();
-    if (!function.containsKey("get_uuid")) {
-      dialect.getFunctions().put("get_uuid", new StandardSQLFunction("get_uuid", new StringType()));
-    }
-    if (!function.containsKey("now")) {
-      dialect.getFunctions().put("now", new StandardSQLFunction("now", new DateType()));
-    }
-    if (!function.containsKey("to_date")) {
-      dialect.getFunctions().put("to_date", new StandardSQLFunction("to_date", new DateType()));
-    }
-    if (!function.containsKey("to_timestamp")) {
-      dialect.getFunctions().put("to_timestamp",
-          new StandardSQLFunction("to_timestamp", new DateType()));
-    }
     StringBuffer insert = new StringBuffer();
     insert.append("insert into " + MaterialTransaction.ENTITY_NAME + "(");
     insert.append(" id ");