cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r586935 - in /cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne: access/jdbc/ dba/mysql/
Date Sun, 21 Oct 2007 19:06:24 GMT
Author: aadamchik
Date: Sun Oct 21 12:06:23 2007
New Revision: 586935

URL: http://svn.apache.org/viewvc?rev=586935&view=rev
Log:
fixing MySQL EJBQL alias generation for delete - release tag

Added:
    cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteFromTranslator.java
    cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteTranslator.java
Modified:
    cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
    cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
    cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
    cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLTranslatorFactory.java

Modified: cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java?rev=586935&r1=586934&r2=586935&view=diff
==============================================================================
--- cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
(original)
+++ cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLDeleteTranslator.java
Sun Oct 21 12:06:23 2007
@@ -27,16 +27,12 @@
  * @since 3.0
  * @author Andrus Adamchik
  */
-class EJBQLDeleteTranslator extends EJBQLBaseVisitor {
+public class EJBQLDeleteTranslator extends EJBQLBaseVisitor {
 
-    private EJBQLTranslationContext context;
+    protected EJBQLTranslationContext context;
 
-    EJBQLDeleteTranslator(EJBQLTranslationContext context) {
+    public EJBQLDeleteTranslator(EJBQLTranslationContext context) {
         this.context = context;
-    }
-
-    EJBQLTranslationContext getContext() {
-        return context;
     }
 
     public boolean visitDelete(EJBQLExpression expression) {

Modified: cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java?rev=586935&r1=586934&r2=586935&view=diff
==============================================================================
--- cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
(original)
+++ cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
Sun Oct 21 12:06:23 2007
@@ -34,16 +34,16 @@
  * @since 3.0
  * @author Andrus Adamchik
  */
-class EJBQLFromTranslator extends EJBQLBaseVisitor {
+public class EJBQLFromTranslator extends EJBQLBaseVisitor {
 
-    private EJBQLTranslationContext context;
+    protected EJBQLTranslationContext context;
     private String lastId;
 
     static String makeJoinTailMarker(String id) {
         return "FROM_TAIL" + id;
     }
 
-    EJBQLFromTranslator(EJBQLTranslationContext context) {
+    public EJBQLFromTranslator(EJBQLTranslationContext context) {
         super(true);
         this.context = context;
     }
@@ -144,7 +144,7 @@
         context.append(")");
     }
 
-    private String appendTable(String id) {
+    protected String appendTable(String id) {
         ClassDescriptor descriptor = context.getEntityDescriptor(id);
 
         String tableName = descriptor.getEntity().getDbEntity().getFullyQualifiedName();

Modified: cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java?rev=586935&r1=586934&r2=586935&view=diff
==============================================================================
--- cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
(original)
+++ cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
Sun Oct 21 12:06:23 2007
@@ -47,18 +47,20 @@
     private Map idAliases;
     private int columnAliasPosition;
     private EJBQLTranslatorFactory translatorFactory;
+    private boolean usingAliases;
 
     // a flag indicating whether column expressions should be treated as result columns or
     // not.
     private boolean appendingResultColumns;
 
-    public EJBQLTranslationContext(EJBQLCompiledExpression compiledExpression, Map parameters,
-            EJBQLTranslatorFactory translatorFactory) {
+    public EJBQLTranslationContext(EJBQLCompiledExpression compiledExpression,
+            Map parameters, EJBQLTranslatorFactory translatorFactory) {
         this.compiledExpression = compiledExpression;
         this.mainBuffer = new StringBuffer();
         this.currentBuffer = mainBuffer;
         this.parameters = parameters;
         this.translatorFactory = translatorFactory;
+        this.usingAliases = true;
     }
 
     SQLTemplate getQuery() {
@@ -91,7 +93,7 @@
      * Looks up entity descriptor for an identifier that can be a compiled expression id
      * or one of the aliases.
      */
-    ClassDescriptor getEntityDescriptor(String id) {
+    public ClassDescriptor getEntityDescriptor(String id) {
         return compiledExpression.getEntityDescriptor(resolveId(id));
     }
 
@@ -304,7 +306,11 @@
      * Retrieves a SQL alias for the combination of EJBQL id variable and a table name. If
      * such alias hasn't been used, it is created on the fly.
      */
-    String getTableAlias(String idPath, String tableName) {
+    protected String getTableAlias(String idPath, String tableName) {
+        
+        if(!isUsingAliases()) {
+            return tableName;
+        }
 
         StringBuffer keyBuffer = new StringBuffer();
 
@@ -360,5 +366,13 @@
 
     void setAppendingResultColumns(boolean appendingResultColumns) {
         this.appendingResultColumns = appendingResultColumns;
+    }
+
+    public boolean isUsingAliases() {
+        return usingAliases;
+    }
+
+    public void setUsingAliases(boolean useAliases) {
+        this.usingAliases = useAliases;
     }
 }

Added: cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteFromTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteFromTranslator.java?rev=586935&view=auto
==============================================================================
--- cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteFromTranslator.java
(added)
+++ cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteFromTranslator.java
Sun Oct 21 12:06:23 2007
@@ -0,0 +1,45 @@
+/*****************************************************************
+ *   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.dba.mysql;
+
+import org.apache.cayenne.access.jdbc.EJBQLFromTranslator;
+import org.apache.cayenne.access.jdbc.EJBQLTranslationContext;
+import org.apache.cayenne.reflect.ClassDescriptor;
+
+/**
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class MySQLEJBQLDeleteFromTranslator extends EJBQLFromTranslator {
+
+    MySQLEJBQLDeleteFromTranslator(EJBQLTranslationContext context) {
+        super(context);
+    }
+
+    /**
+     * Suppresses table alias.
+     */
+    protected String appendTable(String id) {
+        ClassDescriptor descriptor = context.getEntityDescriptor(id);
+        String tableName = descriptor.getEntity().getDbEntity().getFullyQualifiedName();
+
+        context.append(' ').append(tableName);
+        return tableName;
+    }
+}

Added: cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteTranslator.java?rev=586935&view=auto
==============================================================================
--- cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteTranslator.java
(added)
+++ cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLDeleteTranslator.java
Sun Oct 21 12:06:23 2007
@@ -0,0 +1,40 @@
+/*****************************************************************
+ *   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.dba.mysql;
+
+import org.apache.cayenne.access.jdbc.EJBQLDeleteTranslator;
+import org.apache.cayenne.access.jdbc.EJBQLTranslationContext;
+import org.apache.cayenne.ejbql.EJBQLExpression;
+
+/**
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class MySQLEJBQLDeleteTranslator extends EJBQLDeleteTranslator {
+
+    MySQLEJBQLDeleteTranslator(EJBQLTranslationContext context) {
+        super(context);
+    }
+
+    public boolean visitFrom(EJBQLExpression expression, int finishedChildIndex) {
+        context.append(" FROM");
+        expression.visit(new MySQLEJBQLDeleteFromTranslator(context));
+        return false;
+    }
+}

Modified: cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLTranslatorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLTranslatorFactory.java?rev=586935&r1=586934&r2=586935&view=diff
==============================================================================
--- cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLTranslatorFactory.java
(original)
+++ cayenne/main/tags/3.0M2/cayenne/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/dba/mysql/MySQLEJBQLTranslatorFactory.java
Sun Oct 21 12:06:23 2007
@@ -31,4 +31,9 @@
     public EJBQLExpressionVisitor getConditionTranslator(EJBQLTranslationContext context)
{
         return new MySQLEJBQLConditionTranslator(context);
     }
+
+    public EJBQLExpressionVisitor getDeleteTranslator(EJBQLTranslationContext context) {
+        context.setUsingAliases(false);
+        return new MySQLEJBQLDeleteTranslator(context);
+    }
 }



Mime
View raw message