[teiid-commits] teiid SVN: r2753 - in trunk/engine/src: main/java/org/teiid/query/validator and 3 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Dec 3 12:14:37 EST 2010


Author: shawkins
Date: 2010-12-03 12:14:37 -0500 (Fri, 03 Dec 2010)
New Revision: 2753

Removed:
   trunk/engine/src/main/java/org/teiid/query/validator/ValidatorWarning.java
Modified:
   trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
   trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java
   trunk/engine/src/main/java/org/teiid/query/validator/ValidatorReport.java
   trunk/engine/src/main/resources/org/teiid/query/i18n.properties
   trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
   trunk/engine/src/test/java/org/teiid/query/validator/TestUpdateValidator.java
Log:
TEIID-1351 ensuring that validation is performed only based update type

Modified: trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java	2010-12-02 21:53:52 UTC (rev 2752)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/ProcedureContainerResolver.java	2010-12-03 17:14:37 UTC (rev 2753)
@@ -23,7 +23,6 @@
 package org.teiid.query.resolver;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -41,7 +40,6 @@
 import org.teiid.query.metadata.TempMetadataStore;
 import org.teiid.query.metadata.TempMetadataID.Type;
 import org.teiid.query.parser.QueryParser;
-import org.teiid.query.report.ReportItem;
 import org.teiid.query.resolver.command.UpdateProcedureResolver;
 import org.teiid.query.resolver.util.ResolverUtil;
 import org.teiid.query.sql.ProcedureReservedWords;
@@ -56,7 +54,6 @@
 import org.teiid.query.sql.symbol.ElementSymbol;
 import org.teiid.query.sql.symbol.GroupSymbol;
 import org.teiid.query.validator.UpdateValidator;
-import org.teiid.query.validator.ValidatorFailure;
 import org.teiid.query.validator.UpdateValidator.UpdateInfo;
 
 
@@ -236,7 +233,17 @@
 			throws TeiidComponentException, QueryMetadataException,
 			QueryResolverException {
 		if(!procCommand.getGroup().isTempGroupSymbol() && metadata.isVirtualGroup(procCommand.getGroup().getMetadataID())) {
-            return getPlan(metadata, procCommand.getGroup());
+            String plan = getPlan(metadata, procCommand.getGroup());
+            if (plan == null && !metadata.isProcedure(procCommand.getGroup().getMetadataID())) {
+            	UpdateInfo info = getUpdateInfo(procCommand.getGroup(), metadata);
+            	int type = procCommand.getType();
+        		if ((info.isDeleteValidationError() && type == Command.TYPE_DELETE) 
+        				|| (info.isUpdateValidationError() && type == Command.TYPE_UPDATE) 
+        				|| (info.isInsertValidationError() && type == Command.TYPE_INSERT)) {
+        			throw new QueryResolverException("ERR.015.008.0009", QueryPlugin.Util.getString("ERR.015.008.0009", procCommand.getGroup(), procCommand.getClass().getSimpleName())); //$NON-NLS-1$ //$NON-NLS-2$
+        		}
+            }
+            return plan;
         }
 		return null;
 	}
@@ -260,17 +267,8 @@
     				metadata.getInsertPlan(group.getMetadataID()) == null);
     		validator.validate(UpdateProcedureResolver.getQueryTransformCmd(group, metadata), elements);
     		info = validator.getUpdateInfo();
-    		for (ReportItem item : (Collection<ReportItem>)validator.getReport().getItems()) {
-				if (item instanceof ValidatorFailure) {
-					info.setValidationError(item.getMessage());
-					break;
-				}
-    		}
     		metadata.addToMetadataCache(group.getMetadataID(), "UpdateInfo", info); //$NON-NLS-1$
     	}
-    	if (info.getValidationError() != null) {
-    		throw new QueryResolverException(info.getValidationError());
-    	}
     	return info;
 	}
     

Modified: trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java	2010-12-02 21:53:52 UTC (rev 2752)
+++ trunk/engine/src/main/java/org/teiid/query/validator/UpdateValidator.java	2010-12-03 17:14:37 UTC (rev 2753)
@@ -83,10 +83,12 @@
 		private Map<String, UpdateMapping> updatableGroups = new HashMap<String, UpdateMapping>();
 		private boolean isSimple = true;
 		private UpdateMapping deleteTarget;
