cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject [1/2] cayenne git commit: Fixed EJBQL query validation
Date Fri, 11 Nov 2016 18:42:25 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 5d8471a83 -> b013ca167


Fixed EJBQL query validation


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/8c625cfd
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/8c625cfd
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/8c625cfd

Branch: refs/heads/master
Commit: 8c625cfd7362b780d71ef0707c772399b55475b7
Parents: 2b7a21b
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Wed Nov 9 12:21:40 2016 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Wed Nov 9 12:21:40 2016 +0300

----------------------------------------------------------------------
 .../project/validation/EJBQLQueryValidator.java |  9 +-----
 .../validation/EJBQLStatementValidator.java     | 34 +++++++++-----------
 .../modeler/editor/EjbqlQueryScriptsTab.java    |  5 +--
 3 files changed, 17 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/8c625cfd/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
index d44fb50..ae250e4 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLQueryValidator.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.project.validation;
 
-import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.project.validation.EJBQLStatementValidator.PositionException;
 import org.apache.cayenne.map.EJBQLQueryDescriptor;
 import org.apache.cayenne.validation.ValidationResult;
@@ -27,13 +26,7 @@ class EJBQLQueryValidator extends ConfigurationNodeValidator {
 
     void validate(EJBQLQueryDescriptor query, ValidationResult validationResult) {
 
-        PositionException message = new EJBQLStatementValidator().validateEJBQL(
-                query,
-                new EntityResolver(query
-                        .getDataMap()
-                        .getDataChannelDescriptor()
-                        .getDataMaps()));
-
+        PositionException message = new EJBQLStatementValidator().validateEJBQL(query);
         if (message != null) {
             addFailure(validationResult, query, "Error in EJBQL query '%s' syntax", query
                     .getName());

http://git-wip-us.apache.org/repos/asf/cayenne/blob/8c625cfd/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
index acd5064..6ac0110 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/EJBQLStatementValidator.java
@@ -22,23 +22,23 @@ import java.lang.reflect.Field;
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ejbql.EJBQLException;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.ejbql.EJBQLParserFactory;
 import org.apache.cayenne.map.EJBQLQueryDescriptor;
 
 public class EJBQLStatementValidator {
 
-    public PositionException validateEJBQL(EJBQLQueryDescriptor query, EntityResolver er)
{
+    public PositionException validateEJBQL(EJBQLQueryDescriptor query) {
         if (query.getEjbql() != null) {
             PositionException message = null;
 
-            EJBQLQuery queryTemp = new EJBQLQuery();
-            queryTemp.setEjbqlStatement(query.getEjbql());
-
             try {
-                queryTemp.getExpression(er);
-            }
-            catch (CayenneRuntimeException e) {
+                // Only parse query and validate it's syntax.
+                // It still may be invalid e.g. invalid entities used.
+                // We can't call compile() for the full check as it will try to get
+                // Class objects for ObjEntities used in query that are not available
+                // in the modeler
+                EJBQLParserFactory.getParser().parse(query.getEjbql());
+            } catch (CayenneRuntimeException e) {
                 message = new PositionException();
                 message.setE(e);
                 if (e.getCause() != null) {
@@ -46,7 +46,6 @@ public class EJBQLStatementValidator {
                     message.setMessage(e.getCause().getMessage());
 
                     if (e instanceof EJBQLException) {
-
                         EJBQLException ejbqlException = (EJBQLException) e;
                         Throwable cause = ejbqlException.getCause();
 
@@ -77,23 +76,20 @@ public class EJBQLStatementValidator {
                                 message.setEndLine((Integer) endLineField.get(nextToken));
                                 message.setImage((String) imageField.get(nextToken));
                                 message.setLength(message.getImage().length());
-                            }
-                            catch (Exception e1) {
+                            } catch (Exception e1) {
                                 throw new CayenneRuntimeException(e1);
                             }
                         }
-
                     }
-                }
-                else {
+                } else {
                     message.setE(e);
                     message.setMessage(e.getUnlabeledMessage());
                 }
-
-            }
-            catch (Exception e) {
+            } catch (Throwable e) {
                 message = new PositionException();
-                message.setE(e);
+                if(e instanceof Exception) {
+                    message.setE((Exception)e);
+                }
                 message.setMessage(e.getMessage());
             }
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/8c625cfd/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
index 146b372..003e674 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EjbqlQueryScriptsTab.java
@@ -31,9 +31,7 @@ import javax.swing.event.DocumentListener;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
 
-import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.configuration.event.QueryEvent;
-import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.util.JUndoableCayenneTextPane;
 import org.apache.cayenne.project.validation.EJBQLStatementValidator;
@@ -205,8 +203,7 @@ public class EjbqlQueryScriptsTab extends JPanel implements DocumentListener
{
     }
 
     void validateEJBQL() {
-        final PositionException positionException = ejbqlQueryValidator.validateEJBQL(getQuery(),
new EntityResolver(
-                ((DataChannelDescriptor) mediator.getProject().getRootNode()).getDataMaps()));
+        final PositionException positionException = ejbqlQueryValidator.validateEJBQL(getQuery());
         if (positionException != null) {
 
             if (!SwingUtilities.isEventDispatchThread()) {


Mime
View raw message