[teiid-commits] teiid SVN: r556 - in trunk: client/src/test/java/com/metamatrix/dqp and 11 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Mar 13 14:54:39 EDT 2009


Author: shawkins
Date: 2009-03-13 14:54:39 -0400 (Fri, 13 Mar 2009)
New Revision: 556

Added:
   trunk/client/src/test/java/com/metamatrix/dqp/message/
   trunk/client/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java
Removed:
   trunk/engine/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java
Modified:
   trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMStatement.java
   trunk/client/src/main/java/com/metamatrix/dqp/message/RequestMessage.java
   trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedTrackingService.java
   trunk/engine/pom.xml
   trunk/engine/src/main/java/com/metamatrix/dqp/internal/cache/ResultSetCacheUtil.java
   trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorManager.java
   trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/CachedRequestWorkItem.java
   trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/DQPCore.java
   trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/PreparedStatementRequest.java
   trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java
   trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
   trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.java
   trunk/engine/src/main/java/com/metamatrix/dqp/service/TrackingService.java
   trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDQPCore.java
   trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDataTierManager.java
   trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestMetaDataProcessor.java
   trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestPreparedStatement.java
   trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestRequest.java
   trunk/engine/src/test/java/com/metamatrix/dqp/service/TestCustomizableTrackingService.java
Log:
TEIID-395 clean up of command logging to ensure the exact user command string is logged.

Modified: trunk/client/src/main/java/com/metamatrix/dqp/message/RequestMessage.java
===================================================================
--- trunk/client/src/main/java/com/metamatrix/dqp/message/RequestMessage.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/client/src/main/java/com/metamatrix/dqp/message/RequestMessage.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -23,6 +23,7 @@
 package com.metamatrix.dqp.message;
 
 import java.io.Serializable;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -40,9 +41,8 @@
     
     public static final int DEFAULT_FETCH_SIZE = 2000;
 
-    private String commandStr;
-    private String[] batchedCommands;
-    private Serializable command;
+    private String[] commands;
+    private boolean isBatchedUpdate;
     private int fetchSize = DEFAULT_FETCH_SIZE;
     private int cursorType;
     private boolean partialResultsFlag;
@@ -83,37 +83,9 @@
 
 	public RequestMessage(String command) {
 		this();
-		
-		this.commandStr = command;
+		setCommands(command);
 	}
-	
-	/**
-	 * @return Command
-	 */
-	public Serializable getCommand() {
-		if (command != null) {
-			return command;
-		}
-		if (commandStr != null) {
-			return commandStr;
-		}
-		return batchedCommands;
-	}
 
-	/**
-	 * Sets the command.
-	 * @param command The command to set
-	 */
-	public void setCommand(Serializable command) {
-		if (command instanceof String) {
-			this.commandStr = (String)command;
-		} else if (command instanceof String[]) {
-			this.batchedCommands = (String[])command;
-		} else {
-			this.command = command;
-		}
-	}
-
     public int getFetchSize() {
         return fetchSize;
     }
@@ -327,8 +299,11 @@
 		this.useResultSetCache = useResultSetCacse;
 	}
 
