Concurrency issue in EscapedFunctions

Поиск
Список
Период
Сортировка
От Pierre Queinnec
Тема Concurrency issue in EscapedFunctions
Дата
Msg-id 4BDC5DE2.7070402@zenika.com
обсуждение исходный текст
Ответы Re: Concurrency issue in EscapedFunctions  (Kris Jurka <books@ejurka.com>)
Список pgsql-jdbc
[sending again as it never got delivered to the ML]

Hi,

It seems that there's a concurrency initialization issue in
o.p.jdbc2.EscapedFunctions. I've attached a tentative fix for this.
BTW, thanks a lot Kris for the commits on my previous patches!

Cheers,
--
Pierre Queinnec
CTO - Zenika
http://www.zenika.com

Index: org/postgresql/jdbc2/EscapedFunctions.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/EscapedFunctions.java,v
retrieving revision 1.12
diff -c -r1.12 EscapedFunctions.java
*** org/postgresql/jdbc2/EscapedFunctions.java    16 Nov 2008 12:14:06 -0000    1.12
--- org/postgresql/jdbc2/EscapedFunctions.java    1 May 2010 15:40:10 -0000
***************
*** 116,138 ****


      /** storage for functions implementations */
!     private static Map functionMap = null;
!
      /**
       * get Method object implementing the given function
       * @param functionName name of the searched function
       * @return a Method object or null if not found
       */
      public static Method getFunction(String functionName){
-         if (functionMap==null){
-             Method[] arrayMeths = EscapedFunctions.class.getDeclaredMethods();
-             functionMap = new HashMap(arrayMeths.length*2);
-             for (int i=0;i<arrayMeths.length;i++){
-                 Method meth = arrayMeths[i];
-                 if (meth.getName().startsWith("sql"))
-                     functionMap.put(meth.getName().toLowerCase(Locale.US),meth);
-             }
-         }
          return (Method) functionMap.get("sql"+functionName.toLowerCase(Locale.US));
      }

--- 116,143 ----


      /** storage for functions implementations */
!     private static Map functionMap;
!
!     static {
!         initializeFunctionMap();
!     }
!
!     private static void initializeFunctionMap() {
!         Method[] arrayMeths = EscapedFunctions.class.getDeclaredMethods();
!         functionMap = new HashMap(arrayMeths.length*2);
!         for (int i=0;i<arrayMeths.length;i++){
!             Method meth = arrayMeths[i];
!             if (meth.getName().startsWith("sql"))
!                 functionMap.put(meth.getName().toLowerCase(Locale.US),meth);
!         }
!     }
!
      /**
       * get Method object implementing the given function
       * @param functionName name of the searched function
       * @return a Method object or null if not found
       */
      public static Method getFunction(String functionName){
          return (Method) functionMap.get("sql"+functionName.toLowerCase(Locale.US));
      }


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Kris Jurka
Дата:
Сообщение: Re: Driver not returning the type for TYPEs
Следующее
От: Nookala Satish Kumar
Дата:
Сообщение: Re: Glassfish ignoring "ssl" property in connection pool of PostgreSQL