[teiid-commits] teiid SVN: r4466 - in trunk: build/kits/jboss-as7/docs/teiid and 26 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Sep 24 11:36:50 EDT 2012


Author: shawkins
Date: 2012-09-24 11:36:49 -0400 (Mon, 24 Sep 2012)
New Revision: 4466

Added:
   trunk/engine/src/main/java/org/teiid/query/sql/proc/ExceptionExpression.java
   trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseStatement.java
   trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcErrors.java
Removed:
   trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java
Modified:
   trunk/api/src/main/java/org/teiid/language/SQLConstants.java
   trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
   trunk/client/src/main/java/org/teiid/client/ProcedureErrorInstructionException.java
   trunk/client/src/main/java/org/teiid/client/SourceWarning.java
   trunk/client/src/main/java/org/teiid/client/util/ExceptionUtil.java
   trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java
   trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java
   trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
   trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
   trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
   trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
   trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java
   trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java
   trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
   trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
   trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
   trunk/engine/src/main/java/org/teiid/query/processor/proc/ErrorInstruction.java
   trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
   trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
   trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
   trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
   trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java
   trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
   trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
   trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
   trunk/engine/src/main/resources/org/teiid/query/i18n.properties
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
   trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
   trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
   trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
   trunk/engine/src/test/java/org/teiid/query/sql/proc/TestRaiseErrorStatement.java
   trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
   trunk/jboss-integration/src/test/java/org/teiid/jboss/rest/TestRestWebArchiveBuilder.java
Log:
TEIID-1386 initial changes to exception handling.  the error statement is superseded by a more general raise statement

Modified: trunk/api/src/main/java/org/teiid/language/SQLConstants.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/SQLConstants.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/api/src/main/java/org/teiid/language/SQLConstants.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -126,6 +126,8 @@
 		public static final String XMLDECLARATION = "XMLDECLARATION"; //$NON-NLS-1$
 		public static final String VARIADIC = "VARIADIC"; //$NON-NLS-1$
 		public static final String INDEX = "INDEX"; //$NON-NLS-1$
+		public static final String EXCEPTION = "EXCEPTION"; //$NON-NLS-1$
+		public static final String RAISE = "RAISE"; //$NON-NLS-1$
 	}
 	
 	public interface Reserved {

Modified: trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/build/kits/jboss-as7/docs/teiid/teiid-releasenotes.html	2012-09-24 15:36:49 UTC (rev 4466)
@@ -38,6 +38,7 @@
 	<li>TEIID-2181 <b>System query performance</b> - system queries are now indexed on case-insensitive schema/table name columns.
 	<li>TEIID-2086 <b>Transactional results caching</b> - the result set cache is now transactional by default.
 	<li>TEIID-2210 <b>Object Translator</b> - the translator-object can support Infinispan Cache and other Map type caches.  See OBJECTTABLE for executing queries against this translator.
+	<li>TEIID-1386 <b>Procedure exception handling</b> - the Teiid procedure language now supports exception handling and emitting SQLWarnings.  See the Reference for syntax and usage.
 </ul>
 
 <h2><a name="Compatibility">Compatibility Issues</a></h2>
@@ -55,6 +56,9 @@
   <li>TEIID-2184 to be consistent with the rest of Teiid's logic the system functions dayName and monthName will return values from the default locale, rather than only the English names.  Use the system property org.teiid.enDateNames true to revert to the pre-8.2 behavior.
   <li>TEIID-2187 the CONSTRAINT keyword is not correctly used in table DDL.  It should be replaced with a comma from scripts to be compatible with 8.2.  If desired, 8.2 now supports the CONSTRAINT keyword to provide a name for each constraint.
   <li>TEIID-2181 system tables no longer contain valid OIDs.  That responsibility has moved to the pg_catalog.
+  <li>TEIID-1386 assignment statements and stored procedure invocations assigning a return value will no longer allow non-quoted non-reserved identifiers as left hand side variables.  The workaround is to use a quoted variable name if you are using a non-reserved word as a variable name.
+  <li>TEIID-1386 the SQLState and errorCode reported by a TeiidSQLException will typically be from the top level nested SQLException.  If there is also a nested TeiidException, the TeiidSQLException.teiidCode will be set to the TeiidException.getCode value and the TeiidSQLException.errorCode will be set
+  to the integer suffix of the teiidCode if possible.  
 </ul>
 
 <h4>from 8.0</h4>

Modified: trunk/client/src/main/java/org/teiid/client/ProcedureErrorInstructionException.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/ProcedureErrorInstructionException.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/client/src/main/java/org/teiid/client/ProcedureErrorInstructionException.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -50,7 +50,7 @@
         super(message);
     }
 
-    public ProcedureErrorInstructionException(BundleUtil.Event event, String message) {
-        super(event, message);
+    public ProcedureErrorInstructionException(BundleUtil.Event event, Exception parent) {
+        super(event, parent);
     }    
 }

