[teiid-commits] teiid SVN: r4526 - in branches/7.7.x: engine/src/main/java/org/teiid/dqp/internal/process and 6 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu Nov 1 16:34:44 EDT 2012


Author: jolee
Date: 2012-11-01 16:34:44 -0400 (Thu, 01 Nov 2012)
New Revision: 4526

Modified:
   branches/7.7.x/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java
   branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
   branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
   branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
   branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
   branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java
   branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
   branches/7.7.x/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java
   branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalNodeStatistics.java
Log:
TEIID-2245: Limit pushdown of nulls first/last- further fixes

Modified: branches/7.7.x/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java
===================================================================
--- branches/7.7.x/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/common-core/src/main/java/org/teiid/core/util/PropertiesUtils.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -40,6 +40,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.TreeMap;
 
 import org.teiid.core.CorePlugin;
 import org.teiid.core.TeiidRuntimeException;
@@ -938,80 +939,81 @@
     }
 
     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(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) {
+            	if (caseSensitive) {
+            		propertyName = prefix + "." + Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1, propertyName.length()); //$NON-NLS-1$
+            	} else {
+            		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();
+ 	public static void setBeanProperty(Object bean, String name, Object value) {
 	    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(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 Properties lowerCaseAllPropNames(final Properties connectionProps) {
-	    final Properties lcProps = new Properties();
+	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("Unable to set Property", propertyName, argType, e);
+		}
+		return argType;
+	}  
+
+	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: branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/Request.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -46,6 +46,7 @@
 import org.teiid.core.id.IDGenerator;
 import org.teiid.core.types.DataTypeManager;
 import org.teiid.core.util.Assertion;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
 import org.teiid.dqp.internal.process.AuthorizationValidator.CommandType;
 import org.teiid.dqp.internal.process.multisource.MultiSourceCapabilitiesFinder;
@@ -77,6 +78,7 @@
 import org.teiid.query.rewriter.QueryRewriter;
 import org.teiid.query.sql.lang.BatchedUpdateCommand;
 import org.teiid.query.sql.lang.Command;
+import org.teiid.query.util.ContextProperties;
 import org.teiid.query.sql.lang.Limit;
 import org.teiid.query.sql.lang.QueryCommand;
 import org.teiid.query.sql.lang.StoredProcedure;
@@ -88,7 +90,7 @@
 import org.teiid.query.tempdata.GlobalTableStore;
 import org.teiid.query.tempdata.TempTableStore;
 import org.teiid.query.util.CommandContext;
-import org.teiid.query.util.ContextProperties;
+import org.teiid.query.util.Options;
 import org.teiid.query.validator.AbstractValidationVisitor;
 import org.teiid.query.validator.ValidationVisitor;
 import org.teiid.query.validator.Validator;
@@ -222,10 +224,10 @@
 
         RequestID reqID = workContext.getRequestID(this.requestMsg.getExecutionId());
         
-        Properties props = new Properties();
-        props.setProperty(ContextProperties.SESSION_ID, workContext.getSessionId());
+       Properties props = new Properties();
+       props.setProperty(ContextProperties.SESSION_ID, workContext.getSessionId());
         
-        this.context =
+       this.context =
             new CommandContext(
                 reqID,
                 groupName,
@@ -233,7 +235,6 @@
                 requestMsg.getExecutionPayload(), 
                 workContext.getVdbName(), 
                 workContext.getVdbVersion(),
-                props,
                 this.requestMsg.getShowPlan() != ShowPlan.OFF);
         this.context.setProcessorBatchSize(bufferManager.getProcessorBatchSize());
         this.context.setGlobalTableStore(this.globalTables);
@@ -243,6 +244,7 @@
 					multiSourceModels, workContext, context);
             context.setPlanToProcessConverter(modifier);
         }
+        
         context.setExecutor(this.executor);
         context.setSecurityFunctionEvaluator(this);
         context.setTempTableStore(tempTableStore);
@@ -253,11 +255,15 @@
         context.setResultSetCacheEnabled(this.resultSetCacheEnabled);
         context.setUserRequestSourceConcurrency(this.userRequestConcurrency);
         context.setSubject(workContext.getSubject());
+        context.setEnvironmentProperties(props);
+        
+        this.context.setConnectionID(workContext.getSessionId());
         this.context.setSession(workContext.getSession());
         this.context.setRequestId(this.requestId);
         this.context.setDQPWorkContext(this.workContext);
         this.context.setTransactionService(this.transactionService);
         this.context.setTransactionContext(this.transactionContext);
