1 19 20 package org.apache.cayenne.project.validator; 21 22 import java.util.Iterator ; 23 24 import org.apache.cayenne.map.DataMap; 25 import org.apache.cayenne.map.Procedure; 26 import org.apache.cayenne.project.ProjectPath; 27 import org.apache.cayenne.query.ProcedureQuery; 28 import org.apache.cayenne.query.Query; 29 import org.apache.cayenne.util.Util; 30 31 37 public class ProcedureQueryValidator extends TreeNodeValidator { 38 39 public void validateObject(ProjectPath treeNodePath, Validator validator) { 40 ProcedureQuery query = (ProcedureQuery) treeNodePath.getObject(); 41 42 validateName(query, treeNodePath, validator); 43 validateRoot(query, treeNodePath, validator); 44 } 45 46 protected void validateRoot( 47 ProcedureQuery query, 48 ProjectPath path, 49 Validator validator) { 50 DataMap map = (DataMap) path.firstInstanceOf(DataMap.class); 51 Object root = query.getRoot(); 52 53 if (root == null && map != null) { 54 validator.registerWarning("Query has no root", path); 55 } 56 57 if (root instanceof Procedure) { 59 Procedure procedure = (Procedure) root; 60 61 if (map != null && map.getProcedure(procedure.getName()) != procedure) { 63 validator.registerWarning("Invalid Procedure Root - " 64 + procedure.getName(), path); 65 } 66 67 return; 68 } 69 70 if (root instanceof String ) { 71 if (map != null && map.getProcedure(root.toString()) == null) { 72 validator.registerWarning("Invalid Procedure Root - " + root, path); 73 } 74 } 75 } 76 77 protected void validateName(Query query, ProjectPath path, Validator validator) { 78 String name = query.getName(); 79 80 if (Util.isEmptyString(name)) { 82 validator.registerError("Unnamed Query.", path); 83 return; 84 } 85 86 DataMap map = (DataMap) path.getObjectParent(); 87 if (map == null) { 88 return; 89 } 90 91 Iterator it = map.getQueries().iterator(); 93 while (it.hasNext()) { 94 Query otherQuery = (Query) it.next(); 95 if (otherQuery == query) { 96 continue; 97 } 98 99 if (name.equals(otherQuery.getName())) { 100 validator.registerError("Duplicate Query name: " + name + ".", path); 101 break; 102 } 103 } 104 } 105 106 } 107 | Popular Tags |