Modified: trunk/client/src/main/java/org/teiid/client/SourceWarning.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/SourceWarning.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/client/src/main/java/org/teiid/client/SourceWarning.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -34,7 +34,7 @@
 
 public class SourceWarning extends TeiidException {
 	
-	private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
+	public static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
 	private String modelName = "UNKNOWN"; // variable stores the name of the model for the atomic query //$NON-NLS-1$
 	private String connectorBindingName = "UNKNOWN"; // variable stores name of the connector binding //$NON-NLS-1$
 	private boolean partialResults;

Modified: trunk/client/src/main/java/org/teiid/client/util/ExceptionUtil.java
===================================================================
--- trunk/client/src/main/java/org/teiid/client/util/ExceptionUtil.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/client/src/main/java/org/teiid/client/util/ExceptionUtil.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -31,11 +31,10 @@
 
 public class ExceptionUtil {
 	
-    @SuppressWarnings("unchecked")
 	public static <T extends Throwable> T getExceptionOfType(Throwable ex, Class<T> cls) {
         while (ex != null) {
             if (cls.isAssignableFrom(ex.getClass())) {
-                return (T)ex;
+                return cls.cast(ex);
             } 
             if (ex.getCause() == ex) {
             	break;

Modified: trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLException.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -47,6 +47,7 @@
 public class TeiidSQLException extends SQLException {
 
 	private static final long serialVersionUID = 3672305321346173922L;
+	private String teiidCode;
 
 	/**
      * No-arg constructor required by Externalizable semantics.
@@ -70,8 +71,8 @@
         return create(exception, exception.getMessage());
     }
         
-    public TeiidSQLException(Throwable ex, String reason, String sqlState) {
-        super(reason, sqlState); // passing the message to the super class constructor.
+    public TeiidSQLException(Throwable ex, String reason, String sqlState, int errorCode) {
+        super(reason, sqlState, errorCode); // passing the message to the super class constructor.
         initCause(ex);
     }
     
@@ -94,23 +95,41 @@
     public static TeiidSQLException create(Throwable exception, String message) {
 		message = getMessage(exception, message);
 		Throwable origException = exception;
-		if (exception instanceof TeiidSQLException) {
-			if (message.equals(exception.getMessage())) {
-				return (TeiidSQLException) exception;
-			}
+		if (exception instanceof TeiidSQLException 
+				&& message.equals(exception.getMessage())) {
+			return (TeiidSQLException) exception;
 		}
 		if (exception instanceof SQLException) {
 			return new TeiidSQLException((SQLException) exception, message, true);
 		}
 		String sqlState = SQLStates.DEFAULT;
+		int errorCode = 0;
+		SQLException se = ExceptionUtil.getExceptionOfType(exception, SQLException.class);
+		if (se != null && se.getSQLState() != null) {
+			sqlState = se.getSQLState();
+			errorCode = se.getErrorCode();
+		}
 		TeiidException te = ExceptionUtil.getExceptionOfType(exception, TeiidException.class);
+		String code = null;
 		if (te != null && te.getCode() != null) {
-			sqlState = te.getCode();
-		} else {
-			exception = findRootException(exception);
-			sqlState = determineSQLState(exception, sqlState);
+			code = te.getCode();
+			if (errorCode == 0) {
+				String intPart = code;
+				if (code.startsWith("TEIID")) { //$NON-NLS-1$
+					intPart = code.substring(5);
+				}
+				try {
+					errorCode = Integer.valueOf(intPart);
+				} catch (NumberFormatException e) {
+					
+				}
+			}
 		}
-		return new TeiidSQLException(origException, message, sqlState);
+		exception = findRootException(exception);
+		sqlState = determineSQLState(exception, sqlState);
+		TeiidSQLException tse = new TeiidSQLException(origException, message, sqlState, errorCode);
+		tse.teiidCode = code;
+		return tse;
 	}
 
     /** 
@@ -228,4 +247,8 @@
     public boolean isUsageErrorState() {
         return SQLStates.isUsageErrorState(getSQLState());
     }
+    
+    public String getTeiidCode() {
+		return teiidCode;
+	}
 }
\ No newline at end of file

Modified: trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidSQLWarning.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -74,6 +74,10 @@
         this.modelName = modelName;
     }
     
+    public TeiidSQLWarning(String reason, String sqlState, int errorCode, Throwable ex) {
+        super(reason, sqlState, errorCode, ex); 
+    }
+    
     /**
      * 
      * @return the source name or null if the warning is not associated with a source

Modified: trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java
===================================================================
--- trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/client/src/test/java/org/teiid/jdbc/TestSQLException.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -214,17 +214,18 @@
         assertEquals(exception.getNextException().getNextException().getMessage(), nested.getMessage());
     }
 	public static enum Event implements BundleUtil.Event {
-		T21,
+		TEIID21,
 	}
-    @Test public void testCodeAsSQLState() {
+    @Test public void testCodeAsVendorCode() {
 
-        TeiidException sqlexception = new TeiidException(Event.T21, "foo"); //$NON-NLS-1$ 
+        TeiidException sqlexception = new TeiidException(Event.TEIID21, "foo"); //$NON-NLS-1$ 
         
         String message = "top level message"; //$NON-NLS-1$
         
         TeiidSQLException exception = TeiidSQLException.create(sqlexception, message);
         
-        assertEquals(sqlexception.getCode(), exception.getSQLState());        
+        assertEquals(sqlexception.getCode(), exception.getTeiidCode());        
+        assertEquals(21, exception.getErrorCode());
     }
 
 }

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierTupleSource.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -543,7 +543,7 @@
 		if (response.getWarnings() != null) {
 			for (Exception warning : response.getWarnings()) {
 				SourceWarning sourceFailure = new SourceWarning(this.aqr.getModelName(), aqr.getConnectorName(), warning, partial);
-		        workItem.addSourceFailureDetails(sourceFailure);
+		        this.aqr.getCommandContext().addWarning(sourceFailure);
 			}
 		}
 		if (response.getFinalRow() >= 0) {

Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -36,7 +36,6 @@
 
 import org.teiid.client.RequestMessage;
 import org.teiid.client.ResultsMessage;
-import org.teiid.client.SourceWarning;
 import org.teiid.client.RequestMessage.ShowPlan;
 import org.teiid.client.lob.LobChunk;
 import org.teiid.client.metadata.ParameterInfo;
@@ -155,8 +154,6 @@
      */
     private Throwable processingException;
     private Map<AtomicRequestID, DataTierTupleSource> connectorInfo = Collections.synchronizedMap(new HashMap<AtomicRequestID, DataTierTupleSource>(4));
-    // This exception contains details of all the atomic requests that failed when query is run in partial results mode.
-    private List<TeiidException> warnings = new LinkedList<TeiidException>();
     private volatile boolean doneProducingBatches;
     private volatile boolean isClosed;
     private volatile boolean isCanceled;
@@ -719,19 +716,7 @@
 	        // set final row
 	        response.setFinalRow(finalRowCount);
 	
-	        // send any warnings with the response object
-	        List<Throwable> responseWarnings = new ArrayList<Throwable>();
-	        if (this.processor != null) {
-				List<Exception> currentWarnings = processor.getAndClearWarnings();
-			    if (currentWarnings != null) {
-			    	responseWarnings.addAll(currentWarnings);
-			    }
-	        }
-		    synchronized (warnings) {
-	        	responseWarnings.addAll(this.warnings);
-	        	this.warnings.clear();
-		    }
-	        response.setWarnings(responseWarnings);
+	        setWarnings(response);
 	        
 	        // If it is stored procedure, set parameters
 	        if (originalCommand instanceof StoredProcedure) {
@@ -751,6 +736,18 @@
         receiver.receiveResults(response);
         return result;
 	}
+
+	private void setWarnings(ResultsMessage response) {
+		// send any warnings with the response object
+		List<Throwable> responseWarnings = new ArrayList<Throwable>();
+		if (this.processor != null) {
+			List<Exception> currentWarnings = processor.getAndClearWarnings();
+		    if (currentWarnings != null) {
+		    	responseWarnings.addAll(currentWarnings);
+		    }
+		}
+		response.setWarnings(responseWarnings);
+	}
     
     public ResultsMessage createResultsMessage(List<? extends List<?>> batch, List<? extends Expression> columnSymbols) {
         String[] columnNames = new String[columnSymbols.size()];
@@ -801,6 +798,7 @@
         if (isCanceled) {
         	exception = addCancelCode(exception); 
         }
+        setWarnings(response);
         response.setException(exception);
         setAnalysisRecords(response);
         receiver.receiveResults(response);
@@ -927,16 +925,6 @@
 		connectorInfo.put(atomicRequestId, connInfo);
 	}
     
-    /**
-	 * <p>This method add information to the warning on the work item for the given
-	 * <code>RequestID</code>. This method is called from <code>DataTierManager</code></p>
-	 */
-    public void addSourceFailureDetails(SourceWarning details) {
-    	synchronized (warnings) {
-			this.warnings.add(details);
-    	}
-	}
-        
 	boolean isCanceled() {
 		return isCanceled;
 	}
@@ -969,10 +957,6 @@
 		return this.connectorInfo.get(id);
 	}
 	
-	public List<TeiidException> getWarnings() {
-		return warnings;
-	}
-
 	@Override
 	public String toString() {
 		return this.requestID.toString();

Modified: trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/QueryPlugin.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -534,6 +534,7 @@
     	TEIID31116,
     	TEIID31117,
     	TEIID31118,
-    	TEIID31119,
+    	TEIID31119, 
+    	TEIID31120,
 	}
 }

Modified: trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -48,6 +48,7 @@
 
 import org.teiid.api.exception.query.ExpressionEvaluationException;
 import org.teiid.api.exception.query.FunctionExecutionException;
+import org.teiid.client.SourceWarning;
 import org.teiid.common.buffer.BlockedException;
 import org.teiid.core.ComponentNotFoundException;
 import org.teiid.core.TeiidComponentException;
@@ -57,6 +58,8 @@
 import org.teiid.core.types.XMLType.Type;
 import org.teiid.core.types.basic.StringToSQLXMLTransform;
 import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.jdbc.TeiidSQLException;
+import org.teiid.jdbc.TeiidSQLWarning;
 import org.teiid.language.Like.MatchMode;
 import org.teiid.query.QueryPlugin;
 import org.teiid.query.function.FunctionDescriptor;
@@ -66,6 +69,7 @@
 import org.teiid.query.processor.ProcessorDataManager;
 import org.teiid.query.sql.LanguageObject;
 import org.teiid.query.sql.lang.*;
+import org.teiid.query.sql.proc.ExceptionExpression;
 import org.teiid.query.sql.symbol.*;
 import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
 import org.teiid.query.sql.util.ValueIterator;
@@ -658,11 +662,39 @@
 			   result[i] = internalEvaluate(exprs.get(i), tuple);
 		   }
 		   return new ArrayImpl(result);
+	   } else if (expression instanceof ExceptionExpression) {
+		   return evaluate(tuple, (ExceptionExpression)expression);
 	   } else {
 	        throw new TeiidComponentException(QueryPlugin.Event.TEIID30329, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30329, expression.getClass().getName()));
 	   }
 	}
 
+	private Object evaluate(List<?> tuple, ExceptionExpression ee)
+			throws ExpressionEvaluationException, BlockedException,
+			TeiidComponentException {
+		String msg = (String) internalEvaluate(ee.getMessage(), tuple);
+		String sqlState = ee.getDefaultSQLState();
+		if (ee.getSqlState() != null) {
+			sqlState = (String) internalEvaluate(ee.getSqlState(), tuple);
+		}
+		Integer errorCode = null;
+		if (ee.getErrorCode() != null) {
+			errorCode = (Integer) internalEvaluate(ee.getErrorCode(), tuple);
+		}
+		Exception parent = null;
+		if (ee.getParent() != null) {
+			parent = (Exception) internalEvaluate(ee.getParent(), tuple);
+		}
+		Exception result = null;
+		if (ee.isWarning()) {
+			result = new TeiidSQLWarning(msg, sqlState, errorCode!=null?errorCode:0, parent);
+		} else {
+			result = new TeiidSQLException(parent, msg, sqlState, errorCode!=null?errorCode:0);
+		}
+		result.setStackTrace(SourceWarning.EMPTY_STACK_TRACE);
+		return result;
+	}
+
 	private Object evaluateXMLParse(List<?> tuple, final XMLParse xp) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
 		Object value = internalEvaluate(xp.getExpression(), tuple);
 		if (value == null) {

Modified: trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/DDLMetadataRepository.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -21,10 +21,10 @@
  */
 package org.teiid.query.metadata;
 
+import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.core.TeiidRuntimeException;
 import org.teiid.metadata.MetadataFactory;
 import org.teiid.query.QueryPlugin;
-import org.teiid.query.parser.ParseException;
 import org.teiid.query.parser.QueryParser;
 import org.teiid.translator.ExecutionFactory;
 import org.teiid.translator.TranslatorException;
@@ -36,7 +36,7 @@
 	public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory) throws TranslatorException {
 		try {
 			QueryParser.getQueryParser().parseDDL(factory, factory.getRawMetadata());
-		} catch (ParseException e) {
+		} catch (QueryParserException e) {
 			throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30386, e);
 		}
 		super.loadMetadata(factory, executionFactory, connectionFactory);