-	public String getCacheCommand() {
-		return commandStr;
+	public String getCommandString() {
+		if (commands.length == 1) {
+			return commands[0];
+		}
+		return Arrays.deepToString(commands);
 	}
            
     public void setDoubleQuotedVariableAllowed(boolean allowed) {
@@ -382,22 +357,14 @@
         this.rowLimit = rowLimit;
     }
 
-	public String getCommandStr() {
-		return commandStr;
+	public String[] getCommands() {
+		return commands;
 	}
 
-	public void setCommandStr(String commandStr) {
-		this.commandStr = commandStr;
+	public void setCommands(String... batchedCommands) {
+		this.commands = batchedCommands;
 	}
 
-	public String[] getBatchedCommands() {
-		return batchedCommands;
-	}
-
-	public void setBatchedCommands(String[] batchedCommands) {
-		this.batchedCommands = batchedCommands;
-	}
-
 	public boolean isPreparedBatchUpdate() {
 		return isPreparedBatchUpdate;
 	}
@@ -422,4 +389,12 @@
 		this.executionId = executionId;
 	}
 
+	public void setBatchedUpdate(boolean isBatchedUpdate) {
+		this.isBatchedUpdate = isBatchedUpdate;
+	}
+
+	public boolean isBatchedUpdate() {
+		return isBatchedUpdate;
+	}
+
 }

Copied: trunk/client/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java (from rev 544, trunk/engine/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java)
===================================================================
--- trunk/client/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java	                        (rev 0)
+++ trunk/client/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package com.metamatrix.dqp.message;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.core.util.UnitTestUtil;
+import com.metamatrix.jdbc.api.ExecutionProperties;
+
+public class TestRequestMessage extends TestCase {
+
+    /**
+     * Constructor for TestRequestMessage.
+     * @param name
+     */
+    public TestRequestMessage(String name) {
+        super(name);
+    }
+
+    public static RequestMessage example() {
+        RequestMessage message = new RequestMessage();
+        message.setCallableStatement(true);
+        message.setFetchSize(100);
+        List params = new ArrayList();
+        params.add(new Integer(100));
+        params.add(new Integer(200));
+        params.add(new Integer(300));
+        params.add(new Integer(400));
+        message.setParameterValues(params);
+
+        message.setPartialResults(true);
+        message.setPreparedStatement(false);
+        message.setSubmittedTimestamp(new Date(11111111L));
+        message.setProcessingTimestamp(new Date(12345678L));
+        message.setStyleSheet("myStyleSheet"); //$NON-NLS-1$
+        message.setExecutionPayload("myExecutionPayload"); //$NON-NLS-1$
+        try {
+			message.setTxnAutoWrapMode(ExecutionProperties.AUTO_WRAP_ON);
+		} catch (MetaMatrixProcessingException e) {
+			throw new RuntimeException(e);
+		} 
+
+        message.setValidationMode(true);
+        message.setXMLFormat("xMLFormat"); //$NON-NLS-1$
+        message.setShowPlan(true);
+        message.setRowLimit(1313);
+        return message;
+    }
+
+    public void testSerialize() throws Exception {
+        RequestMessage copy = UnitTestUtil.helpSerialize(example());
+
+        assertTrue(copy.isCallableStatement());
+        assertEquals(100, copy.getFetchSize());
+        assertNotNull(copy.getParameterValues());
+        assertEquals(4, copy.getParameterValues().size());
+        assertEquals(new Integer(100), copy.getParameterValues().get(0));
+        assertEquals(new Integer(200), copy.getParameterValues().get(1));
+        assertEquals(new Integer(300), copy.getParameterValues().get(2));
+        assertEquals(new Integer(400), copy.getParameterValues().get(3));
+
+        assertFalse(copy.isPreparedStatement());
+        assertEquals(new Date(11111111L), copy.getSubmittedTimestamp());
+        assertEquals(new Date(12345678L), copy.getProcessingTimestamp());
+        assertEquals("myStyleSheet", copy.getStyleSheet()); //$NON-NLS-1$
+        assertEquals("myExecutionPayload", copy.getExecutionPayload()); //$NON-NLS-1$
+        assertEquals(ExecutionProperties.AUTO_WRAP_ON, copy.getTxnAutoWrapMode()); //$NON-NLS-1$
+        assertTrue(copy.getValidationMode());
+        assertEquals("xMLFormat", copy.getXMLFormat()); //$NON-NLS-1$
+        assertTrue(copy.getShowPlan());
+        assertEquals(1313, copy.getRowLimit());
+        
+    }
+    
+    public void testInvalidTxnAutoWrap() {
+		RequestMessage rm = new RequestMessage();
+		try {
+			rm.setTxnAutoWrapMode("foo"); //$NON-NLS-1$
+			fail("exception expected"); //$NON-NLS-1$
+		} catch (MetaMatrixProcessingException e) {
+			assertEquals("'FOO' is an invalid transaction autowrap mode.", e.getMessage()); //$NON-NLS-1$
+		}
+	}
+
+}


Property changes on: trunk/client/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMStatement.java
===================================================================
--- trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMStatement.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/client-jdbc/src/main/java/com/metamatrix/jdbc/MMStatement.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -975,11 +975,8 @@
         this.currentRequestID = this.driverConnection.nextRequestID();
         RequestMessage reqMsg = new RequestMessage();        
         // Create a request message
-        if (isBatchedCommand) {
-        	reqMsg.setBatchedCommands(commands);
-        } else {
-        	reqMsg.setCommandStr(commands[0]);
-        }
+    	reqMsg.setCommands(commands);
+    	reqMsg.setBatchedUpdate(isBatchedCommand);
         reqMsg.markSubmissionStart();        
         reqMsg.setExecutionPayload(this.payload);        
         reqMsg.setDoubleQuotedVariableAllowed(Boolean.valueOf(

Modified: trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedTrackingService.java
===================================================================
--- trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedTrackingService.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/embedded/src/main/java/com/metamatrix/dqp/embedded/services/EmbeddedTrackingService.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -30,7 +30,6 @@
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
 import com.metamatrix.common.application.exception.ApplicationLifecycleException;
 import com.metamatrix.dqp.service.TrackingService;
-import com.metamatrix.query.sql.lang.Command;
 
 public class EmbeddedTrackingService extends EmbeddedBaseDQPService implements TrackingService {
     //public static HashMap traceData = new HashMap();
@@ -48,7 +47,7 @@
         short cmdPoint,
         String sessionUid,
         String principal,
-        Command sql,
+        String sql,
         int rowCount,
         ExecutionContext context) {
 
@@ -81,7 +80,7 @@
         String principal,
         String vdbName,
         String vdbVersion,
-        Command sql,
+        String sql,
         int rowCount) {
 
     }

Modified: trunk/engine/pom.xml
===================================================================
--- trunk/engine/pom.xml	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/pom.xml	2009-03-13 18:54:39 UTC (rev 556)
@@ -56,6 +56,12 @@
       <groupId>org.jboss.teiid</groupId>
       <artifactId>teiid-client</artifactId>
     </dependency>
+
+    <dependency>
+      <groupId>org.jboss.teiid</groupId>
+      <artifactId>teiid-client</artifactId>
+      <type>test-jar</type>
+    </dependency>
     
     <dependency>
       <groupId>javax.transaction</groupId>

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/cache/ResultSetCacheUtil.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/cache/ResultSetCacheUtil.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/cache/ResultSetCacheUtil.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -37,7 +37,7 @@
 		}else{
 			scopeID = workContext.getConnectionID();
 		}
-		return new CacheID(scopeID, request.getCacheCommand(), request.getParameterValues());
+		return new CacheID(scopeID, request.getCommandString(), request.getParameterValues());
 	}
 	
 //	public static boolean isQuery(String sql){

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorManager.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorManager.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/datamgr/impl/ConnectorManager.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -547,9 +547,10 @@
         if(tracker == null || !tracker.willRecordSrcCmd()){
             return;
         }
-        Command sqlCmd = null;
+        String sqlStr = null;
         if(cmdStatus == TrackerLogConstants.CMD_STATUS.NEW){
-            sqlCmd = qr.getCommand();
+        	Command cmd = qr.getCommand();
+            sqlStr = cmd != null ? cmd.toString() : null;
         }
         String userName = qr.getWorkContext().getUserName();
         String transactionID = null;
@@ -563,7 +564,7 @@
         tracker.log(qr.getRequestID().toString(), id.getNodeID(), transactionID,
                 cmdStatus, modelName == null ? "null" : modelName, connectorName, //$NON-NLS-1$
                 cmdStatus == TrackerLogConstants.CMD_STATUS.NEW ? TrackerLogConstants.CMD_POINT.BEGIN : TrackerLogConstants.CMD_POINT.END,
-                qr.getWorkContext().getConnectionID(), userName == null ? "unknown" : userName, sqlCmd, finalRowCnt, context); //$NON-NLS-1$
+                qr.getWorkContext().getConnectionID(), userName == null ? "unknown" : userName, sqlStr, finalRowCnt, context); //$NON-NLS-1$
     }
     
     /**

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/CachedRequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/CachedRequestWorkItem.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/CachedRequestWorkItem.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -52,7 +52,6 @@
 	protected void processNew() throws MetaMatrixComponentException, MetaMatrixProcessingException  {
 		request.initMetadata();
     	request.validateEntitlement(originalCommand);
-    	requestMsg.setCommand(originalCommand);
     	this.request = null;
 	}
 	

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/DQPCore.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/DQPCore.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -191,7 +191,7 @@
             RequestWorkItem holder = requests.get(requestID);
             
             if(holder != null && !holder.isCanceled()) {
-            	RequestInfo req = new RequestInfo(holder.requestID, holder.requestMsg.getCommand().toString(), holder.requestMsg.getSubmittedTimestamp(), holder.requestMsg.getProcessingTimestamp());
+            	RequestInfo req = new RequestInfo(holder.requestID, holder.requestMsg.getCommandString(), holder.requestMsg.getSubmittedTimestamp(), holder.requestMsg.getProcessingTimestamp());
             	if (holder.getTransactionContext() != null && holder.getTransactionContext().isInTransaction()) {
             		req.setTransactionId(holder.getTransactionContext().getTxnID());
             	}
@@ -497,10 +497,10 @@
         }
         DQPWorkContext workContext = DQPWorkContext.getWorkContext();
         RequestID rID = new RequestID(workContext.getConnectionID(), msg.getExecutionId());
-        Command command = null;
+        String command = null;
         String txnID = null;
     	if(isBegin && !isCancel){
-    		command = (Command)msg.getCommand();
+    		command = msg.getCommandString();
     	}
     	String appName = workContext.getAppName();
         // Log to request log

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/PreparedStatementRequest.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/PreparedStatementRequest.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/PreparedStatementRequest.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -123,7 +123,7 @@
         List values = requestMsg.getParameterValues();
         if(requestMsg.isPreparedBatchUpdate()){
         	if(values.size() > 1){
-        		((PreparedBatchUpdate)requestMsg.getCommand()).setUpdatingModelCount(2);
+        		((PreparedBatchUpdate)command).setUpdatingModelCount(2);
         	}
         	for(int i=0; i<values.size(); i++){
         	   if (params.size() != ((List)values.get(i)).size()) {
@@ -152,7 +152,7 @@
      */
     protected void generatePlan() throws QueryPlannerException, QueryParserException, QueryResolverException, QueryValidatorException, MetaMatrixComponentException {
     	
-    	String sqlQuery = (String)requestMsg.getCommand();
+    	String sqlQuery = requestMsg.getCommands()[0];
         prepPlan = prepPlanCache.getPreparedPlan(this.workContext.getConnectionID(), sqlQuery, requestMsg.isPreparedBatchUpdate());
         if (prepPlan == null) {
             //if prepared plan does not exist, create one
@@ -178,7 +178,7 @@
             //already in cache. obtain the values from cache
             analysisRecord = prepPlan.getAnalysisRecord();
             
-            requestMsg.setCommand(command);
+            this.command = command;
             createCommandContext(command);
         }
         

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/Request.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -145,6 +145,8 @@
     protected TransactionContext transactionContext;
     
     private int chunkSize;
+    
+    protected Command command;
 
     void initialize(RequestMessage requestMsg,
                               ApplicationEnvironment env,
@@ -327,7 +329,7 @@
             }
         }
         
