[teiid-commits] teiid SVN: r4332 - in trunk: engine/src/main/java/org/teiid/dqp/internal/process and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Aug 16 11:34:04 EDT 2012


Author: shawkins
Date: 2012-08-16 11:34:02 -0400 (Thu, 16 Aug 2012)
New Revision: 4332

Modified:
   trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
Log:
TEIID-2149 making sure there is minimal properties overhead

Modified: trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java	2012-08-16 15:15:36 UTC (rev 4331)
+++ trunk/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java	2012-08-16 15:34:02 UTC (rev 4332)
@@ -40,6 +40,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.TreeMap;
 
 import org.teiid.core.BundleUtil;
 import org.teiid.core.CorePlugin;
@@ -56,7 +57,7 @@
 	public static class InvalidPropertyException extends TeiidRuntimeException {
 		private static final long serialVersionUID = 1586068295007497776L;
 
-		public InvalidPropertyException(BundleUtil.Event event, String propertyName, String value, Class<?> expectedType, Throwable cause) {
+		public InvalidPropertyException(BundleUtil.Event event, String propertyName, Object value, Class<?> expectedType, Throwable cause) {
 			super(event, cause, CorePlugin.Util.getString("InvalidPropertyException.message", propertyName, value, expectedType.getSimpleName())); //$NON-NLS-1$
 		}		
 
@@ -732,81 +733,78 @@
         return original;
     }
     
- public static void setBeanProperties(Object bean, Properties props, String prefix) {
+    public static void setBeanProperties(Object bean, Properties props, String prefix) {
+    	setBeanProperties(bean, props, prefix, false);
+    }
+    
+    public static void setBeanProperties(Object bean, Properties props, String prefix, boolean caseSensitive) {
 		// Move all prop names to lower case so we can use reflection to get
 	    // method names and look them up in the connection props.
-	    final Properties connProps = lowerCaseAllPropNames(props);
+    	Map<?, ?> map = props;
+    	if (!caseSensitive) {
+    		map = caseInsensitiveProps(props);    		
+    	}
 	    final Method[] methods = bean.getClass().getMethods();
 	    for (int i = 0; i < methods.length; i++) {
 	        final Method method = methods[i];
 	        final String methodName = method.getName();
 	        // If setter ...
-	        if ( methodName.startsWith("set") && method.getParameterTypes().length == 1 ) { //$NON-NLS-1$
-	            // Get the property name
-	            final String propertyName = methodName.substring(3);    // remove the "set"
-	            String shortName = propertyName.toLowerCase();
-	            String propertyValue = null;
-	            if (prefix != null) {
-	            	propertyValue = connProps.getProperty(prefix + "." + shortName); //$NON-NLS-1$
-	            } else {
-	            	propertyValue = connProps.getProperty(shortName);
-	            }
-	            if (propertyValue == null) {
-	            	continue;
-	            }
-                final Class<?> argType = method.getParameterTypes()[0];
-                try {
-                    final Object[] params = new Object[] {StringUtil.valueOf(propertyValue, argType)};
-                    method.invoke(bean, params);
-                } catch (Throwable e) {
-                	  throw new InvalidPropertyException(CorePlugin.Event.TEIID10043, propertyName, propertyValue, argType, e);
-                }
+	        if (! methodName.startsWith("set") || method.getParameterTypes().length != 1 ) { //$NON-NLS-1$
+	        	continue;
 	        }
+            // Get the property name
+            String propertyName = methodName.substring(3);    // remove the "set"
+            if (prefix != null) {
+            	propertyName = prefix + "." + propertyName; //$NON-NLS-1$
+            }
+            Object propertyValue = map.get(propertyName);
+            if (propertyValue != null || map.containsKey(propertyName)) {
+            	setProperty(bean, propertyValue, method, propertyName);
+            }
 	    }
 	}
     
     public static void setBeanProperty(Object bean, String name, Object value) {
-    	if (value == null) {
-    		return;
-    	}
-    	name = name.toLowerCase();
 	    final Method[] methods = bean.getClass().getMethods();
 	    for (int i = 0; i < methods.length; i++) {
 	        final Method method = methods[i];
 	        final String methodName = method.getName();
 	        // If setter ...
-	        if ( methodName.startsWith("set") && method.getParameterTypes().length == 1 ) { //$NON-NLS-1$
-	            // Get the property name
-	            final String propertyName = methodName.substring(3);    // remove the "set"
-	            String shortName = propertyName.toLowerCase();
-	            if (!shortName.equals(name)) {
-	            	continue;
-	            }
-                final Class<?> argType = method.getParameterTypes()[0];
-                try {
-                	Object[] params = new Object[] {value};
-                	if (!argType.isAssignableFrom(value.getClass())) {
-                		params = new Object[] {StringUtil.valueOf(value.toString(), argType)};
-                	}
-                    method.invoke(bean, params);
-                } catch (Throwable e) {
-                	  throw new InvalidPropertyException(CorePlugin.Event.TEIID10044, propertyName, value.toString(), argType, e);
-                }
+	        if (! methodName.startsWith("set") || method.getParameterTypes().length != 1 || !StringUtil.endsWithIgnoreCase(methodName, name)) { //$NON-NLS-1$
+	        	continue;
 	        }
+            // Get the property name
+            final String propertyName = methodName.substring(3);    // remove the "set"
+            setProperty(bean, value, method, propertyName);
 	    }
+	}
+
+	private static Class<?> setProperty(Object bean, Object value,
+			final Method method, final String propertyName) {
+		final Class<?> argType = method.getParameterTypes()[0];
+		try {
+			Object[] params = new Object[] {value};
+			if (value != null && !argType.isAssignableFrom(value.getClass())) {
+				params = new Object[] {StringUtil.valueOf(value.toString(), argType)};
+			}
+		    method.invoke(bean, params);
+		} catch (Throwable e) {
+			  throw new InvalidPropertyException(CorePlugin.Event.TEIID10044, propertyName, value, argType, e);
+		}
+		return argType;
 	}    
 
-	private static Properties lowerCaseAllPropNames(final Properties connectionProps) {
-	    final Properties lcProps = new Properties();
+	private static TreeMap<String, String> caseInsensitiveProps(final Properties connectionProps) {
+	    final TreeMap<String, String> caseInsensitive = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
 	    final Enumeration<?> itr = connectionProps.propertyNames();
 	    while ( itr.hasMoreElements() ) {
 	        final String name = (String) itr.nextElement();
 	        String propValue = connectionProps.getProperty(name);
-	        if (propValue != null) {
-	        	lcProps.setProperty(name.toLowerCase(), propValue);
+	        if (propValue != null || connectionProps.containsKey(name)) {
+	        	caseInsensitive.put(name, propValue);
 	        } 
 	    }
-	    return lcProps;
+	    return caseInsensitive;
 	}
 
 }

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2012-08-16 15:15:36 UTC (rev 4331)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2012-08-16 15:34:02 UTC (rev 4332)
@@ -249,7 +249,7 @@
         context.setSubject(workContext.getSubject());
         Options options = new Options();
         options.setProperties(System.getProperties());
-        PropertiesUtils.setBeanProperties(options, options.getProperties(), "org.teiid"); //$NON-NLS-1$
+        PropertiesUtils.setBeanProperties(options, options.getProperties(), "org.teiid", true); //$NON-NLS-1$
         this.context.setSession(workContext.getSession());
         this.context.setRequestId(this.requestId);
         this.context.setDQPWorkContext(this.workContext);



More information about the teiid-commits mailing list