-		private String validationError;
 		private boolean inherentUpdate;
+		private boolean updateValidationError;
 		private boolean inherentDelete;
+		private boolean deleteValidationError;
 		private boolean inherentInsert;
+		private boolean insertValidationError;
 		private Query view;
 		
 		public boolean isSimple() {
@@ -101,14 +103,6 @@
 			return updatableGroups;
 		}
 		
-		public String getValidationError() {
-			return validationError;
-		}
-		
-		public void setValidationError(String validationError) {
-			this.validationError = validationError;
-		}
-		
 		public boolean isInherentDelete() {
 			return inherentDelete;
 		}
@@ -134,6 +128,18 @@
 			return view;
 		}
 		
+		public boolean isDeleteValidationError() {
+			return deleteValidationError;
+		}
+		
+		public boolean isInsertValidationError() {
+			return insertValidationError;
+		}
+		
+		public boolean isUpdateValidationError() {
+			return updateValidationError;
+		}
+		
 	}
 	
 	private QueryMetadataInterface metadata;
@@ -155,38 +161,45 @@
 		return report;
 	}
 	
+	private void handleValidationError(String error, boolean update, boolean insert, boolean delete) {
+		report.handleValidationError(error);
+		updateInfo.updateValidationError |= update;
+		updateInfo.insertValidationError |= insert;
+		updateInfo.deleteValidationError |= delete;
+	}
+	
     public void validate(Command command, List<ElementSymbol> viewSymbols) throws QueryMetadataException, TeiidComponentException {
     	if (!(command instanceof Query)) {
-    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001"), true, true, true); //$NON-NLS-1$
     		return;
         }
     	
     	Query query = (Query)command;
 
     	if (query.getFrom() == null || query.getInto() != null) {
-    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0001"), true, true, true); //$NON-NLS-1$
     		return;
     	}
     	
     	if (query.getWith() != null) {
-    		report.handleValidationWarning(QueryPlugin.Util.getString("ERR.015.012.0002")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0002"), true, true, true); //$NON-NLS-1$
     		updateInfo.isSimple = false;
     	}
 
     	if (query.hasAggregates()) {
-    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0006")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0006"), true, true, true); //$NON-NLS-1$
     		return;
     	}
     	
     	updateInfo.view = query;
     	
     	if (query.getLimit() != null) {
-    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0013")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0013"), true, true, true); //$NON-NLS-1$
     		return;
     	}
     	
     	if (query.getSelect().isDistinct()) {
-    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0008")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0008"), true, true, true); //$NON-NLS-1$
     		return;
     	} 
     	
@@ -221,12 +234,12 @@
             } else {
             	//TODO: look for reversable widening conversions
             	
-                report.handleValidationWarning(QueryPlugin.Util.getString("ERR.015.012.0007", viewSymbols.get(i), symbol)); //$NON-NLS-1$
+                report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0007", viewSymbols.get(i), symbol)); //$NON-NLS-1$
             }
     	}
     	
     	if (query.getFrom().getClauses().size() > 1 || (!(query.getFrom().getClauses().get(0) instanceof UnaryFromClause))) {
-    		report.handleValidationWarning(QueryPlugin.Util.getString("ERR.015.012.0009", query.getFrom())); //$NON-NLS-1$
+    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0009", query.getFrom())); //$NON-NLS-1$
     		updateInfo.isSimple = false;
     	}
     	List<GroupSymbol> allGroups = query.getFrom().getGroups();
@@ -249,7 +262,7 @@
 				if (info == null) {
 					continue; // not projected
 				}
-				report.handleValidationWarning(QueryPlugin.Util.getString("ERR.015.012.0004", groupSymbol)); //$NON-NLS-1$
+				report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0004", groupSymbol)); //$NON-NLS-1$
 			}
 		}
 