-        requestMsg.setCommand(preRewrite);
+        this.command = preRewrite;
         return command;
     }
     
@@ -371,15 +373,15 @@
     }
 
     private Command getCommand() throws QueryParserException {
-        String command = requestMsg.getCommandStr();
+        String[] commands = requestMsg.getCommands();
         ParseInfo parseInfo = new ParseInfo();
         if (requestMsg.isDoubleQuotedVariableAllowed()) {
         	parseInfo.allowDoubleQuotedVariable = true;
         }
-        if (command != null) {
-            return QueryParser.getQueryParser().parseCommand(command, parseInfo);
-        }
-        String[] commands = requestMsg.getBatchedCommands();
+        if (!requestMsg.isBatchedUpdate()) {
+        	String commandStr = commands[0];
+            return QueryParser.getQueryParser().parseCommand(commandStr, parseInfo);
+        } 
         List parsedCommands = new ArrayList(commands.length);
         for (int i = 0; i < commands.length; i++) {
         	String updateCommand = commands[i];
@@ -422,7 +424,7 @@
             
             if(ExecutionProperties.AUTO_WRAP_ON.equals(requestMsg.getTxnAutoWrapMode())){ 
                 startAutoWrapTxn = true;
-            } else if ( ((Command)requestMsg.getCommand()).updatingModelCount(metadata) > 1) { 
+            } else if ( command.updatingModelCount(metadata) > 1) { 
                 if (ExecutionProperties.AUTO_WRAP_OPTIMISTIC.equals(requestMsg.getTxnAutoWrapMode())){ 
                     String msg = DQPPlugin.Util.getString("Request.txn_needed_wrong_mode", requestId); //$NON-NLS-1$
                     throw new MetaMatrixComponentException(msg);
@@ -596,8 +598,6 @@
         
         generatePlan();
         
-        Command command = (Command)requestMsg.getCommand();
-        
         validateEntitlement(command);
         
         setSchemasForXMLPlan(command, metadata);
@@ -606,25 +606,25 @@
     }
     
 	public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext) throws MetaMatrixProcessingException, MetaMatrixComponentException {
-		boolean isRootXQuery = recursionGroup == null && commandContext.getCallStackDepth() == 0 && this.requestMsg.getCommand() instanceof XQuery;
+		boolean isRootXQuery = recursionGroup == null && commandContext.getCallStackDepth() == 0 && command instanceof XQuery;
 		
 		ParseInfo parseInfo = new ParseInfo();
 		if (isRootXQuery && requestMsg.isDoubleQuotedVariableAllowed()) {
 			parseInfo.allowDoubleQuotedVariable = true;
 		}
-		Command command = QueryParser.getQueryParser().parseCommand(query, parseInfo);
-        QueryResolver.resolveCommand(command, metadata);            
+		Command newCommand = QueryParser.getQueryParser().parseCommand(query, parseInfo);
+        QueryResolver.resolveCommand(newCommand, metadata);            
         
-        List references = ReferenceCollectorVisitor.getReferences(command);
+        List references = ReferenceCollectorVisitor.getReferences(newCommand);
         
         referenceCheck(references);
         
-        validateQuery(command, isRootXQuery);
+        validateQuery(newCommand, isRootXQuery);
         
-        validateQueryValues(command);
+        validateQueryValues(newCommand);
         
         if (isRootXQuery) {
-        	validateEntitlement(command);
+        	validateEntitlement(newCommand);
         }
         
         CommandContext copy = (CommandContext) commandContext.clone();
@@ -632,10 +632,10 @@
         	copy.pushCall(recursionGroup);
         }
         
-        QueryRewriter.rewrite(command, null, metadata, copy);
-        ProcessorPlan plan = QueryOptimizer.optimizePlan(command, metadata, idGenerator, capabilitiesFinder, analysisRecord, copy);
+        QueryRewriter.rewrite(newCommand, null, metadata, copy);
+        ProcessorPlan plan = QueryOptimizer.optimizePlan(newCommand, metadata, idGenerator, capabilitiesFinder, analysisRecord, copy);
 
-        TupleSourceID resultsId = bufferManager.createTupleSource(command.getProjectedSymbols(), TypeRetrievalUtil.getTypeNames(command.getProjectedSymbols()), copy.getConnectionID(), TupleSourceType.PROCESSOR);
+        TupleSourceID resultsId = bufferManager.createTupleSource(newCommand.getProjectedSymbols(), TypeRetrievalUtil.getTypeNames(newCommand.getProjectedSymbols()), copy.getConnectionID(), TupleSourceType.PROCESSOR);
         copy.setTupleSourceID(resultsId);
         return new QueryProcessor(plan, copy, bufferManager, processorDataManager);
 	}

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/internal/process/RequestWorkItem.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -370,7 +370,7 @@
 
 	protected void processNew() throws MetaMatrixProcessingException, MetaMatrixComponentException {
 		request.processRequest();
-		originalCommand = (Command)requestMsg.getCommand();
+		originalCommand = request.command;
 		processor = request.processor;
 		processor.setBatchHandler(new BatchHandler() {
 			public void batchProduced(TupleBatch batch)
@@ -468,9 +468,8 @@
             response.setWarnings(responseWarnings);
             
             // If it is stored procedure, set parameters
-            Command command = (Command)requestMsg.getCommand();
-            if (command instanceof StoredProcedure) {
-            	StoredProcedure proc = (StoredProcedure)command;
+            if (originalCommand instanceof StoredProcedure) {
+            	StoredProcedure proc = (StoredProcedure)originalCommand;
             	if (proc.returnParameters()) {
             		response.setParameters(getParameterInfo(proc));
             	}
@@ -691,7 +690,7 @@
                     dqpWorkContext.getUserName(),
                     dqpWorkContext.getVdbName(),
                     dqpWorkContext.getVdbVersion(),
-                    originalCommand,
+                    (originalCommand != null ? originalCommand.toString() : null ),
                     -1);
     }
 

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/CustomizableTrackingService.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -43,7 +43,6 @@
 import com.metamatrix.dqp.DQPPlugin;
 import com.metamatrix.dqp.spi.CommandLoggerSPI;
 import com.metamatrix.dqp.spi.TrackerLogConstants;
-import com.metamatrix.query.sql.lang.Command;
 
 
 /** 
@@ -100,13 +99,13 @@
                     String principal,
                     String vdbName,
                     String vdbVersion,
-                    Command sql,
+                    String sql,
                     int rowCount) {
 
         if (this.willRecordMMCmd()) {
             CustomizableTrackingMessage message = null;
             if (cmdPoint == TrackerLogConstants.CMD_POINT.BEGIN) {
-                message = new CustomizableTrackingMessage(System.currentTimeMillis(), requestId, txnUid, sessionUid, applicationName, principal, vdbName, vdbVersion, (sql!=null)?sql.toString():null);
+                message = new CustomizableTrackingMessage(System.currentTimeMillis(), requestId, txnUid, sessionUid, applicationName, principal, vdbName, vdbVersion, sql);
             } else {
                 boolean isCancelled = false;
                 boolean errorOccurred = false;
@@ -134,14 +133,14 @@
                     short cmdPoint,
                     String sessionUid,
                     String principal,
-                    Command sql,
+                    String sql,
                     int rowCount,
                     ExecutionContext context) {
         
         if (this.willRecordSrcCmd()) {
             CustomizableTrackingMessage message = null;
             if (cmdPoint == TrackerLogConstants.CMD_POINT.BEGIN) {
-                message = new CustomizableTrackingMessage(System.currentTimeMillis(), requestId, nodeID, subTxnUid, modelName, cbName, sessionUid, principal, (sql!=null)?sql.toString():null, context);
+                message = new CustomizableTrackingMessage(System.currentTimeMillis(), requestId, nodeID, subTxnUid, modelName, cbName, sessionUid, principal, sql, context);
 
             } else {
                 boolean isCancelled = false;

Modified: trunk/engine/src/main/java/com/metamatrix/dqp/service/TrackingService.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/dqp/service/TrackingService.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/main/java/com/metamatrix/dqp/service/TrackingService.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -27,7 +27,6 @@
 import org.teiid.connector.api.ExecutionContext;
 
 import com.metamatrix.common.application.ApplicationService;
-import com.metamatrix.query.sql.lang.Command;
 
 /**
  * This service is used to log transactions and commands,
@@ -35,12 +34,14 @@
  */
 public interface TrackingService extends ApplicationService {
     /**
-     * Log the command into database if the vaule of the property
+     * Log the command if the value of the property
      * "metamatrix.transaction.log.storeMMCMD" is "true".
+     * 
      * @param requestId Unique command ID.
      * @param txnUid Unique transaction ID.
      * @param cmdPoint Point in command being logged - 
-     * TransactionLogConstants.POINT.BEGIN, or TransactionLogConstants.POINT.END.
+     *                 TransactionLogConstants.POINT.BEGIN, 
+     *                 or TransactionLogConstants.POINT.END.
      * @param sessionUid Session ID.
      * @param applicationName name of the user application
      * @param principal User name.
@@ -50,21 +51,22 @@
      * @param rowCount Final row count.
      */
     public void log(String requestId, String txnUid, short cmdPoint, short status,
-            String sessionUid, String applicationName, String principal, String vdbName, String vdbVersion, Command sql, int rowCount);
+            String sessionUid, String applicationName, String principal, String vdbName, String vdbVersion, String sql, int rowCount);
 
     /**
-     * Log the command into database if the vaule of the property
+     * Log the command if the value of the property 
      * "metamatrix.transaction.log.storeSRCCMD" is "true".
+     * 
      * @param requestId Unique command ID.
      * @param nodeID Subcommand ID
      * @param subTxnUid Unique subtransaction ID.
-     * @param status Type of request -
-     * TransactionLogConstants.SRCCMD_STATUS.NEW, or TransactionLogConstants.SRCCMD_STATUS.CANCEL, 
-     * TransactionLogConstants.SRCCMD_STATUS.END, or TransactionLogConstants.SRCCMD_STATUS.ERROR.
+     * @param status Type of request - TransactionLogConstants.SRCCMD_STATUS.NEW, 
+     *               or TransactionLogConstants.SRCCMD_STATUS.CANCEL, or TransactionLogConstants.SRCCMD_STATUS.END, 
+     *               or TransactionLogConstants.SRCCMD_STATUS.ERROR.
      * @param modelName Name of model.
      * @param cbName Connector binding name.
-     * @param cmdPoint Point in command being logged - 
-     * TransactionLogConstants.POINT.BEGIN, or TransactionLogConstants.POINT.END.
+     * @param cmdPoint Point in command being logged - TransactionLogConstants.POINT.BEGIN, 
+     *                 or TransactionLogConstants.POINT.END.
      * @param sessionUid Session ID.
      * @param principal User name.
      * @param sql SQL for the command.
@@ -72,7 +74,7 @@
      */
     public void log(String requestId, long nodeID, String subTxnUid, 
             short status, String modelName, String cbName, short cmdPoint, 
-            String sessionUid, String principal, Command sql, int rowCount, 
+            String sessionUid, String principal, String sql, int rowCount, 
             ExecutionContext context);
 
     /**

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDQPCore.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDQPCore.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -95,8 +95,7 @@
     }
 
     public RequestMessage exampleRequestMessage(String sql) {
-        RequestMessage msg = new RequestMessage();
-        msg.setCommand(sql);
+        RequestMessage msg = new RequestMessage(sql);
         msg.setCallableStatement(false);
         msg.setCursorType(ResultSet.TYPE_SCROLL_INSENSITIVE);
         msg.setFetchSize(10);

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDataTierManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDataTierManager.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestDataTierManager.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -116,7 +116,6 @@
         command = helpGetCommand(sql, metadata);
         
         RequestMessage original = new RequestMessage();
-        original.setCommand(command);
         original.setExecutionId(1);
         
         DQPWorkContext workContext = new DQPWorkContext();

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestMetaDataProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestMetaDataProcessor.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestMetaDataProcessor.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -72,8 +72,7 @@
 
         // Initialize components
         RequestID requestID = workContext.getRequestID(1);  
-        RequestMessage requestMsg = new RequestMessage();
-        requestMsg.setCommand(sql);      
+        RequestMessage requestMsg = new RequestMessage(sql);
         TestDQPCoreRequestHandling.addRequest(requestMgr, requestMsg, requestID, command, null, null, AnalysisRecord.createNonRecordingRecord(), null, null); //$NON-NLS-1$
         
         ApplicationEnvironment env = new ApplicationEnvironment();

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestPreparedStatement.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestPreparedStatement.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -183,8 +183,7 @@
 			QueryPlannerException {
         
         //Create Request
-        RequestMessage request = new RequestMessage();
-        request.setCommand(preparedSql);
+        RequestMessage request = new RequestMessage(preparedSql);
         request.setPreparedStatement(true);
         request.setCallableStatement(callableStatement);
         request.setParameterValues(values);

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestRequest.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestRequest.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/internal/process/TestRequest.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -83,12 +83,11 @@
     
     public void testGetSchemasForValidation() throws Exception {
         FakeMetadataFacade metadata = FakeMetadataFactory.example1();
-        FakeMetadataObject doc1 = metadata.getStore().findObject("xmltest.doc1", FakeMetadataObject.GROUP);
+        FakeMetadataObject doc1 = metadata.getStore().findObject("xmltest.doc1", FakeMetadataObject.GROUP); //$NON-NLS-1$
         List<String> schemas = Arrays.asList("a.xsd", "b.xsd"); //$NON-NLS-1$ //$NON-NLS-2$
         doc1.putProperty(FakeMetadataObject.Props.XML_SCHEMAS, schemas);
-        RequestMessage message = new RequestMessage();
+        RequestMessage message = new RequestMessage("select * from xmltest.doc1"); //$NON-NLS-1$
         message.setValidationMode(true);
-        message.setCommandStr("select * from xmltest.doc1"); //$NON-NLS-1$
         DQPWorkContext workContext = new DQPWorkContext();
         workContext.setVdbName(VDB); 
         workContext.setVdbVersion(VDB_VERSION); 
@@ -116,7 +115,6 @@
         QueryResolver.resolveCommand(command, Collections.EMPTY_MAP, true, metadata, AnalysisRecord.createNonRecordingRecord());
         
         RequestMessage message = new RequestMessage();
-        message.setCommand(command);
         DQPWorkContext workContext = new DQPWorkContext();
         workContext.setVdbName(VDB); 
         workContext.setVdbVersion(VDB_VERSION); 

Deleted: trunk/engine/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/message/TestRequestMessage.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -1,113 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership.  Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package com.metamatrix.dqp.message;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.api.exception.MetaMatrixProcessingException;
-import com.metamatrix.core.util.UnitTestUtil;
-import com.metamatrix.dqp.internal.datamgr.language.TestQueryImpl;
-import com.metamatrix.jdbc.api.ExecutionProperties;
-
-public class TestRequestMessage extends TestCase {
-
-    /**
-     * Constructor for TestRequestMessage.
-     * @param name
-     */
-    public TestRequestMessage(String name) {
-        super(name);
-    }
-
-    public static RequestMessage example() {
-        RequestMessage message = new RequestMessage();
-        message.setCallableStatement(true);
-        message.setCommand(TestQueryImpl.helpExample());
-        message.setFetchSize(100);
-        List params = new ArrayList();
-        params.add(new Integer(100));
-        params.add(new Integer(200));
-        params.add(new Integer(300));
-        params.add(new Integer(400));
-        message.setParameterValues(params);
-
-        message.setPartialResults(true);
-        message.setPreparedStatement(false);
-        message.setSubmittedTimestamp(new Date(11111111L));
-        message.setProcessingTimestamp(new Date(12345678L));
-        message.setStyleSheet("myStyleSheet"); //$NON-NLS-1$
-        message.setExecutionPayload("myExecutionPayload"); //$NON-NLS-1$
-        try {
-			message.setTxnAutoWrapMode(ExecutionProperties.AUTO_WRAP_ON);
-		} catch (MetaMatrixProcessingException e) {
-			throw new RuntimeException(e);
-		} 
-
-        message.setValidationMode(true);
-        message.setXMLFormat("xMLFormat"); //$NON-NLS-1$
-        message.setShowPlan(true);
-        message.setRowLimit(1313);
-        return message;
-    }
-
-    public void testSerialize() throws Exception {
-        RequestMessage copy = UnitTestUtil.helpSerialize(example());
-
-        assertTrue(copy.isCallableStatement());
-        assertEquals(TestQueryImpl.helpExample(), copy.getCommand());
-        assertEquals(100, copy.getFetchSize());
-        assertNotNull(copy.getParameterValues());
-        assertEquals(4, copy.getParameterValues().size());
-        assertEquals(new Integer(100), copy.getParameterValues().get(0));
-        assertEquals(new Integer(200), copy.getParameterValues().get(1));
-        assertEquals(new Integer(300), copy.getParameterValues().get(2));
-        assertEquals(new Integer(400), copy.getParameterValues().get(3));
-
-        assertFalse(copy.isPreparedStatement());
-        assertEquals(new Date(11111111L), copy.getSubmittedTimestamp());
-        assertEquals(new Date(12345678L), copy.getProcessingTimestamp());
-        assertEquals("myStyleSheet", copy.getStyleSheet()); //$NON-NLS-1$
-        assertEquals("myExecutionPayload", copy.getExecutionPayload()); //$NON-NLS-1$
-        assertEquals(ExecutionProperties.AUTO_WRAP_ON, copy.getTxnAutoWrapMode()); //$NON-NLS-1$
-        assertTrue(copy.getValidationMode());
-        assertEquals("xMLFormat", copy.getXMLFormat()); //$NON-NLS-1$
-        assertTrue(copy.getShowPlan());
-        assertEquals(1313, copy.getRowLimit());
-        
-    }
-    
-    public void testInvalidTxnAutoWrap() {
-		RequestMessage rm = new RequestMessage();
-		try {
-			rm.setTxnAutoWrapMode("foo"); //$NON-NLS-1$
-			fail("exception expected"); //$NON-NLS-1$
-		} catch (MetaMatrixProcessingException e) {
-			assertEquals("'FOO' is an invalid transaction autowrap mode.", e.getMessage()); //$NON-NLS-1$
-		}
-	}
-
-}

Modified: trunk/engine/src/test/java/com/metamatrix/dqp/service/TestCustomizableTrackingService.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/dqp/service/TestCustomizableTrackingService.java	2009-03-12 23:09:37 UTC (rev 555)
+++ trunk/engine/src/test/java/com/metamatrix/dqp/service/TestCustomizableTrackingService.java	2009-03-13 18:54:39 UTC (rev 556)
@@ -22,21 +22,37 @@
 
 package com.metamatrix.dqp.service;
 
+import java.io.Serializable;
+import java.sql.ResultSet;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
+import junit.framework.TestCase;
+
 import org.teiid.connector.api.ExecutionContext;
 
-import junit.framework.TestCase;
-
+import com.metamatrix.api.exception.MetaMatrixProcessingException;
+import com.metamatrix.common.application.ApplicationEnvironment;
 import com.metamatrix.common.application.DQPConfigSource;
 import com.metamatrix.common.application.exception.ApplicationInitializationException;
 import com.metamatrix.common.application.exception.ApplicationLifecycleException;
+import com.metamatrix.common.vdb.api.ModelInfo;
+import com.metamatrix.dqp.internal.datamgr.impl.FakeTransactionService;
+import com.metamatrix.dqp.internal.process.DQPCore;
+import com.metamatrix.dqp.internal.process.DQPWorkContext;
+import com.metamatrix.dqp.message.RequestMessage;
+import com.metamatrix.dqp.message.ResultsMessage;
 import com.metamatrix.dqp.spi.CommandLoggerSPI;
 import com.metamatrix.dqp.spi.TrackerLogConstants;
+import com.metamatrix.platform.security.api.MetaMatrixSessionID;
 import com.metamatrix.query.sql.lang.Command;
 import com.metamatrix.query.sql.lang.TestQuery;
+import com.metamatrix.query.unittest.FakeMetadataFactory;
 
 /** 
  * Tests the DQP Tracking service implementation which uses a CommandLogger service
@@ -100,6 +116,33 @@
         assertEquals(expectedResults, ((FakeCommandLogger)trackingService.getCommandLogger()).logEntries);
     }      
     
+    /**
+     * Test the tracking service as it is invoked by DQP during query processing
+     * using a <code>String</code> as the query object.
+     * <p>
+     * This test creates a sample query statement of type <code>String</code> along 
+     * with an instance of <code>TrackingService</code> returned by a call to 
+     * <code>getTrackingService()</code> asking for a <code>TrackingService</code> that 
+     * will log the user-command.  The query and <code>TrackingService</code> instance 
+     * are passed to the helper method <code>logUserCommandViaDQP()</code> and the 
+     * expected results returned from the helper method are compared to the actual 
+     * results logged by <code>FakeCommandLogger</code>.
+     * <p>
+     * This test can only succeed if the log entry sent to <code>FakeCommandLogger</code>
+     * from <code>DQPCore</code> matches the expected results returned by the 
+     * helper method.
+     * 
+     * @see #getTrackingService(boolean, boolean, boolean)
+     * @see #helpLogUserCommandViaDQP(TrackingService, Serializable)
+     * @since 6
+     * @throws Exception
+     */
+    public void testUserCommandFromDQP_String() throws Exception {
+        String sql = "SELECT SQRT(100)"; //$NON-NLS-1$
+    	CustomizableTrackingService trackingService = getTrackingService(false, true, false);
+        helpLogUserCommandViaDQP(trackingService, sql);
+    }      
+    
     // ========================================================================================================
     // test utilities
     // ========================================================================================================
@@ -118,6 +161,124 @@
         return service;
     }
     
+    /**
+     * Helper method that creates an instance of <code>DQPCore</code> and sends 
+     * it a <code>RequestMessage</code> along with the value passed in <code>ts</code> 
+     * so that <code>DQPCore</code> can use it as the tracking service to log the 
+     * user-command <code>command</code> if <code>ts</code> is set to capture 
+     * user-commands.  
+     * <p>
+     * If <code>ts</code> is set to record the user-command, this method will 
+     * return two log entries.  The first log entry represents the START state 
+     * of the user-command and the second represents the END state of the 
+     * user command.  
+     * <p>
+     * <code>command</code> must be valid and DQP must be able to parse the query.  
+     * Because this helper method does not actually build or establish any metadata 
+     * for DQP or define any sources, <code>command</code> should only contain scalar 
+     * functions or constant values for its symbols.  Because DQP can receive either 
+     * a <code>String</code> or a <code>Command</code> object representing the 
+     * user-command, <code>command</code> can be of either type.  <code>command</code> 
+     * will be passed to the <code>RequestMessage</code> that is sent to <code>DQPCore</code> 
+     * 
+     * @param ts A configured and running instance of a <code>TrackingService</code>.
+     * @param command The query representing the user-command.
+     * @return If <code>ts</code> has been set to record the user-command, two log entries 
+     *         should be returned.  Each entry is made up of one or more <code>Object</code> 
+     *         types and is contained within a <code>List</code> object.  The final two log
+     *         entries are also contained in a <code>List</code> object.
+     * @throws InterruptedException
+     * @throws ExecutionException
+     * @throws TimeoutException
+     * @throws MetaMatrixProcessingException
+     * @throws ApplicationLifecycleException
+     */
+    private void helpLogUserCommandViaDQP(CustomizableTrackingService ts, String command) throws InterruptedException, ExecutionException, TimeoutException, MetaMatrixProcessingException, ApplicationLifecycleException {
+        String principal = "stuart"; //$NON-NLS-1$
+        String vdbName = "bqt"; //$NON-NLS-1$
+		String vdbVersion = "1"; //$NON-NLS-1$
+		MetaMatrixSessionID sessionID = new MetaMatrixSessionID(1); 
+        int requestID = 100;
+        int finalRowCount = 1;
+        List<Object> expectedStartLogEntry = new ArrayList<Object>();
+        List<Object> expectedEndLogEntry = new ArrayList<Object>();
+        List<List<Object>> expectedLogEntries = new ArrayList<List<Object>>();
+
+        if ( ts.willRecordMMCmd() ) {
+	        expectedStartLogEntry.add(sessionID + "." + requestID);	// Request ID //$NON-NLS-1$
+	        expectedStartLogEntry.add(null);							// Transaction ID 
+	        expectedStartLogEntry.add(sessionID.toString());			// Session ID
+	        expectedStartLogEntry.add(null);							// Application Name
+	        expectedStartLogEntry.add(principal);						// Principal Name
+	        expectedStartLogEntry.add(vdbName);						// VDB Name
+	        expectedStartLogEntry.add(vdbVersion);					// VDB Version
+	        expectedStartLogEntry.add(command.toString());				// SQL
+	        expectedLogEntries.add(expectedStartLogEntry);
+	
+	        expectedEndLogEntry.add(sessionID + "." + requestID);	// Request ID //$NON-NLS-1$
+	        expectedEndLogEntry.add(null);							// Transaction ID 
+	        expectedEndLogEntry.add(sessionID.toString());			// Session ID
+	        expectedEndLogEntry.add(principal);						// Principal Name
+	        expectedEndLogEntry.add(vdbName);							// VDB Name
+	        expectedEndLogEntry.add(vdbVersion);						// VDB Version
+	        expectedEndLogEntry.add(new Integer(finalRowCount));		// Expected Number of Rows
+	        expectedEndLogEntry.add(Boolean.FALSE);					// isCanceled?
+	        expectedEndLogEntry.add(Boolean.FALSE);					// wasError?
+	        expectedLogEntries.add(expectedEndLogEntry);
+        }
+        
+    	ApplicationEnvironment env = new ApplicationEnvironment();
+        env.bindService(DQPServiceNames.BUFFER_SERVICE, new FakeBufferService());
+        FakeMetadataService mdSvc = new FakeMetadataService();
+		mdSvc.addVdb(vdbName, vdbVersion, FakeMetadataFactory.exampleBQTCached()); 
+        env.bindService(DQPServiceNames.METADATA_SERVICE, mdSvc);
+        env.bindService(DQPServiceNames.DATA_SERVICE, new AutoGenDataService());
+        env.bindService(DQPServiceNames.TRANSACTION_SERVICE, new FakeTransactionService());
+        env.bindService(DQPServiceNames.TRACKING_SERVICE, ts);
+        FakeVDBService vdbService = new FakeVDBService();
+        vdbService.addBinding(vdbName, vdbVersion, "BQT1", "mmuuid:blah", "BQT"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        vdbService.addBinding(vdbName, vdbVersion, "BQT2", "mmuuid:blah", "BQT"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        vdbService.addBinding(vdbName, vdbVersion, "BQT3", "mmuuid:blah", "BQT"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 
+        vdbService.addModel(vdbName, vdbVersion, "BQT3", ModelInfo.PRIVATE, false); //$NON-NLS-1$
+        env.bindService(DQPServiceNames.VDB_SERVICE, vdbService);
+
+        DQPCore core = new DQPCore(env);
+        core.start(new Properties());
+
+        DQPWorkContext workContext = new DQPWorkContext();
+        workContext.setVdbName(vdbName);
+        workContext.setVdbVersion(vdbVersion);
+        workContext.setSessionId(sessionID);
+        workContext.setUserName(principal);
+        DQPWorkContext.setWorkContext(workContext);
+        
+        RequestMessage reqMsg = new RequestMessage(command);
+        reqMsg.setCallableStatement(false);
+        reqMsg.setCursorType(ResultSet.TYPE_SCROLL_INSENSITIVE);
+        reqMsg.setFetchSize(10);
+        reqMsg.setPartialResults(false);
+        reqMsg.setExecutionId(requestID);
+
+        ResultsMessage results = null;
+        Future<ResultsMessage> message = null;
+        
+        // Execute reqMsg
+        message = core.executeRequest(reqMsg.getExecutionId(), reqMsg);
+        results = message.get(50000, TimeUnit.MILLISECONDS);
+        assertNull("executeRequest resulted in " + results.getException(), results.getException()); //$NON-NLS-1$
+        core.closeRequest(requestID);
+        FakeCommandLogger fcl = (FakeCommandLogger)ts.getCommandLogger();
+        //close is fully asynch, calling stop immediately may take effect before the work item is requeued
+        synchronized (fcl) {
+        	for (int i = 0; i < 10 && fcl.logEntries.size() != expectedLogEntries.size(); i++) {
+        		fcl.wait(50);
+        	}
+		}
+        core.stop();
+        ts.stop();
+        assertEquals(expectedLogEntries, fcl.logEntries);
+    }
+    
     private List logExampleUserCommandStart(TrackingService trackingService) {
         
         String requestID = "req1"; //$NON-NLS-1$
@@ -131,9 +292,10 @@
         String vdbVersion = "2"; //$NON-NLS-1$
         Command sql = TestQuery.sample1();
         int rows = 10000;
+
+        String sqlStr = sql != null ? sql.toString() : null;
+        trackingService.log(requestID, transactionID, cmdPoint, status, sessionID, applicationName, principal, vdbName, vdbVersion, sqlStr, rows);
         
-        trackingService.log(requestID, transactionID, cmdPoint, status, sessionID, applicationName, principal, vdbName, vdbVersion, sql, rows);
-        
         List expectedLogEntry = new ArrayList();
         expectedLogEntry.add(requestID);
         expectedLogEntry.add(transactionID);
@@ -163,7 +325,8 @@
         boolean isCancelled = false;
         boolean errorOccurred = false;
         
-        trackingService.log(requestID, transactionID, cmdPoint, status, sessionID, applicationName, principal, vdbName, vdbVersion, sql, rows);
+        String sqlStr = sql != null ? sql.toString() : null;
+        trackingService.log(requestID, transactionID, cmdPoint, status, sessionID, applicationName, principal, vdbName, vdbVersion, sqlStr, rows);
         
         List expectedLogEntry = new ArrayList();
         expectedLogEntry.add(requestID);
@@ -192,8 +355,9 @@
         short status = TrackerLogConstants.CMD_STATUS.NEW;
         int finalRowCount = 3;
         
+        String sqlStr = sql != null ? sql.toString() : null;
         trackingService.log(requestID, sourceCommandID, subTransactionID, status, modelName, connectorBindingName, 
-                            cmdPoint, sessionID, principal, sql, finalRowCount, null);
+                            cmdPoint, sessionID, principal, sqlStr, finalRowCount, null);
         
         List expectedLogEntry = new ArrayList();
         expectedLogEntry.add(requestID);
@@ -223,8 +387,9 @@
         boolean isCancelled = true;
         boolean errorOccurred = false;
 
+        String sqlStr = sql != null ? sql.toString() : null;
         trackingService.log(requestID, sourceCommandID, subTransactionID, status, modelName, connectorBindingName, 
-                            cmdPoint, sessionID, principal, sql, finalRowCount, null);
+                            cmdPoint, sessionID, principal, sqlStr, finalRowCount, null);
         
         List expectedLogEntry = new ArrayList();
         expectedLogEntry.add(requestID);
@@ -264,7 +429,7 @@
         public void close() {
         }
 
-        public void dataSourceCommandStart(long timestamp,
+        public synchronized void dataSourceCommandStart(long timestamp,
                                            String requestID,
                                            long sourceCommandID,
                                            String subTransactionID,
@@ -285,9 +450,10 @@
             logEntry.add(principal);
             logEntry.add(sql);
             logEntries.add(logEntry);
+            notifyAll();
         }        
         
-        public void dataSourceCommandEnd(long timestamp,
+        public synchronized void dataSourceCommandEnd(long timestamp,
                                          String requestID,
                                          long sourceCommandID,
                                          String subTransactionID,
@@ -312,43 +478,10 @@
             logEntry.add(Boolean.valueOf(isCancelled));
             logEntry.add(Boolean.valueOf(errorOccurred));
             logEntries.add(logEntry);
+            notifyAll();
         }
 
-        public void transactionStart(long timestamp,
-                                     String transactionID,
-                                     String sessionID,
-                                     String principal,
-                                     String vdbName,
-                                     String vdbVersion) {
-            
-            List logEntry = new ArrayList(8);
-            logEntry.add(transactionID);
-            logEntry.add(sessionID);
-            logEntry.add(principal);
-            logEntry.add(vdbName);
-            logEntry.add(vdbVersion);
-            logEntries.add(logEntry);
-        }
-
-        public void transactionEnd(long timestamp,
-                                   String transactionID,
-                                   String sessionID,
-                                   String principal,
-                                   String vdbName,
-                                   String vdbVersion,
-                                   boolean commit) {
-            
-            List logEntry = new ArrayList(8);
-            logEntry.add(transactionID);
-            logEntry.add(sessionID);
-            logEntry.add(principal);
-            logEntry.add(vdbName);
-            logEntry.add(vdbVersion);
-            logEntry.add(Boolean.valueOf(commit));
-            logEntries.add(logEntry);
-        }
-        
-        public void userCommandStart(long timestamp,
+        public synchronized void userCommandStart(long timestamp,
                                      String requestID,
                                      String transactionID,
                                      String sessionID,
@@ -367,10 +500,11 @@
             logEntry.add(vdbName);
             logEntry.add(vdbVersion);
             logEntry.add(sql);
-            logEntries.add(logEntry);            
+            logEntries.add(logEntry);   
+            notifyAll();
         }
         
-        public void userCommandEnd(long timestamp,
+        public synchronized void userCommandEnd(long timestamp,
                                    String requestID,
                                    String transactionID,
                                    String sessionID,
@@ -391,7 +525,8 @@
             logEntry.add(new Integer(finalRowCount));
             logEntry.add(Boolean.valueOf(isCancelled));
             logEntry.add(Boolean.valueOf(errorOccurred));
-            logEntries.add(logEntry);            
+            logEntries.add(logEntry);
+            notifyAll();
         }
     }
 }




More information about the teiid-commits mailing list