+		this.context.setVDBClassLoader(workContext.getVDB().getAttachment(ClassLoader.class));
     }
     
     @Override

Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
===================================================================
--- branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -145,6 +145,8 @@
 		private LRUCache<String, SimpleDateFormat> dateFormatCache;
 		
 		private Options options;
+
+		public ClassLoader classLoader;
 	}
 	
 	private GlobalState globalState = new GlobalState();
@@ -160,14 +162,13 @@
      * Construct a new context.
      */
     public CommandContext(Object processorID, String connectionID, String userName, 
-        Serializable commandPayload, String vdbName, int vdbVersion, Properties envProperties, boolean collectNodeStatistics) {
+        Serializable commandPayload, String vdbName, int vdbVersion, boolean collectNodeStatistics) {
         setProcessorID(processorID);
         setConnectionID(connectionID);
         setUserName(userName);
         setCommandPayload(commandPayload);
         setVdbName(vdbName);
         setVdbVersion(vdbVersion);  
-        setEnvironmentProperties(envProperties);        
         setCollectNodeStatistics(collectNodeStatistics);
     }
 
@@ -178,7 +179,7 @@
         String vdbName, int vdbVersion) {
 
         this(processorID, connectionID, userName, null, vdbName, 
-            vdbVersion, null, false);            
+            vdbVersion, false);            
              
     }
 
@@ -705,5 +706,13 @@
 		this.globalState.options = options;
 	}
 
+	public ClassLoader getVDBClassLoader() {
+		return this.globalState.classLoader;
+	}
 	
+	public void setVDBClassLoader(ClassLoader classLoader) {
+		this.globalState.classLoader = classLoader;
+	}
+
+	
 }

Modified: branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -232,6 +232,7 @@
     }
 
     @Test public void testEnvSessionId() throws Exception {
+    	System.out.println("testEnvSessionId--------------------");
         String sql = "SELECT env('sessionid') as SessionID"; //$NON-NLS-1$
         String userName = "1"; //$NON-NLS-1$
         ResultsMessage rm = helpExecute(sql, userName);

Modified: branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -125,7 +125,7 @@
         DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, RealMetadataFactory.example1VDB());
         
         Request request = helpProcessMessage(message, null, workContext);
-        assertEquals("1", request.context.getEnvironmentProperties().get(ContextProperties.SESSION_ID)); //$NON-NLS-1$
+        assertEquals("1", request.context.getConnectionID()); //$NON-NLS-1$
     }
 
     private Request helpProcessMessage(RequestMessage message, SessionAwareCache<PreparedPlan> cache, DQPWorkContext workContext) throws TeiidComponentException,

Modified: branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/test/java/org/teiid/dqp/internal/process/multisource/TestMultiSourcePlanToProcessConverter.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -35,6 +35,7 @@
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.common.buffer.TupleSource;
 import org.teiid.core.id.IDGenerator;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.dqp.internal.process.DQPWorkContext;
 import org.teiid.query.analysis.AnalysisRecord;
 import org.teiid.query.metadata.QueryMetadataInterface;
@@ -57,6 +58,7 @@
 import org.teiid.query.sql.visitor.ElementCollectorVisitor;
 import org.teiid.query.unittest.RealMetadataFactory;
 import org.teiid.query.util.CommandContext;