@@ -268,16 +281,16 @@
     		insertable |= info.insertAllowed;
     	}
     	if ((this.updateInfo.inherentInsert && !insertable)) {
-    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0015")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0015"), false, true, false); //$NON-NLS-1$
     	} 
     	if (this.updateInfo.inherentUpdate && !updatable) {
-    		report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0005")); //$NON-NLS-1$
+    		handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0005"), true, false, true); //$NON-NLS-1$
     	}
     	if (this.updateInfo.inherentDelete && this.updateInfo.deleteTarget == null) {
     		if (this.updateInfo.isSimple) {
     			this.updateInfo.deleteTarget = this.updateInfo.updatableGroups.values().iterator().next();
     		} else {
-    			report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0014")); //$NON-NLS-1$
+    			handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0014"), false, false, true); //$NON-NLS-1$
     		}
     	}
     }
@@ -290,7 +303,7 @@
 		}
 
 		if (!metadata.groupSupports(groupSymbol.getMetadataID(), SupportConstants.Group.UPDATE)) {
-			report.handleValidationWarning(QueryPlugin.Util.getString("ERR.015.012.0003", groupSymbol)); //$NON-NLS-1$
+			report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0003", groupSymbol)); //$NON-NLS-1$
 			return;
 		}
 
@@ -318,7 +331,7 @@
 			return true;
 		}
 		if (this.updateInfo.inherentInsert) {
-			report.handleValidationWarning(QueryPlugin.Util.getString("ERR.015.012.0010", element, element.getGroupSymbol())); //$NON-NLS-1$
+			report.handleValidationError(QueryPlugin.Util.getString("ERR.015.012.0010", element, element.getGroupSymbol())); //$NON-NLS-1$
 		}
 	    return false;
 	}

Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidatorReport.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidatorReport.java	2010-12-02 21:53:52 UTC (rev 2752)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidatorReport.java	2010-12-03 17:14:37 UTC (rev 2753)
@@ -87,8 +87,4 @@
         this.addItem(new ValidatorFailure(message, invalidObjs));
     }
 
-	public void handleValidationWarning(String message) {
-		this.addItem(new ValidatorWarning(message));
-	}
-
 }

Deleted: trunk/engine/src/main/java/org/teiid/query/validator/ValidatorWarning.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidatorWarning.java	2010-12-02 21:53:52 UTC (rev 2752)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidatorWarning.java	2010-12-03 17:14:37 UTC (rev 2753)
@@ -1,84 +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.validator;
-
-import java.util.*;
-
-import org.teiid.query.report.ReportItem;
-import org.teiid.query.sql.LanguageObject;
-
-public class ValidatorWarning extends ReportItem {
-
-	private static final long serialVersionUID = 3991298598581344564L;
-
-	public static final String VALIDATOR_WARNING = "ValidatorWarning"; //$NON-NLS-1$
-
-    // Don't want to pass this around, so make it transient
-    private transient Collection invalidObjects;  
-        
-    public ValidatorWarning(String description) { 
-        super(VALIDATOR_WARNING);
-        setMessage(description);
-    }
-    
-    public ValidatorWarning(String description, LanguageObject object) {
-        super(VALIDATOR_WARNING);
-        setMessage(description);
-        this.invalidObjects = new ArrayList(1);
-        this.invalidObjects.add(object);
-    }
-
-    public ValidatorWarning(String description, Collection objects) { 
-        super(VALIDATOR_WARNING);
-        setMessage(description);
-        this.invalidObjects = new ArrayList(objects);
-    }
-    
-    /** 
-     * Get count of invalid objects.
-     * @return Count of invalid objects
-     */
-    public int getInvalidObjectCount() { 
-        if(this.invalidObjects == null) { 
-            return 0;
-        }
-        return this.invalidObjects.size();
-    }   
-    
-    /**
-     * Get the objects that failed validation.  The collection may be null.
-     * @return Invalid objects, may be null
-     */
-    public Collection getInvalidObjects() { 
-        return this.invalidObjects;
-    } 
-    
-    /**
-     * Return description
-     * @return Description of failure
-     */    
-    public String toString() { 
-        return getMessage();
-    }
-
-}

Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties	2010-12-02 21:53:52 UTC (rev 2752)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties	2010-12-03 17:14:37 UTC (rev 2753)
@@ -94,7 +94,7 @@
 # resolver (008)
 ERR.015.008.0003= Only one XML document may be specified in the FROM clause of a query.
 ERR.015.008.0007= Incorrect number of parameters specified on the stored procedure {2} - expected {0} but got {1}
