cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r561488 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc: EJBQLAction.java EJBQLUpdateTranslator.java
Date Tue, 31 Jul 2007 20:22:44 GMT
Author: aadamchik
Date: Tue Jul 31 13:22:43 2007
New Revision: 561488

URL: http://svn.apache.org/viewvc?view=rev&rev=561488
Log:
CAY-837 EJBQL Update Statement Support
(initial update translator; doesn't fully work)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java?view=diff&rev=561488&r1=561487&r2=561488
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLAction.java
Tue Jul 31 13:22:43 2007
@@ -73,7 +73,9 @@
             }
 
             public boolean visitUpdate(EJBQLExpression expression) {
-                throw new UnsupportedOperationException("Not yet implemented");
+                EJBQLUpdateTranslator visitor = new EJBQLUpdateTranslator(context);
+                expression.visit(visitor);
+                return false;
             }
         });
 

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java?view=auto&rev=561488
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLUpdateTranslator.java
Tue Jul 31 13:22:43 2007
@@ -0,0 +1,79 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access.jdbc;
+
+import org.apache.cayenne.ejbql.EJBQLBaseVisitor;
+import org.apache.cayenne.ejbql.EJBQLExpression;
+
+/**
+ * A translator of EJBQL UPDATE statements into SQL.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class EJBQLUpdateTranslator extends EJBQLBaseVisitor {
+
+    private EJBQLTranslationContext context;
+    private int itemCount;
+
+    EJBQLUpdateTranslator(EJBQLTranslationContext context) {
+        this.context = context;
+    }
+
+    EJBQLTranslationContext getContext() {
+        return context;
+    }
+
+    public boolean visitUpdate(EJBQLExpression expression) {
+        context.append("UPDATE");
+        return true;
+    }
+
+    public boolean visitFrom(EJBQLExpression expression, int finishedChildIndex) {
+        expression.visit(new EJBQLFromTranslator(context));
+
+        return false;
+    }
+
+    public boolean visitUpdateItem(EJBQLExpression expression) {
+        if (itemCount++ > 0) {
+            context.append(',');
+        }
+        else {
+            context.append(" SET");
+        }
+
+        return true;
+    }
+
+    public boolean visitUpdateField(EJBQLExpression expression) {
+        EJBQLPathTranslator pathTranslator = new EJBQLPathTranslator(context) {
+
+            protected void appendMultiColumnPath(EJBQLMultiColumnOperand operand) {
+                throw new UnsupportedOperationException();
+            }
+        };
+        expression.visit(pathTranslator);
+        return false;
+    }
+
+    public boolean visitUpdateValue(EJBQLExpression expression) {
+        return true;
+    }
+}



Mime
View raw message