eclipse-ee4j / glassfish

Eclipse GlassFish
https://eclipse-ee4j.github.io/glassfish/
384 stars 143 forks source link

GlassFish JDBC resource should make it possible to setup Properties attributes. #19615

Closed glassfishrobot closed 3 years ago

glassfishrobot commented 11 years ago

Environment

Config: GlassFish 2.1.x, GlassFish 3.x and possible BG OS: Any Database: Oracle RAC and any Database API have setXXXX(Properties p)

glassfishrobot commented 6 years ago
glassfishrobot commented 11 years ago

@glassfishrobot Commented gfuser9999 said: Configuration: GFv211 and all GFv31x and also BG (currently) Problem:

For FCF http://download.oracle.com/otn_hosted_doc/jdeveloper/905/jdbc-javadoc/oracle/jdbc/pool/OracleDataSource.html setConnectionCacheProperties(java.util.Properties cp) [see http://keremerkan.net/posts/supporting-oracle-fcf-in-tomcat/ example for the ConnectionCacheProperties

or for UCP http://docs.oracle.com/cd/E18283_01/java.112/e12826/oracle/ucp/jdbc/PoolDataSource.html to set the UCP pool But this is doable in Tomcat for passing ConnectionProperties.

**com.sun.gjc.util.MethodExecutor.java (diff)**--- MethodExecutor.java-orig Fri Feb  1 16:40:54 2013
+++ MethodExecutor.java Fri Feb  1 17:26:49 2013
@@ -48,6 +48,7 @@
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Vector;
+import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;

@@ -67,6 +68,8 @@

     private boolean debug = false;

+    private final String newline = System.getProperty("line.separator");
+
     private static StringManager sm = StringManager.getManager(
             DataSourceObjectBuilder.class);

@@ -206,6 +209,11 @@
 return Boolean.valueOf(parameter);
             }

+            if (typeName.equals("java.util.Properties")) {
+Properties p = stringToProperties(parameter);
+if (p!= null) return p;
+            }
+
             return parameter;
         } catch (NumberFormatException nfe) {
             _logger.log(Level.SEVERE, "jdbc.exc_nfe", parameter);
@@ -238,6 +246,48 @@
         }
         return returnValue;
     }
+
+    private Properties stringToProperties(String parameter)
+    {
+         if (parameter == null) return null;
+         String s = parameter.trim();
+         if (!((s.startsWith("(") && s.endsWith(")")))) {
+            return null; // not a "( .... )" syntax +         }
+         s = s.substring(1,s.length()-2);
+         s = s.replaceAll("(?<!\\\\),",newline);
+
+         Properties p = new Properties();
+         Properties prop = new Properties();
+         try {
+            p.load(new java.io.StringBufferInputStream(s));
+         } catch (java.io.IOException ex) {
+            if (_logger.isLoggable(Level.FINEST)) {
+               _logger.log(Level.FINEST,
+"Parsing string to properties: "+ex.getMessage());
+            }
+            return null;
+         }
+         // cleanup trailing whitespace in value +         for (java.util.Enumeration propKeys = p.propertyNames();
+               propKeys.hasMoreElements();) {
+             String tmpKey = (String)propKeys.nextElement();
+             String tmpValue = p.getProperty(tmpKey);
+             // Trim spaces +             tmpValue = tmpValue.trim();
+             // Quoted string. +             if (tmpValue.length() > 1 && tmpValue.startsWith("\"")
+ && tmpValue.endsWith("\"")) {
+tmpValue = tmpValue.substring(1,tmpValue.length()-2);
+             }
+             prop.put(tmpKey, tmpValue);
+         }
+         if (_logger.isLoggable(Level.FINEST)) {
+               _logger.log(Level.FINEST,
+"Parsing string to properties: "+prop+" size:"+prop.size());
+         }
+         return prop;
+    }
 }
glassfishrobot commented 11 years ago

@glassfishrobot Commented Was assigned to sfelts

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA GLASSFISH-19615

glassfishrobot commented 11 years ago

@glassfishrobot Commented Reported by gfuser9999

github-actions[bot] commented 4 years ago

This issue has been marked as inactive and old and will be closed in 7 days if there is no further activity. If you want the issue to remain open please add a comment

github-actions[bot] commented 3 years ago

This issue has been marked as inactive and old and will be closed in 7 days if there is no further activity. If you want the issue to remain open please add a comment