-ERR.015.008.0009= {1} is not allowed on the virtual group {0}: no {1} procedure was defined.
+ERR.015.008.0009= {1} is not allowed on the view {0}: a procedure must be defined to handle the {1}.
 ERR.015.008.0010= INSERT statement must have the same number of elements and values specified.  This statement has {0} elements and {1} values.
 ERR.015.008.0011= Error parsing query plan transformation for {0}
 ERR.015.008.0012= Unable to resolve update procedure as the virtual group context is ambiguous.

Modified: trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java	2010-12-02 21:53:52 UTC (rev 2752)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestResolver.java	2010-12-03 17:14:37 UTC (rev 2753)
@@ -2572,6 +2572,24 @@
         
         helpResolveException(sql);
     }
+    
+    @Test public void testUpdateError() {
+        String userUpdateStr = "UPDATE vm1.g2 SET e1='x'"; //$NON-NLS-1$
+        
+        helpResolveException(userUpdateStr, metadata, "Error Code:ERR.015.008.0009 Message:Update is not allowed on the view vm1.g2: a procedure must be defined to handle the Update."); //$NON-NLS-1$
+    }
+    
+    @Test public void testInsertError() {
+        String userUpdateStr = "INSERT into vm1.g2 (e1) values ('x')"; //$NON-NLS-1$
+        
+        helpResolveException(userUpdateStr, metadata, "Error Code:ERR.015.008.0009 Message:Insert is not allowed on the view vm1.g2: a procedure must be defined to handle the Insert."); //$NON-NLS-1$
+    }
+    
+    @Test public void testDeleteError() {
+        String userUpdateStr = "DELETE from vm1.g2 where e1='x'"; //$NON-NLS-1$
+        
+        helpResolveException(userUpdateStr, metadata, "Error Code:ERR.015.008.0009 Message:Delete is not allowed on the view vm1.g2: a procedure must be defined to handle the Delete."); //$NON-NLS-1$
+    }
                 
     @Test public void testResolveXMLSelect() {
         String procedure = "CREATE VIRTUAL PROCEDURE "; //$NON-NLS-1$

Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestUpdateValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestUpdateValidator.java	2010-12-02 21:53:52 UTC (rev 2752)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestUpdateValidator.java	2010-12-03 17:14:37 UTC (rev 2753)
@@ -24,7 +24,6 @@
 
 import static org.junit.Assert.*;
 
-import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -46,13 +45,13 @@
 import org.teiid.query.mapping.relational.QueryNode;
 import org.teiid.query.metadata.TransformationMetadata;
 import org.teiid.query.parser.QueryParser;
-import org.teiid.query.report.ReportItem;
 import org.teiid.query.resolver.QueryResolver;
 import org.teiid.query.resolver.util.ResolverUtil;
 import org.teiid.query.sql.lang.Command;
 import org.teiid.query.sql.symbol.GroupSymbol;
 import org.teiid.query.sql.symbol.SingleElementSymbol;
 import org.teiid.query.unittest.RealMetadataFactory;
+import org.teiid.query.validator.UpdateValidator.UpdateInfo;
 
 @SuppressWarnings("nls")
 public class TestUpdateValidator {
@@ -66,15 +65,8 @@
 			GroupSymbol gs = new GroupSymbol(vGroup);
 			ResolverUtil.resolveGroup(gs, md);
 			uv.validate(command, ResolverUtil.resolveElementsInGroup(gs, md));
-			boolean failed = false;
-			for (ReportItem item : (Collection<ReportItem>)uv.getReport().getItems()) {
-				if (item instanceof ValidatorFailure) {
-					failed = true;
-					if (!shouldFail) {
-						fail(item.toString());
-					}
-				}
-			}
+			UpdateInfo info = uv.getUpdateInfo();
+			boolean failed = info.isDeleteValidationError() || info.isInsertValidationError() || info.isUpdateValidationError();
 			if (!failed && shouldFail) {
 				fail("expeceted failures, but got none: " + uv.getReport());
 			}



More information about the teiid-commits mailing list