+import org.teiid.query.util.Options;
 import org.teiid.translator.SourceSystemFunctions;
 
 /** 
@@ -126,8 +128,11 @@
         finder = new TempCapabilitiesFinder(finder);
         IDGenerator idGenerator = new IDGenerator();
         
-        Properties props = new Properties();
-        CommandContext context = new CommandContext("0", "test", "user", null, vdb.getName(), vdb.getVersion(), props, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+        Options options = new Options();
+        options.setProperties(System.getProperties());
+        PropertiesUtils.setBeanProperties(options, options.getProperties(), "org.teiid", true); //$NON-NLS-1$
+        
+        CommandContext context = new CommandContext("0", "test", "user", null, vdb.getName(), vdb.getVersion(), false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         context.setPlanToProcessConverter(new MultiSourcePlanToProcessConverter(wrapper, idGenerator, analysis, finder, multiSourceModels, dqpContext, context));
 
         ProcessorPlan plan = QueryOptimizer.optimizePlan(command, wrapper, idGenerator, finder, analysis, context);

Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -47,6 +47,7 @@
 import org.teiid.core.types.DataTypeManager;
 import org.teiid.core.types.XMLType;
 import org.teiid.core.util.ExecutorUtils;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.dqp.internal.process.CachedResults;
 import org.teiid.dqp.internal.process.PreparedPlan;
 import org.teiid.dqp.internal.process.QueryProcessorFactoryImpl;
@@ -92,6 +93,7 @@
 import org.teiid.query.unittest.RealMetadataFactory;
 import org.teiid.query.unittest.TimestampUtil;
 import org.teiid.query.util.CommandContext;
+import org.teiid.query.util.Options;
 import org.teiid.query.validator.Validator;
 import org.teiid.query.validator.ValidatorReport;
 import org.teiid.translator.SourceSystemFunctions;
@@ -350,10 +352,14 @@
 	}
 
 	public static CommandContext createCommandContext() {
-		Properties props = new Properties();
-		props.setProperty("soap_host", "my.host.com"); //$NON-NLS-1$ //$NON-NLS-2$
-		props.setProperty("soap_port", "12345"); //$NON-NLS-1$ //$NON-NLS-2$
-		CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, props, DEBUG); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+		
+		Options options = new Options();
+        options.setProperties(System.getProperties());
+        options.getProperties().setProperty("soap_host", "my.host.com"); //$NON-NLS-1$ //$NON-NLS-2$
+        options.getProperties().setProperty("soap_port", "12345"); //$NON-NLS-1$ //$NON-NLS-2$
+        PropertiesUtils.setBeanProperties(options, options.getProperties(), "org.teiid", true); //$NON-NLS-1$
+
+		CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, DEBUG); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
         context.setProcessorBatchSize(BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE);
         context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
         context.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>());

Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/eval/TestExpressionEvaluator.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -40,6 +40,7 @@
 import org.teiid.core.TeiidException;
 import org.teiid.core.TeiidProcessingException;
 import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.PropertiesUtils;
 import org.teiid.query.eval.Evaluator;
 import org.teiid.query.function.FunctionDescriptor;
 import org.teiid.query.parser.QueryParser;
@@ -64,6 +65,7 @@
 import org.teiid.query.sql.util.ValueIterator;
 import org.teiid.query.unittest.RealMetadataFactory;
 import org.teiid.query.util.CommandContext;
+import org.teiid.query.util.Options;
 
 @SuppressWarnings("nls")
 public class TestExpressionEvaluator {
@@ -333,11 +335,14 @@
         
         FakeDataManager dataMgr = new FakeDataManager();
         
-        Properties props = new Properties();
-        props.setProperty("http_host", "testHostName"); //$NON-NLS-1$ //$NON-NLS-2$
-        props.setProperty("http_port", "8000"); //$NON-NLS-1$ //$NON-NLS-2$
-        CommandContext context = new CommandContext(new Long(1), null, null, null, null, 0, props, false);
+        Options options = new Options();
+        options.setProperties(System.getProperties());
+        options.getProperties().setProperty("http_host", "testHostName"); //$NON-NLS-1$ //$NON-NLS-2$
+        options.getProperties().setProperty("http_port", "8000"); //$NON-NLS-1$ //$NON-NLS-2$
+        PropertiesUtils.setBeanProperties(options, options.getProperties(), "org.teiid", true); //$NON-NLS-1$
         
+        CommandContext context = new CommandContext(new Long(1), null, null, null, null, 0, false);
+        
         func.setArgs(new Expression[] {new Constant("http_host")}); //$NON-NLS-1$
         assertEquals("testHostName", new Evaluator(Collections.emptyMap(), dataMgr, context).evaluate(func, Collections.emptyList())); //$NON-NLS-1$
                
@@ -358,7 +363,7 @@
         func.setFunctionDescriptor(desc);
         
         FakeDataManager dataMgr = new FakeDataManager();       
-        CommandContext context = new CommandContext(new Long(-1), null, "user", payload, "vdb", 1, null, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        CommandContext context = new CommandContext(new Long(-1), null, "user", payload, "vdb", 1, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
 
         if(property != null) {
             func.setArgs(new Expression[] {new Constant(property)}); 

Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalNodeStatistics.java
===================================================================
--- branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalNodeStatistics.java	2012-10-31 21:31:09 UTC (rev 4525)
+++ branches/7.7.x/engine/src/test/java/org/teiid/query/processor/relational/TestRelationalNodeStatistics.java	2012-11-01 20:34:44 UTC (rev 4526)
@@ -111,7 +111,7 @@
         
         FakeRelationalNode fakeNode = new FakeRelationalNode(1, data, 100);
         fakeNode.setElements(elements);
-        CommandContext context = new CommandContext("pid", "group", null, null, null, 1, null, true); //$NON-NLS-1$ //$NON-NLS-2$
+        CommandContext context = new CommandContext("pid", "group", null, null, null, 1, true); //$NON-NLS-1$ //$NON-NLS-2$
         fakeNode.initialize(context, BufferManagerFactory.getStandaloneBufferManager(), null);
         return fakeNode;
     }



More information about the teiid-commits mailing list