Modified: trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/SystemMetadata.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -34,6 +34,7 @@
 
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.core.TeiidRuntimeException;
 import org.teiid.core.types.DataTypeManager;
 import org.teiid.core.types.DataTypeManager.DefaultDataTypes;
@@ -43,7 +44,6 @@
 import org.teiid.metadata.MetadataFactory;
 import org.teiid.metadata.MetadataStore;
 import org.teiid.metadata.Table;
-import org.teiid.query.parser.ParseException;
 import org.teiid.query.parser.QueryParser;
 import org.teiid.query.validator.ValidatorReport;
 import org.teiid.translator.TranslatorException;
@@ -134,7 +134,7 @@
 			};
 			QueryParser.getQueryParser().parseDDL(factory, new InputStreamReader(is, Charset.forName("UTF-8"))); //$NON-NLS-1$
 			return factory;
-		} catch (ParseException e) {
+		} catch (QueryParserException e) {
 			throw new TeiidRuntimeException(e);
 		} finally {
 			try {

Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/ProcedurePlanner.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -194,7 +194,7 @@
             {
             	ErrorInstruction error = new ErrorInstruction();
             	instruction = error;
-            	RaiseErrorStatement res = (RaiseErrorStatement)statement;
+            	RaiseStatement res = (RaiseStatement)statement;
                 
 				Expression asigExpr = res.getExpression();
 				error.setExpression(asigExpr);

Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -356,12 +356,16 @@
         return new QueryParserException(QueryPlugin.Util.getString("QueryParser.parsingError", tme.getMessage())); //$NON-NLS-1$
     }
     
-    public void parseDDL(MetadataFactory factory, String ddl) throws ParseException {
+    public void parseDDL(MetadataFactory factory, String ddl) throws QueryParserException {
     	parseDDL(factory, new StringReader(ddl));
     }
     
-    public void parseDDL(MetadataFactory factory, Reader ddl) throws ParseException {
-    	getSqlParser(ddl).parseMetadata(factory);
+    public void parseDDL(MetadataFactory factory, Reader ddl) throws QueryParserException {
+    	try {
+			getSqlParser(ddl).parseMetadata(factory);
+		} catch (ParseException e) {
+			throw convertParserException(e);
+		}
     	HashSet<FunctionMethod> functions = new HashSet<FunctionMethod>();
     	for (FunctionMethod functionMethod : factory.getSchema().getFunctions().values()) {
 			if (!functions.add(functionMethod)) {

Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -64,9 +64,9 @@
 		return literal;
 	}
 	
-	void convertToParameters(List<Expression> values, StoredProcedure storedProcedure) {
+	void convertToParameters(List<Expression> values, StoredProcedure storedProcedure, int paramIndex) {
 		for (Expression value : values) {
-			SPParameter parameter = new SPParameter(storedProcedure.getParameters().size() + 1, value);
+			SPParameter parameter = new SPParameter(paramIndex++, value);
 			parameter.setParameterType(SPParameter.IN);
 			storedProcedure.setParameter(parameter);
 		}

Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ErrorInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ErrorInstruction.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ErrorInstruction.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -24,6 +24,8 @@
 
 import static org.teiid.query.analysis.AnalysisRecord.*;
 
+import java.sql.SQLWarning;
+
 import org.teiid.client.ProcedureErrorInstructionException;
 import org.teiid.client.plan.PlanNode;
 import org.teiid.core.TeiidComponentException;
@@ -39,8 +41,6 @@
  */
 public class ErrorInstruction extends ProgramInstruction {
 	
-    public static final String ERROR_PREFIX = "Procedure error:"; //$NON-NLS-1$
-    
     private Expression expression;
     
 	/**
@@ -76,8 +76,12 @@
     public void process(ProcedurePlan env) throws TeiidComponentException,
     		TeiidProcessingException {
     	Object value = env.evaluateExpression(expression);
-            LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, new Object[] {"Processing RaiseErrorInstruction with the value :", value}); //$NON-NLS-1$ 
-         throw new ProcedureErrorInstructionException(QueryPlugin.Event.TEIID30167, ERROR_PREFIX + (value != null ? value.toString() : "")); //$NON-NLS-1$ 
+        LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, "Processing ErrorInstruction with the value :", value); //$NON-NLS-1$ 
+    	if (value instanceof SQLWarning) {
+    		env.getContext().addWarning((Exception)value);
+    		return;
+    	}
+        throw new ProcedureErrorInstructionException(QueryPlugin.Event.TEIID30167, (Exception) value); 
     }
  
 }
\ No newline at end of file

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/UpdateProcedureResolver.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -33,6 +33,7 @@
 import org.teiid.client.metadata.ParameterInfo;
 import org.teiid.core.TeiidComponentException;
 import org.teiid.core.types.DataTypeManager;
+import org.teiid.language.SQLConstants;
 import org.teiid.logging.LogManager;
 import org.teiid.query.QueryPlugin;
 import org.teiid.query.metadata.SupportConstants;
@@ -217,7 +218,10 @@
 	        		     throw new QueryResolverException(QueryPlugin.Event.TEIID30123, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30123));
 	        		}
 	        		String varTypeName = DataTypeManager.getDataTypeName(varType);
-	        		exprStmt.setExpression(ResolverUtil.convertExpression(exprStmt.getExpression(), varTypeName, metadata));          
+	        		exprStmt.setExpression(ResolverUtil.convertExpression(exprStmt.getExpression(), varTypeName, metadata));     
+	        		if (statement.getType() == Statement.TYPE_ERROR) {
+	        			ResolverVisitor.checkException(exprStmt.getExpression());
+	        		}
                 }
                 break;
             case Statement.TYPE_WHILE:
@@ -301,11 +305,11 @@
         }
         variable.setType(DataTypeManager.getDataTypeClass(typeName));
         variable.setGroupSymbol(variables);
-        TempMetadataID id = new TempMetadataID(variable.getName(), variable.getType());
+        TempMetadataID id = new TempMetadataID(variable.getName(), typeName.equalsIgnoreCase(SQLConstants.NonReserved.EXCEPTION)?Exception.class:variable.getType());
         id.setUpdatable(true);
         variable.setMetadataID(id);
         //TODO: this will cause the variables group to loose it's cache of resolved symbols
-        metadata.getMetadataStore().addElementToTempGroup(ProcedureReservedWords.VARIABLES, (ElementSymbol)variable.clone());
+        metadata.getMetadataStore().addElementToTempGroup(ProcedureReservedWords.VARIABLES, variable.clone());
     }
 
     private void handleUnresolvableDeclaration(ElementSymbol variable, String description) throws QueryResolverException {

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -46,10 +46,12 @@
 import org.teiid.query.function.FunctionLibrary;
 import org.teiid.query.metadata.GroupInfo;
 import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempMetadataID;
 import org.teiid.query.sql.LanguageObject;
 import org.teiid.query.sql.LanguageVisitor;
 import org.teiid.query.sql.lang.*;
 import org.teiid.query.sql.navigator.PostOrderNavigator;
+import org.teiid.query.sql.proc.ExceptionExpression;
 import org.teiid.query.sql.symbol.*;
 import org.teiid.query.sql.symbol.AggregateSymbol.Type;
 import org.teiid.query.sql.symbol.ElementSymbol.DisplayMode;
@@ -405,6 +407,46 @@
     }
     
     @Override
+    public void visit(ExceptionExpression obj) {
+    	try {
+    		if (obj.getErrorCode() != null) {
+    			obj.setErrorCode(ResolverUtil.convertExpression(obj.getErrorCode(), DataTypeManager.DefaultDataTypes.INTEGER, metadata));
+    		}
+			obj.setMessage(ResolverUtil.convertExpression(obj.getMessage(), DataTypeManager.DefaultDataTypes.STRING, metadata));
+			if (obj.getSqlState() != null) {
+				obj.setSqlState(ResolverUtil.convertExpression(obj.getSqlState(), DataTypeManager.DefaultDataTypes.STRING, metadata));
+			}
+			checkException(obj.getParent());
+		} catch (QueryResolverException e) {
+			handleException(e);
+		}
+    }
+
+	public static void checkException(Expression obj)
+			throws QueryResolverException {
+		if (obj == null || obj instanceof ExceptionExpression) {
+			return;
+		}
+		if (obj instanceof ElementSymbol) {
+			ElementSymbol es = (ElementSymbol)obj;
+			if (!(es.getMetadataID() instanceof TempMetadataID)) {
+				throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
+			}
+			TempMetadataID tid = (TempMetadataID)es.getMetadataID();
+			if (tid.getType() != Exception.class) {
+				throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
+			}
+		} else if (obj instanceof Constant) {
+			Constant c = (Constant)obj;
+			if (!(c.getValue() instanceof Exception)) {
+				throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
+			}
+		} else {
+			throw new QueryResolverException(QueryPlugin.Event.TEIID31120, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31120, obj));
+		}
+	}
+    
+    @Override
     public void visit(AggregateSymbol obj) {
     	if (obj.getCondition() != null) {
 			try {

Modified: trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -110,7 +110,7 @@
         visit((AssignmentStatement)obj);
     }    
     public void visit(IfStatement obj) {}
-    public void visit(RaiseErrorStatement obj) {}
+    public void visit(RaiseStatement obj) {}
     public void visit(BranchingStatement obj) {}
     public void visit(WhileStatement obj) {}
     public void visit(LoopStatement obj) {}
@@ -145,4 +145,6 @@
 
 	public void visit(Array array) {}
 	public void visit(ObjectTable objectTable) {}
+
+	public void visit(ExceptionExpression obj) {}
 }

Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -310,7 +310,7 @@
         visitNode(obj.getOption());
         postVisitVisitor(obj);
     }
-    public void visit(RaiseErrorStatement obj) {
+    public void visit(RaiseStatement obj) {
         preVisitVisitor(obj);
         visitNode(obj.getExpression());
         postVisitVisitor(obj);
@@ -635,6 +635,16 @@
     	postVisitVisitor(array);
     }
     
+    @Override
+    public void visit(ExceptionExpression exceptionExpression) {
+    	preVisitVisitor(exceptionExpression);
+    	visitNode(exceptionExpression.getMessage());
+    	visitNode(exceptionExpression.getSqlState());
+    	visitNode(exceptionExpression.getErrorCode());
+    	visitNode(exceptionExpression.getParent());
+    	postVisitVisitor(exceptionExpression);
+    }
+    
     public static void doVisit(LanguageObject object, LanguageVisitor visitor, boolean order) {
     	doVisit(object, visitor, order, false);
     }

Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/DeclareStatement.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -113,9 +113,9 @@
 	 */
 	public Object clone() {		
         if (getValue() == null) {
-            return new DeclareStatement((ElementSymbol)this.getVariable().clone(), this.varType);
+            return new DeclareStatement(this.getVariable().clone(), this.varType);
         }
-        return new DeclareStatement((ElementSymbol)this.getVariable().clone(), this.varType, (Expression)getValue().clone());
+        return new DeclareStatement(this.getVariable().clone(), this.varType, (Expression)getValue().clone());
 	}
 	
     /**

Added: trunk/engine/src/main/java/org/teiid/query/sql/proc/ExceptionExpression.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/ExceptionExpression.java	                        (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/ExceptionExpression.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -0,0 +1,146 @@
+/*
+ * 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 org.teiid.query.sql.proc;
+
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.core.util.HashCodeUtil;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+
+public class ExceptionExpression implements Expression, LanguageObject {
+	
+	private Expression message;
+	private Expression sqlState;
+	private Expression errorCode;
+	private Expression parent;
+	private boolean warning;
+	
+	@Override
+	public Class<?> getType() {
+		return DataTypeManager.DefaultDataClasses.OBJECT;
+	}
+	
+	public ExceptionExpression() {
+	}
+	
+	@Override
+	public boolean equals(Object obj) {
+		if (obj == this) {
+			return true;
+		}
+		if (!(obj instanceof ExceptionExpression)) {
+			return false;
+		}
+		ExceptionExpression other = (ExceptionExpression)obj;
+		return EquivalenceUtil.areEqual(message, other.message) 
+		&& EquivalenceUtil.areEqual(sqlState, other.sqlState)
+		&& EquivalenceUtil.areEqual(errorCode, other.errorCode)
+		&& EquivalenceUtil.areEqual(parent, other.parent)
+		&& warning == other.warning;
+	}
+	
+	@Override
+	public int hashCode() {
+		return HashCodeUtil.hashCode(warning?0:1, message, sqlState, errorCode);
+	}
+	
+	@Override
+	public String toString() {
+		return SQLStringVisitor.getSQLString(this);
+	}
+	
+	@Override
+	public ExceptionExpression clone() {
+		ExceptionExpression clone = new ExceptionExpression();
+		clone.warning = this.warning;
+		if (this.message != null) {
+			clone.message = (Expression) this.message.clone();
+		}
+		if (this.sqlState != null) {
+			clone.sqlState = (Expression) this.sqlState.clone();
+		}
+		if (this.errorCode != null) {
+			clone.errorCode = (Expression) this.errorCode.clone();
+		}
+		if (this.parent != null) {
+			clone.parent = (Expression) this.parent.clone();
+		}
+		return clone;
+	}
+	
+	public Expression getErrorCode() {
+		return errorCode;
+	}
+	
+	public void setErrorCode(Expression errCode) {
+		this.errorCode = errCode;
+	}
+	
+	public Expression getSqlState() {
+		return sqlState;
+	}
+	
+	public void setSqlState(Expression sqlState) {
+		this.sqlState = sqlState;
+	}
+	
+	public Expression getMessage() {
+		return message;
+	}
+	
+	public void setMessage(Expression message) {
+		this.message = message;
+	}
+	
+	public Expression getParent() {
+		return parent;
+	}
+	
+	public void setParent(Expression parent) {
+		this.parent = parent;
+	}
+	
+	public boolean isWarning() {
+		return warning;
+	}
+	
+	public void setWarning(boolean warning) {
+		this.warning = warning;
+	}
+
+	@Override
+	public void acceptVisitor(LanguageVisitor visitor) {
+		visitor.visit(this);
+	}
+
+	public String getDefaultSQLState() {
+		if (isWarning()) {
+			return "01000";
+		}
+		return "50001";
+	}
+
+}


Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/proc/ExceptionExpression.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Deleted: trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -1,102 +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 org.teiid.query.sql.proc;
-
-import org.teiid.core.types.DataTypeManager;
-import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.symbol.Expression;
-
-
-/**
- * <p> This class represents a error assignment statement in the storedprocedure language.
- * It extends the <code>Statement</code> that could part of a <code>Block</code>.  This
- * this object holds and error message.</p>
- */
-public class RaiseErrorStatement extends Statement implements ExpressionStatement {
-	
-	private Expression expression;
-
-	/**
-	 * Constructor for RaiseErrorStatement.
-	 */
-	public RaiseErrorStatement() {
-		super();
-	}
-	
-	/**
-	 * Constructor for RaiseErrorStatement.
-	 * @param message The error message
-	 */
-	public RaiseErrorStatement(Expression message) {
-		expression = message;
-	}
-        
-    public void acceptVisitor(LanguageVisitor visitor) {
-        visitor.visit(this);
-    }
-    
-    public Expression getExpression() {
-		return expression;
-	}
-    
-    public void setExpression(Expression expression) {
-		this.expression = expression;
-	}
-    
-    /** 
-     * @see org.teiid.query.sql.proc.AssignmentStatement#getType()
-     */
-    public int getType() {
-        return TYPE_ERROR;
-    }
-
-	@Override
-	public RaiseErrorStatement clone() {
-		return new RaiseErrorStatement((Expression) this.expression.clone());
-	}
-	
-	@Override
-	public int hashCode() {
-		return expression.hashCode();
-	}
-	
-	public boolean equals(Object obj) {
-		if (obj == this) {
-			return true;
-		}
-		
-		if (!(obj instanceof RaiseErrorStatement)) {
-			return false;
-		}
-		
-		RaiseErrorStatement other = (RaiseErrorStatement)obj;
-		
-		return other.expression.equals(this.expression);
-	}
-	
-	@Override
-	public Class<?> getExpectedType() {
-		return DataTypeManager.DefaultDataClasses.STRING;
-	}
-    
-} // END CLASS
\ No newline at end of file

Copied: trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseStatement.java (from rev 4461, trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java)
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseStatement.java	                        (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseStatement.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -0,0 +1,95 @@
+/*
+ * 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 org.teiid.query.sql.proc;
+
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.symbol.Expression;
+
+
+/**
+ * <p> This class represents a error assignment statement in the storedprocedure language.
+ * It extends the <code>Statement</code> that could part of a <code>Block</code>.  This
+ * this object holds and error message.</p>
+ */
+public class RaiseStatement extends Statement implements ExpressionStatement {
+	
+	private Expression expression;
+
+	public RaiseStatement() {
+	}
+	
+	/**
+	 * Constructor for RaiseErrorStatement.
+	 * @param message The error message
+	 */
+	public RaiseStatement(Expression message) {
+		expression = message;
+	}
+        
+    public void acceptVisitor(LanguageVisitor visitor) {
+        visitor.visit(this);
+    }
+    
+    public Expression getExpression() {
+		return expression;
+	}
+    
+    public void setExpression(Expression expression) {
+		this.expression = expression;
+	}
+    
+    public int getType() {
+        return TYPE_ERROR;
+    }
+
+	@Override
+	public RaiseStatement clone() {
+		return new RaiseStatement((Expression) this.expression.clone());
+	}
+	
+	@Override
+	public int hashCode() {
+		return expression.hashCode();
+	}
+	
+	public boolean equals(Object obj) {
+		if (obj == this) {
+			return true;
+		}
+		
+		if (!(obj instanceof RaiseStatement)) {
+			return false;
+		}
+		
+		RaiseStatement other = (RaiseStatement)obj;
+		
+		return other.expression.equals(this.expression);
+	}
+	
+	@Override
+	public Class<?> getExpectedType() {
+		return DataTypeManager.DefaultDataClasses.OBJECT;
+	}
+    
+} // END CLASS
\ No newline at end of file

Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -39,6 +39,7 @@
 import org.teiid.query.sql.navigator.PreOrPostOrderNavigator;
 import org.teiid.query.sql.navigator.PreOrderNavigator;
 import org.teiid.query.sql.proc.AssignmentStatement;
+import org.teiid.query.sql.proc.ExceptionExpression;
 import org.teiid.query.sql.symbol.*;
 
 
@@ -445,4 +446,20 @@
     	}
     }
     
+    @Override
+    public void visit(ExceptionExpression exceptionExpression) {
+    	if (exceptionExpression.getMessage() != null) {
+    		exceptionExpression.setMessage(replaceExpression(exceptionExpression.getMessage()));
+    	}
+    	if (exceptionExpression.getSqlState() != null) {
+    		exceptionExpression.setSqlState(replaceExpression(exceptionExpression.getSqlState()));
+    	}
+    	if (exceptionExpression.getErrorCode() != null) {
+    		exceptionExpression.setErrorCode(replaceExpression(exceptionExpression.getErrorCode()));
+    	}
+    	if (exceptionExpression.getParent() != null) {
+    		exceptionExpression.setParent(replaceExpression(exceptionExpression.getParent()));
+    	}
+    }
+    
 }

Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -1461,12 +1461,40 @@
         createAssignment(obj);
     }
 
-    public void visit( RaiseErrorStatement obj ) {
-        append(ERROR);
+    public void visit( RaiseStatement obj ) {
+        append(NonReserved.RAISE);
         append(SPACE);
         visitNode(obj.getExpression());
         append(";"); //$NON-NLS-1$
     }
+    
+    @Override
+    public void visit(ExceptionExpression exceptionExpression) {
+    	if (exceptionExpression.isWarning()) {
+    		append(SQLWARNING);
+    	} else {
+    		append(SQLEXCEPTION);
+    	}
+    	append(SPACE);
+    	visitNode(exceptionExpression.getMessage());
+    	if (exceptionExpression.getSqlState() != null) {
+    		append(SPACE);
+    		append(SQLSTATE);
+    		append(SPACE);
+    		append(exceptionExpression.getSqlState());
+    		if (exceptionExpression.getErrorCode() != null) {
+    			append(Tokens.COMMA);
+    			append(SPACE);
+    			append(exceptionExpression.getErrorCode());
+    		}
+    	}
+    	if (exceptionExpression.getParent() != null) {
+        	append(SPACE);
+        	append(NonReserved.EXCEPTION);
+        	append(SPACE);
+        	append(exceptionExpression.getParent());
+    	}
+    }
 
     public void visit( BranchingStatement obj ) {
     	switch (obj.getMode()) {

Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj	2012-09-24 15:36:49 UTC (rev 4466)
@@ -455,6 +455,8 @@
 |   <EXCLUDING: "excluding">
 |   <XMLDECLARATION: "xmldeclaration">
 |   <VARIADIC: "variadic">
+|   <EXCEPTION: "exception">
+|   <RAISE: "raise">
 
 }
 /*
@@ -562,7 +564,7 @@
      |<TO_BYTES>|<TIMESTAMPADD>|<TIMESTAMPDIFF>|<QUERYSTRING>|<NAMESPACE>|<RESULT>|<INDEX>|<ACCESSPATTERN>|<AUTO_INCREMENT>|<WELLFORMED>|<SQL_TSI_FRAC_SECOND>
      |<SQL_TSI_SECOND>|<SQL_TSI_MINUTE>|<SQL_TSI_HOUR>|<SQL_TSI_DAY>|<SQL_TSI_WEEK>|<SQL_TSI_MONTH>|<SQL_TSI_QUARTER>|<SQL_TSI_YEAR>|<TEXTTABLE>|<ARRAYTABLE>
      |<SELECTOR>|<SKIP_KEYWORD>|<WIDTH>|<PASSING>|<NAME>|<ENCODING>|<COLUMNS>|<DELIMITER>|<QUOTE>|<HEADER>|<NULLS>|<OBJECTTABLE>
-     |<VERSION>|<INCLUDING>|<EXCLUDING>|<XMLDECLARATION>|<VARIADIC>)
+     |<VERSION>|<INCLUDING>|<EXCLUDING>|<XMLDECLARATION>|<VARIADIC>|<RAISE>|<EXCEPTION>)
     {
     	return getToken(0);
     }	
@@ -760,7 +762,7 @@
       sourceHint = getSourceHint(t); 
     }
 	(command = queryExpression(info) |
-	command = storedProcedure(info, new StoredProcedure()) |
+	command = storedProcedure(info, 1) |
 	command = insert(info) |
 	command = update(info) |
 	command = delete(info) |
@@ -885,7 +887,7 @@
 description=Raises an error with the given message.
 example={code:sql}ERROR 'something went wrong'{code}
 */
-RaiseErrorStatement errorStatement(ParseInfo info) :
+RaiseStatement errorStatement(ParseInfo info) :
 {
     Expression errMsg = null;           
 }
@@ -894,12 +896,80 @@
     errMsg = expression(info)           
         
     {
-        RaiseErrorStatement errStmt = new RaiseErrorStatement(errMsg);       
-        return errStmt; 
+        ExceptionExpression ee = new ExceptionExpression();
+        ee.setMessage(errMsg);
+        return new RaiseStatement(ee);       
     }
 }
 
 /*
+name=raise statement
+description=Raises an error or warning with the given message.
+example={code:sql}RAISE SQLEXCEPTION '00A' 'something went wrong'{code}
+*/
+RaiseStatement raiseStatement(ParseInfo info) :
+{
+    Expression err = null;
+}
+{ 
+    <RAISE>
+    err = exceptionReference(info)
+    {
+        return new RaiseStatement(err);       
+    }
+}
+
+/*
+name=exception reference
+description=a reference to an exception
+example={code:sql}SQLEXCEPTION 'something went wrong' SQLSTATE '00X', 2{code}
+*/
+Expression exceptionReference(ParseInfo info) :
+{
+	String id = null;
+	Expression ex;
+}
+{
+	id = id() {return new ElementSymbol(id);}
+	|
+	ex = exception(info)
+	{
+		return ex;
+	}
+}
+
+/*
+name=sql exception
+description=creates a sql exception or warning with the specified message, state, and code
+example={code:sql}SQLEXCEPTION 'something went wrong' SQLSTATE '00X', 2{code}
+*/
+Expression exception(ParseInfo info) :
+{
+	Expression err = null;
+	Expression sqlState = null;
+	Expression errCode = null;
+	Expression parent = null;
+	boolean warning = false;
+}
+{
+    (<SQLWARNING> {warning=true;}|<SQLEXCEPTION>)
+	err = commonValueExpression(info)
+	[<SQLSTATE> sqlState = commonValueExpression(info)
+     [<COMMA> errCode = commonValueExpression(info)]
+    ]
+    [<EXCEPTION> parent = exceptionReference(info)]
+	{
+		ExceptionExpression ee = new ExceptionExpression();
+		ee.setMessage(err);
+		ee.setSqlState(sqlState);
+		ee.setErrorCode(errCode);
+		ee.setParent(parent);
+		ee.setWarning(warning);
+		return ee;
+	}	
+}
+
+/*
 name=statement
 description=A procedure statement.
 example={code:sql}IF (x = 5) BEGIN ... END{code}
@@ -943,9 +1013,10 @@
     Statement stmt = null;
 }           
 {
-     (LOOKAHEAD(3) stmt = assignStatement(info) |
+     (stmt = assignStatement(info) |
 	  stmt = sqlStatement(info) |
       stmt = errorStatement(info) |
+      stmt = raiseStatement(info) |
 	  stmt = declareStatement(info) |
 	  stmt = branchingStatement(info)
 	 )
@@ -1101,7 +1172,7 @@
 }
 {
     <DECLARE>
-    type = parseDataType()
+    (type = parseDataType() | <EXCEPTION> {type = new ParsedDataType(getToken(0).image);})
     var = id()
     {
         variableID = new ElementSymbol(var);
@@ -1126,19 +1197,28 @@
 description=Assigns a variable a value in a procedure.
 example={code:sql}x := 'b'{code}
 */
-AssignmentStatement assignStatement(ParseInfo info) :
+Statement assignStatement(ParseInfo info) :
 {
     LanguageObject value = null;
-    String var = null;
+    Token var = null;
     ElementSymbol elementID = null;
 }
 {
-    var = id()
+    var = <ID>
     {
-        elementID = new ElementSymbol(var);              
+        elementID = new ElementSymbol(normalizeId(var.image));              
     } 
     [<COLON>]<EQ>
-    value = assignStatementOperand(info)
+    (value = assignStatementOperand(info) |
+     value = storedProcedure(info, 2) {
+		StoredProcedure storedProcedure = (StoredProcedure)value;
+	    SPParameter parameter = new SPParameter(1, SPParameter.RETURN_VALUE, "return"); //$NON-NLS-1$
+	    parameter.setExpression(elementID);
+		storedProcedure.setParameter(parameter);  
+		storedProcedure.setCalledWithReturn(true);            
+		return new CommandStatement(storedProcedure);      	    
+     }
+    )
         
     {   
     	if (value instanceof Expression) {
@@ -1160,15 +1240,14 @@
     LanguageObject value = null;
 }
 {
-
     (
 	  LOOKAHEAD(<INSERT><INTO>) (value = insert(info)) | //deprecated
       value = update(info) | //deprecated
       value = delete(info) | //deprecated
-      LOOKAHEAD(expression(info)) (value = expression(info)) |      
-      value = queryExpression(info) //deprecated should be a scalar subquery
+      LOOKAHEAD(1) value = expression(info) |      
+      value = queryExpression(info) | //deprecated should be a scalar subquery
+      value = exception(info)
     ) 
-        
     {   
         return value;
     }    
@@ -1180,33 +1259,18 @@
 */
 CommandStatement sqlStatement(ParseInfo info) :
 {
-    CommandStatement cmdStmt = null;
     Command cmd = null;
     String var = null;
     ElementSymbol elementID = null;
     StoredProcedure storedProcedure = null;
 }
 {
-    (LOOKAHEAD(2) (cmd = userCommand(info)) |
-     cmd = dynamicCommand(info) |
-     (
-      var = id()
-      {
-        storedProcedure = new StoredProcedure();
-        elementID = new ElementSymbol(var);
-        SPParameter parameter = new SPParameter(1, SPParameter.RETURN_VALUE, "return"); //$NON-NLS-1$
-        parameter.setExpression(elementID);
-	    storedProcedure.setParameter(parameter);  
-	    storedProcedure.setCalledWithReturn(true);            
-      } 
-     [<COLON>]<EQ>
-      cmd = storedProcedure(info, storedProcedure) 
-     )
+    (LOOKAHEAD(2) cmd = userCommand(info) |
+     cmd = dynamicCommand(info)
     )
   
     {
-    	cmdStmt = new CommandStatement(cmd);
-        return cmdStmt;
+    	return new CommandStatement(cmd);
     }   
 }
  
@@ -1409,7 +1473,7 @@
 	//parameters
 		
 	[<LPAREN>
-	 [values = expressionList(info) { convertToParameters(values, storedProcedure); }]
+	 [values = expressionList(info) { convertToParameters(values, storedProcedure, parameterIndex); }]
 	 <RPAREN>
 	]
 	<RBRACE>			
@@ -1429,11 +1493,12 @@
 description=Executes the procedure with the given parameters.
 example={code:sql}CALL proc('a', 1){code}
 */
-StoredProcedure storedProcedure(ParseInfo info, StoredProcedure storedProcedure) :
+StoredProcedure storedProcedure(ParseInfo info, int startIndex) :
 {
 	String procName = null;
 	Option option = null;
 	List<Expression> values = null;
+	StoredProcedure storedProcedure = new StoredProcedure();
 }
 {
 	(
@@ -1448,9 +1513,9 @@
 		
 		(
 		 LOOKAHEAD(2)
-		 executeNamedParams(info, storedProcedure)
+		 executeNamedParams(info, storedProcedure, startIndex)
 		 | 		
-		 [values = expressionList(info) { convertToParameters(values, storedProcedure); }]
+		 [values = expressionList(info) { convertToParameters(values, storedProcedure, startIndex); }]
 		)
 		
 		<RPAREN>
@@ -1470,12 +1535,11 @@
 description=A list of named parameters.
 example={code:sql}param1 => 'x', param2 => 1{code}
 */
-void executeNamedParams(ParseInfo info, StoredProcedure storedProcedure) :
+void executeNamedParams(ParseInfo info, StoredProcedure storedProcedure, int parameterIndex) :
 {
 	String name = null;
     Expression value = null;
 	SPParameter parameter = null;
-	int parameterIndex = 1;
 }
 {
 	{
@@ -2788,7 +2852,7 @@
 	]
 	lparen = <LPAREN> 
 	( command = queryExpression(info) |
-      command = storedProcedure(info, new StoredProcedure()) )
+      command = storedProcedure(info, 1) )
 	<RPAREN>
 	[<AS>]
 	aliasID = id()
@@ -3033,7 +3097,7 @@
 	<LPAREN>
 	( subquery = queryExpression(info) | 
 	 (
-		proc = storedProcedure(info, new StoredProcedure()) //deprecated	  
+		proc = storedProcedure(info, 1) //deprecated	  
 	 )
 	 {
 	    subquery = new Query(new Select(Arrays.asList(new MultipleElementSymbol())), new From(Arrays.asList(new SubqueryFromClause("x", proc))), null, null, null);

Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties	2012-09-24 15:36:49 UTC (rev 4466)
@@ -1032,6 +1032,7 @@
 TEIID31114=Function based index {1} expression {0} cannot contain subqueries.
 TEIID31115=Function based index {1} expression {0} is not deterministic.
 TEIID31116=Function based index {1} expression {0} could not be resolved: {2}
+TEIID31120=An exception may only be chained to another exception. {0} is not valid.
 
 SQLParser.proc_type_conflict=Result type {1} conflicts with return type {2} for procedure {0}
 SQLParser.param_out=Procedure {0} RESULT param {1} must be of type OUT.

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -119,21 +119,6 @@
         addRequest(rm, r0, requestID, null, null);  
     }
     
-    public void testWarnings1() {
-        DQPCore rm = new DQPCore();
-        rm.setTransactionService(new FakeTransactionService());
-        RequestMessage r0 = new RequestMessage("foo"); //$NON-NLS-1$
-        RequestID requestID = new RequestID(SESSION_STRING, 1);
-
-        RequestWorkItem workItem = addRequest(rm, r0, requestID, null, null);
-                
-        workItem.addSourceFailureDetails(getSourceFailures("Model1", "Binding1", "Warning1")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        workItem.addSourceFailureDetails(getSourceFailures("Model2", "Binding2", "Warning2")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        workItem.addSourceFailureDetails(getSourceFailures("Model3", "Binding3", "Warning3")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-        
-        assertEquals(3, workItem.getWarnings().size());
-    }
-    
     static RequestWorkItem addRequest(DQPCore rm, 
                     RequestMessage requestMsg,
                     RequestID id,

Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -124,6 +124,7 @@
         AtomicRequestMessage request = new AtomicRequestMessage(original, workContext, nodeId);
         request.setCommand(command);
         request.setConnectorName("FakeConnectorID"); //$NON-NLS-1$
+        request.setCommandContext(context);
         return request;
 	}
 
@@ -187,8 +188,9 @@
     	assertEquals(10, pullTuples(info, 10));
         assertNotNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
         assertNull(info.nextTuple());
-        assertEquals(1, workItem.getWarnings().size());
-        SourceWarning warning = (SourceWarning) workItem.getWarnings().get(0);
+        List<Exception> warnings = context.getAndClearWarnings();
+		assertEquals(1, warnings.size());
+        SourceWarning warning = (SourceWarning) warnings.get(0);
 		assertFalse(warning.isPartialResultsError());
         info.closeSource();
         assertNull(workItem.getConnectorRequest(info.getAtomicRequestMessage().getAtomicRequestID()));
@@ -229,7 +231,7 @@
     	for (int i = 0; i < 10; i++) {
 	    	try {
 	    		assertNull(info.nextTuple());
-	    		SourceWarning warning = (SourceWarning) workItem.getWarnings().get(0);
+	    		SourceWarning warning = (SourceWarning) context.getAndClearWarnings().get(0);
 	    		assertTrue(warning.isPartialResultsError());
 	    		return;
 	    	} catch (BlockedException e) {

Modified: trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/test/java/org/teiid/query/metadata/TestDDLStringVisitor.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -29,12 +29,12 @@
 import java.util.Properties;
 
 import org.junit.Test;
+import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.metadata.Column;
 import org.teiid.metadata.MetadataFactory;
 import org.teiid.metadata.Schema;
 import org.teiid.metadata.Table;
 import org.teiid.metadata.BaseColumn.NullType;
-import org.teiid.query.parser.ParseException;
 import org.teiid.query.parser.TestDDLParser;
 
 @SuppressWarnings("nls")
@@ -243,7 +243,7 @@
 		helpTest(ddl, expected);
 	}
 
-	private void helpTest(String ddl, String expected) throws ParseException {
+	private void helpTest(String ddl, String expected) throws QueryParserException {
 		Schema s = TestDDLParser.helpParse(ddl, "model").getSchema();
 		String metadataDDL = DDLStringVisitor.getDDLString(s, null, null);
 		assertEquals(expected, metadataDDL);

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestDDLParser.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -29,6 +29,7 @@
 import org.junit.Test;
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
+import org.teiid.api.exception.query.QueryParserException;
 import org.teiid.metadata.*;
 import org.teiid.metadata.BaseColumn.NullType;
 import org.teiid.query.metadata.MetadataValidator;
@@ -116,7 +117,7 @@
 		assertEquals("hello", e6.getDefaultValue());
 	}
 	
-	@Test(expected=ParseException.class)
+	@Test(expected=QueryParserException.class)
 	public void testDuplicatePrimarykey() throws Exception {
 		String ddl = "CREATE FOREIGN TABLE G1( e1 integer primary key, e2 varchar primary key)";
 		MetadataStore mds = new MetadataStore();
@@ -214,7 +215,7 @@
 		assertEquals(table.getColumns().subList(1, 3), table.getAccessPatterns().get(1).getColumns());
 	}	
 	
-	@Test(expected=ParseException.class)
+	@Test(expected=QueryParserException.class)
 	public void testWrongPrimarykey() throws Exception {
 		String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, PRIMARY KEY (e3))";
 
@@ -339,7 +340,7 @@
 		assertEquals(fk.getPrimaryKey().getColumns(), s.getSchema("model").getTable("G1").getColumns());
 	}	
 	
-	@Test(expected=ParseException.class)
+	@Test(expected=QueryParserException.class)
 	public void testTableWithPlan() throws Exception {
 		String ddl = "CREATE foreign table G1 as select 1";
 		MetadataStore mds = new MetadataStore();
@@ -513,7 +514,7 @@
 		assertEquals("boolean", fm.getInputParameters().get(0).getType());
 	}
 	
-	@Test(expected=ParseException.class) public void testInvalidFunctionBody() throws Exception {
+	@Test(expected=QueryParserException.class) public void testInvalidFunctionBody() throws Exception {
 		String ddl = "CREATE FUNCTION SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";
 
 		Schema s = helpParse(ddl, "model").getSchema();
@@ -522,7 +523,7 @@
 		assertTrue( fm.getInputParameters().get(0).isVarArg());
 	}
 	
-	@Test(expected=ParseException.class) public void testInvalidProcedureBody() throws Exception {
+	@Test(expected=QueryParserException.class) public void testInvalidProcedureBody() throws Exception {
 		String ddl = "CREATE FOREIGN PROCEDURE SourceFunc(flag boolean) RETURNS varchar AS SELECT 'a';";
 
 		Schema s = helpParse(ddl, "model").getSchema();
@@ -650,7 +651,7 @@
 		assertEquals("http://teiid.org", mf.getNamespaces().get("teiid"));
 	}		
 
-	public static MetadataFactory helpParse(String ddl, String model) throws ParseException {
+	public static MetadataFactory helpParse(String ddl, String model) throws QueryParserException {
 		MetadataFactory mf = new MetadataFactory(null, 1, model, getDataTypes(), new Properties(), null); 
 		QueryParser.getQueryParser().parseDDL(mf, ddl);
 		return mf;

Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -3010,12 +3010,26 @@
     }    
     
     @Test public void testErrorStatement() throws Exception {
-        RaiseErrorStatement errStmt = new RaiseErrorStatement(new Constant("Test only")); //$NON-NLS-1$
+    	ExceptionExpression ee = new ExceptionExpression();
+    	ee.setMessage(new Constant("Test only"));
+        RaiseStatement errStmt = new RaiseStatement(ee);
                  
-        helpStmtTest("ERROR 'Test only';", "ERROR 'Test only';", //$NON-NLS-1$ //$NON-NLS-2$
+        helpStmtTest("ERROR 'Test only';", "RAISE SQLEXCEPTION 'Test only';", //$NON-NLS-1$ //$NON-NLS-2$
             errStmt);           
     }
     
+    @Test public void testRaiseErrorStatement() throws Exception {
+    	ExceptionExpression ee = new ExceptionExpression();
+    	ee.setMessage(new Constant("Test only"));
+    	ee.setWarning(true);
+    	ee.setSqlState(new Constant("100"));
+    	ee.setParent(new ElementSymbol("e"));
+        RaiseStatement errStmt = new RaiseStatement(ee);
+                 
+        helpStmtTest("RAISE SQLWARNING 'Test only' SQLSTATE '100' EXCEPTION e;", "RAISE SQLWARNING 'Test only' SQLSTATE '100' EXCEPTION e;", //$NON-NLS-1$ //$NON-NLS-2$
+            errStmt);           
+    }
+    
     @Test public void testIfStatement() throws Exception {
         ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$
         String shortType = new String("short"); //$NON-NLS-1$

Added: trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcErrors.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcErrors.java	                        (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcErrors.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -0,0 +1,78 @@
+/*
+ * 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 org.teiid.query.processor.proc;
+
+import static org.junit.Assert.*;
+import static org.teiid.query.processor.proc.TestProcedureProcessor.*;
+
+import org.junit.Test;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.jdbc.TeiidSQLException;
+import org.teiid.jdbc.TeiidSQLWarning;
+import org.teiid.query.metadata.TransformationMetadata;
+import org.teiid.query.processor.HardcodedDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.resolver.TestProcedureResolving;
+
+ at SuppressWarnings("nls")
+public class TestProcErrors {
+	
+    @Test public void testInvalidException() throws Exception {
+    	String ddl = 
+    			"create virtual procedure vproc (x integer) returns integer as begin declare object e = sqlwarning 'hello'; raise e; raise sqlexception 'hello world' sqlstate 'abc', 1 exception e; end;";
+    	try {
+    		TestProcedureResolving.createMetadata(ddl);
+    		fail();
+    	} catch (RuntimeException e) {
+    		assertEquals("TEIID31080 View test.vproc validation error: QueryResolverException-TEIID31120 An exception may only be chained to another exception. e is not valid.", e.getMessage());
+    	}
+    }
+
+    @Test public void testExceptionAndWarning() throws Exception {
+    	String ddl = 
+    			"create virtual procedure vproc (x integer) returns integer as begin declare exception e = sqlwarning 'hello'; raise e; raise sqlexception 'hello world' sqlstate 'abc', 1 exception e; end;";
+    	TransformationMetadata tm = TestProcedureResolving.createMetadata(ddl);    	
+
+    	String sql = "call vproc(1)"; //$NON-NLS-1$
+
+        ProcessorPlan plan = getProcedurePlan(sql, tm);
+
+        HardcodedDataManager dataManager = new HardcodedDataManager(tm);
+        
+        try {
+        	helpTestProcess(plan, null, dataManager, tm);
+        	fail();
+        } catch (TeiidProcessingException e) {
+            TeiidSQLWarning tsw = (TeiidSQLWarning) plan.getContext().getAndClearWarnings().get(0);
+        	assertEquals("hello", tsw.getMessage());
+        	
+        	assertEquals(e.getCause().getCause(), tsw);
+        	TeiidSQLException tse = (TeiidSQLException)e.getCause();
+        	assertEquals("hello world", tse.getMessage());
+        	assertEquals("abc", tse.getSQLState());
+        	assertEquals(1, tse.getErrorCode());
+        }
+        
+    }
+	
+}


Property changes on: trunk/engine/src/test/java/org/teiid/query/processor/proc/TestProcErrors.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestRaiseErrorStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestRaiseErrorStatement.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestRaiseErrorStatement.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -23,7 +23,7 @@
 package org.teiid.query.sql.proc;
 
 import org.teiid.core.util.UnitTestUtil;
-import org.teiid.query.sql.proc.RaiseErrorStatement;
+import org.teiid.query.sql.proc.RaiseStatement;
 import org.teiid.query.sql.symbol.Constant;
 
 import junit.framework.*;
@@ -43,32 +43,32 @@
 	
 	// ################################## TEST HELPERS ################################	
 
-	public static final RaiseErrorStatement sample1() { 
-		return new RaiseErrorStatement(new Constant("a")); //$NON-NLS-1$
+	public static final RaiseStatement sample1() { 
+		return new RaiseStatement(new Constant("a")); //$NON-NLS-1$
 	}
 	
-	public static final RaiseErrorStatement sample2() {
-		return new RaiseErrorStatement(new Constant("b")); //$NON-NLS-1$
+	public static final RaiseStatement sample2() {
+		return new RaiseStatement(new Constant("b")); //$NON-NLS-1$
 	}
 	
 	// ################################## ACTUAL TESTS ################################	
 	
 	public void testSelfEquivalence(){
-		RaiseErrorStatement s1 = sample1();
+		RaiseStatement s1 = sample1();
 		int equals = 0;
 		UnitTestUtil.helpTestEquivalence(equals, s1, s1);
 	}
 
 	public void testEquivalence(){
-		RaiseErrorStatement s1 = sample1();
-		RaiseErrorStatement s1a = sample1();
+		RaiseStatement s1 = sample1();
+		RaiseStatement s1a = sample1();
 		int equals = 0;
 		UnitTestUtil.helpTestEquivalence(equals, s1, s1a);
 	}
 	
 	public void testNonEquivalence(){
-		RaiseErrorStatement s1 = sample1();
-		RaiseErrorStatement s2 = sample2();
+		RaiseStatement s1 = sample1();
+		RaiseStatement s2 = sample2();
 		int equals = -1;
 		UnitTestUtil.helpTestEquivalence(equals, s1, s2);
 	}

Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -44,7 +44,7 @@
 import org.teiid.query.sql.proc.CommandStatement;
 import org.teiid.query.sql.proc.CreateProcedureCommand;
 import org.teiid.query.sql.proc.DeclareStatement;
-import org.teiid.query.sql.proc.RaiseErrorStatement;
+import org.teiid.query.sql.proc.RaiseStatement;
 import org.teiid.query.sql.symbol.*;
 import org.teiid.query.unittest.RealMetadataFactory;
 import org.teiid.translator.TypeFacility;
@@ -1341,13 +1341,13 @@
     }
 
     @Test public void testRaiseErrorStatement() {
-    	RaiseErrorStatement errStmt =	new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
-		helpTest(errStmt, "ERROR 'My Error';"); //$NON-NLS-1$
+    	RaiseStatement errStmt =	new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$
+		helpTest(errStmt, "RAISE 'My Error';"); //$NON-NLS-1$
     }  
     
     @Test public void testRaiseErrorStatementWithExpression() {
-        RaiseErrorStatement errStmt =   new RaiseErrorStatement(new ElementSymbol("a")); //$NON-NLS-1$
-        helpTest(errStmt, "ERROR a;"); //$NON-NLS-1$
+        RaiseStatement errStmt =   new RaiseStatement(new ElementSymbol("a")); //$NON-NLS-1$
+        helpTest(errStmt, "RAISE a;"); //$NON-NLS-1$
     }
     
     @Test public void testAssignmentStatement1() {
@@ -1393,12 +1393,12 @@
         d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
     	CommandStatement cmdStmt =	new CommandStatement(d1);
     	AssignmentStatement assigStmt =	new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$
-    	RaiseErrorStatement errStmt =	new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
+    	RaiseStatement errStmt =	new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$
     	Block b = new Block();
     	b.addStatement(cmdStmt);
     	b.addStatement(assigStmt);
     	b.addStatement(errStmt);
-		helpTest(b, "BEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND"); //$NON-NLS-1$
+		helpTest(b, "BEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND"); //$NON-NLS-1$
     }
     
     @Test public void testCreateUpdateProcedure1() {
@@ -1406,13 +1406,13 @@
         d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
     	CommandStatement cmdStmt =	new CommandStatement(d1);
     	AssignmentStatement assigStmt =	new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$
-    	RaiseErrorStatement errStmt =	new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
+    	RaiseStatement errStmt =	new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$
     	Block b = new Block();
     	b.addStatement(cmdStmt);
     	b.addStatement(assigStmt);
     	b.addStatement(errStmt);
 	    CreateProcedureCommand cup = new CreateProcedureCommand(b);
-		helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND");	     //$NON-NLS-1$
+		helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND");	     //$NON-NLS-1$
     }
     
     @Test public void testCreateUpdateProcedure2() {
@@ -1420,13 +1420,13 @@
         d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
     	CommandStatement cmdStmt =	new CommandStatement(d1);
     	AssignmentStatement assigStmt =	new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$
-    	RaiseErrorStatement errStmt =	new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
+    	RaiseStatement errStmt =	new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$
     	Block b = new Block();
     	b.addStatement(cmdStmt);
     	b.addStatement(assigStmt);
     	b.addStatement(errStmt);
 	    CreateProcedureCommand cup = new CreateProcedureCommand(b);
-		helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND");	     //$NON-NLS-1$
+		helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND");	     //$NON-NLS-1$
     }
 
     @Test public void testCreateUpdateProcedure3() {
@@ -1434,13 +1434,13 @@
         d1.setGroup(new GroupSymbol("g")); //$NON-NLS-1$
     	CommandStatement cmdStmt =	new CommandStatement(d1);
     	AssignmentStatement assigStmt =	new AssignmentStatement(new ElementSymbol("a"), new Constant(new Integer(1))); //$NON-NLS-1$
-    	RaiseErrorStatement errStmt =	new RaiseErrorStatement(new Constant("My Error")); //$NON-NLS-1$
+    	RaiseStatement errStmt =	new RaiseStatement(new Constant("My Error")); //$NON-NLS-1$
     	Block b = new Block();
     	b.addStatement(cmdStmt);
     	b.addStatement(assigStmt);
     	b.addStatement(errStmt);
 	    CreateProcedureCommand cup = new CreateProcedureCommand(b);
-		helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nERROR 'My Error';\nEND");	     //$NON-NLS-1$
+		helpTest(cup, "CREATE VIRTUAL PROCEDURE\nBEGIN\nDELETE FROM g;\na = 1;\nRAISE 'My Error';\nEND");	     //$NON-NLS-1$
     }
 
     @Test public void testSubqueryCompareCriteria1() {

Modified: trunk/jboss-integration/src/test/java/org/teiid/jboss/rest/TestRestWebArchiveBuilder.java
===================================================================
--- trunk/jboss-integration/src/test/java/org/teiid/jboss/rest/TestRestWebArchiveBuilder.java	2012-09-23 18:36:52 UTC (rev 4465)
+++ trunk/jboss-integration/src/test/java/org/teiid/jboss/rest/TestRestWebArchiveBuilder.java	2012-09-24 15:36:49 UTC (rev 4466)
@@ -21,28 +21,24 @@
  */
 package org.teiid.jboss.rest;
 
+import static org.junit.Assert.*;
+
 import java.io.ByteArrayInputStream;
 import java.io.FileInputStream;
 import java.util.ArrayList;
-import java.util.Map;
-import java.util.Properties;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
 import org.junit.Test;
-import static org.junit.Assert.*;
 import org.teiid.adminapi.impl.ModelMetaData;
 import org.teiid.adminapi.impl.VDBMetaData;
 import org.teiid.adminapi.impl.VDBMetadataParser;
 import org.teiid.core.util.UnitTestUtil;
-import org.teiid.metadata.Datatype;
 import org.teiid.metadata.MetadataFactory;
 import org.teiid.metadata.MetadataStore;
 import org.teiid.query.metadata.QueryMetadataInterface;
-import org.teiid.query.metadata.SystemMetadata;
 import org.teiid.query.metadata.TransformationMetadata;
-import org.teiid.query.parser.ParseException;
-import org.teiid.query.parser.QueryParser;
+import org.teiid.query.parser.TestDDLParser;
 import org.teiid.query.unittest.RealMetadataFactory;
 
 @SuppressWarnings("nls")
@@ -53,7 +49,7 @@
 		VDBMetaData vdb = VDBMetadataParser.unmarshell(new FileInputStream(UnitTestUtil.getTestDataFile("sample-vdb.xml")));
 		MetadataStore ms = new MetadataStore();
 		for (ModelMetaData model: vdb.getModelMetaDatas().values()) {
-			MetadataFactory mf = buildMetadataFactory(model.getSchemaText(), model.getName());
+			MetadataFactory mf = TestDDLParser.helpParse(model.getSchemaText(), model.getName());
 			ms.addSchema(mf.getSchema());
 		}
 		
@@ -80,14 +76,4 @@
 		}
 	}
 
-	
-	public MetadataFactory buildMetadataFactory(String ddl, String model) throws ParseException {
-		MetadataFactory mf = new MetadataFactory(null, 1, model, getDataTypes(), new Properties(), null); 
-		new QueryParser().parseDDL(mf, ddl);
-		return mf;
-	}
-	
-	static Map<String, Datatype> getDataTypes() {
-		return SystemMetadata.getInstance().getRuntimeTypeMap();
-	}
 }



More information about the teiid-commits mailing list