cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r546073 - /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/
Date Mon, 11 Jun 2007 10:18:37 GMT
Author: aadamchik
Date: Mon Jun 11 03:18:35 2007
New Revision: 546073

URL: http://svn.apache.org/viewvc?view=rev&rev=546073
Log:
refactoring of EJBQL translator - consistent use of the newly introduced "context" in child
translators

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java?view=diff&rev=546073&r1=546072&r2=546073
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLConditionTranslator.java
Mon Jun 11 03:18:35 2007
@@ -31,10 +31,10 @@
  */
 class EJBQLConditionTranslator extends EJBQLDelegatingVisitor {
 
-    private EJBQLSelectTranslator parent;
+    private EJBQLTranslationContext context;
 
-    EJBQLConditionTranslator(EJBQLSelectTranslator parent) {
-        this.parent = parent;
+    EJBQLConditionTranslator(EJBQLTranslationContext context) {
+        this.context = context;
     }
 
     public boolean visitAnd(EJBQLExpression expression, int finishedChildIndex) {
@@ -47,15 +47,15 @@
         switch (finishedChildIndex) {
             case 0:
                 if (expression.isNegated()) {
-                    parent.getParent().getBuffer().append(" NOT");
+                    context.append(" NOT");
                 }
-                parent.getParent().getBuffer().append(" BETWEEN #bind(");
+                context.append(" BETWEEN #bind(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(") AND #bind(");
+                context.append(") AND #bind(");
                 break;
             case 2:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -71,10 +71,10 @@
         setDelegate(null);
         switch (finishedChildIndex) {
             case 0:
-                parent.getParent().getBuffer().append(" #bindEqual(");
+                context.append(" #bindEqual(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -82,7 +82,7 @@
     }
 
     public boolean visitNot(EJBQLExpression expression) {
-        parent.getParent().getBuffer().append(" NOT");
+        context.append(" NOT");
         return true;
     }
 
@@ -90,10 +90,10 @@
         setDelegate(null);
         switch (finishedChildIndex) {
             case 0:
-                parent.getParent().getBuffer().append(" #bindNotEqual(");
+                context.append(" #bindNotEqual(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -104,10 +104,10 @@
         setDelegate(null);
         switch (finishedChildIndex) {
             case 0:
-                parent.getParent().getBuffer().append(" > #bind(");
+                context.append(" > #bind(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -118,10 +118,10 @@
         setDelegate(null);
         switch (finishedChildIndex) {
             case 0:
-                parent.getParent().getBuffer().append(" >= #bind(");
+                context.append(" >= #bind(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -132,10 +132,10 @@
         setDelegate(null);
         switch (finishedChildIndex) {
             case 0:
-                parent.getParent().getBuffer().append(" <= #bind(");
+                context.append(" <= #bind(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -146,10 +146,10 @@
         setDelegate(null);
         switch (finishedChildIndex) {
             case 0:
-                parent.getParent().getBuffer().append(" < #bind(");
+                context.append(" < #bind(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -161,12 +161,12 @@
         switch (finishedChildIndex) {
             case 0:
                 if (expression.isNegated()) {
-                    parent.getParent().getBuffer().append(" NOT");
+                    context.append(" NOT");
                 }
-                parent.getParent().getBuffer().append(" LIKE #bind(");
+                context.append(" LIKE #bind(");
                 break;
             case 1:
-                parent.getParent().getBuffer().append(")");
+                context.append(")");
                 break;
         }
 
@@ -176,7 +176,7 @@
     protected void afterChild(EJBQLExpression e, String text, int childIndex) {
         if (childIndex >= 0) {
             if (childIndex + 1 < e.getChildrenCount()) {
-                parent.getParent().getBuffer().append(text);
+                context.append(text);
             }
 
             // reset child-specific delegate
@@ -186,7 +186,7 @@
 
     public boolean visitPath(EJBQLPath expression, int finishedChildIndex) {
         if (finishedChildIndex < 0) {
-            setDelegate(new EJBQLPathTranslator(parent));
+            setDelegate(new EJBQLPathTranslator(context));
             return true;
         }
         else {
@@ -196,20 +196,19 @@
 
     public boolean visitStringLiteral(EJBQLExpression expression) {
         if (expression.getText() == null) {
-            parent.getParent().getBuffer().append("null");
+            context.append("null");
         }
         else {
             // note that String Literal text is already wrapped in single quotes, with
             // quotes that are part of the string escaped.
-            parent.getParent().getBuffer().append(expression.getText()).append(
-                    " 'VARCHAR'");
+            context.append(expression.getText()).append(" 'VARCHAR'");
         }
         return true;
     }
 
     public boolean visitIntegerLiteral(EJBQLExpression expression) {
         if (expression.getText() == null) {
-            parent.getParent().getBuffer().append("null");
+            context.append("null");
         }
         else {
             Object value;
@@ -221,15 +220,15 @@
                 throw new EJBQLException("Invalid integer: " + expression.getText());
             }
 
-            String var = parent.getParent().bindParameter(value);
-            parent.getParent().getBuffer().append('$').append(var).append(" 'INTEGER'");
+            String var = context.bindParameter(value);
+            context.append('$').append(var).append(" 'INTEGER'");
         }
         return true;
     }
 
     public boolean visitDecimalLiteral(EJBQLExpression expression) {
         if (expression.getText() == null) {
-            parent.getParent().getBuffer().append("null");
+            context.append("null");
         }
         else {
             Object value;
@@ -241,12 +240,12 @@
                 throw new EJBQLException("Invalid decimal: " + expression.getText());
             }
 
-            String var = parent.getParent().bindParameter(value);
-            parent.getParent().getBuffer().append('$').append(var).append(" 'DECIMAL'");
+            String var = context.bindParameter(value);
+            context.append('$').append(var).append(" 'DECIMAL'");
         }
         return true;
     }
-    
+
     public boolean visitPatternValue(EJBQLExpression expression) {
         // TODO: andrus 3/25/2007 - implement me
         return true;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java?view=diff&rev=546073&r1=546072&r2=546073
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLFromTranslator.java
Mon Jun 11 03:18:35 2007
@@ -31,18 +31,18 @@
 
 public class EJBQLFromTranslator extends EJBQLBaseVisitor {
 
-    private EJBQLSelectTranslator parent;
+    private EJBQLTranslationContext context;
     private String lastTableAlias;
 
-    public EJBQLFromTranslator(EJBQLSelectTranslator parent) {
+    public EJBQLFromTranslator(EJBQLTranslationContext context) {
         super(true);
-        this.parent = parent;
+        this.context = context;
     }
 
     public boolean visitFromItem(EJBQLFromItem expression, int finishedChildIndex) {
         if (finishedChildIndex < 0) {
             if (lastTableAlias != null) {
-                parent.getParent().getBuffer().append(',');
+                context.append(',');
             }
 
             lastTableAlias = appendTable(expression.getId());
@@ -83,14 +83,12 @@
         }
 
         String sourceAlias = lastTableAlias;
-        StringBuffer buffer = parent.getParent().getBuffer();
 
-        buffer.append(" ").append(semantics);
+        context.append(" ").append(semantics);
         String targetAlias = appendTable(id);
-        buffer.append(" ON (");
+        context.append(" ON (");
 
-        ObjRelationship incoming = parent
-                .getParent()
+        ObjRelationship incoming = context
                 .getCompiledExpression()
                 .getIncomingRelationship(id);
         if (incoming == null) {
@@ -103,36 +101,40 @@
         Iterator it = incomingDB.getJoins().iterator();
         if (it.hasNext()) {
             DbJoin dbJoin = (DbJoin) it.next();
-            buffer.append(sourceAlias).append('.').append(dbJoin.getSourceName()).append(
-                    " = ").append(targetAlias).append('.').append(dbJoin.getTargetName());
+            context
+                    .append(sourceAlias)
+                    .append('.')
+                    .append(dbJoin.getSourceName())
+                    .append(" = ")
+                    .append(targetAlias)
+                    .append('.')
+                    .append(dbJoin.getTargetName());
         }
 
         while (it.hasNext()) {
-            buffer.append(", ");
+            context.append(", ");
             DbJoin dbJoin = (DbJoin) it.next();
-            buffer.append(sourceAlias).append('.').append(dbJoin.getSourceName()).append(
-                    " = ").append(targetAlias).append('.').append(dbJoin.getTargetName());
+            context
+                    .append(sourceAlias)
+                    .append('.')
+                    .append(dbJoin.getSourceName())
+                    .append(" = ")
+                    .append(targetAlias)
+                    .append('.')
+                    .append(dbJoin.getTargetName());
         }
 
-        buffer.append(")");
+        context.append(")");
         this.lastTableAlias = targetAlias;
     }
 
     private String appendTable(String id) {
-        ClassDescriptor descriptor = parent
-                .getParent()
-                .getCompiledExpression()
-                .getEntityDescriptor(id);
+        ClassDescriptor descriptor = context.getCompiledExpression().getEntityDescriptor(
+                id);
 
         String tableName = descriptor.getEntity().getDbEntity().getFullyQualifiedName();
-        String alias = parent.getParent().createAlias(id, tableName);
-        parent
-                .getParent()
-                .getBuffer()
-                .append(' ')
-                .append(tableName)
-                .append(" AS ")
-                .append(alias);
+        String alias = context.createAlias(id, tableName);
+        context.append(' ').append(tableName).append(" AS ").append(alias);
         return alias;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java?view=diff&rev=546073&r1=546072&r2=546073
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLPathTranslator.java
Mon Jun 11 03:18:35 2007
@@ -30,14 +30,14 @@
 
 class EJBQLPathTranslator extends EJBQLBaseVisitor {
 
-    private EJBQLSelectTranslator parent;
+    private EJBQLTranslationContext context;
     private ObjEntity currentEntity;
     private String lastPathComponent;
     private String idPath;
 
-    EJBQLPathTranslator(EJBQLSelectTranslator parent) {
+    EJBQLPathTranslator(EJBQLTranslationContext context) {
         super(true);
-        this.parent = parent;
+        this.context = context;
     }
 
     public boolean visitPath(EJBQLPath expression, int finishedChildIndex) {
@@ -55,10 +55,8 @@
     }
 
     public boolean visitIdentifier(EJBQLExpression expression) {
-        ClassDescriptor descriptor = parent
-                .getParent()
-                .getCompiledExpression()
-                .getEntityDescriptor(expression.getText());
+        ClassDescriptor descriptor = context.getCompiledExpression().getEntityDescriptor(
+                expression.getText());
         if (descriptor == null) {
             throw new EJBQLException("Invalid identification variable: "
                     + expression.getText());
@@ -98,10 +96,8 @@
                 .getAttribute(lastPathComponent);
 
         DbEntity table = currentEntity.getDbEntity();
-        String alias = parent.getParent().createAlias(
-                idPath,
-                table.getFullyQualifiedName());
-        parent.getParent().getBuffer().append(' ').append(alias).append('.').append(
+        String alias = context.createAlias(idPath, table.getFullyQualifiedName());
+        context.append(' ').append(alias).append('.').append(
                 attribute.getDbAttributeName());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java?view=diff&rev=546073&r1=546072&r2=546073
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectColumnsTranslator.java
Mon Jun 11 03:18:35 2007
@@ -18,13 +18,17 @@
  ****************************************************************/
 package org.apache.cayenne.access.jdbc;
 
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.ejbql.EJBQLBaseVisitor;
 import org.apache.cayenne.ejbql.EJBQLExpression;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.ObjAttribute;
@@ -44,11 +48,11 @@
  */
 class EJBQLSelectColumnsTranslator extends EJBQLBaseVisitor {
 
-    private EJBQLSelectTranslator parent;
+    private EJBQLTranslationContext context;
 
-    EJBQLSelectColumnsTranslator(EJBQLSelectTranslator parent) {
+    EJBQLSelectColumnsTranslator(EJBQLTranslationContext context) {
         super(false);
-        this.parent = parent;
+        this.context = context;
     }
 
     public boolean visitSelectExpression(EJBQLExpression expression) {
@@ -60,10 +64,8 @@
         final String idVar = expression.getText();
 
         // append all table columns
-        ClassDescriptor descriptor = parent
-                .getParent()
-                .getCompiledExpression()
-                .getEntityDescriptor(idVar);
+        ClassDescriptor descriptor = context.getCompiledExpression().getEntityDescriptor(
+                idVar);
 
         PropertyVisitor visitor = new PropertyVisitor() {
 
@@ -83,7 +85,7 @@
                                     "ObjAttribute has no DbAttribute: " + oa.getName());
                         }
 
-                        parent.appendColumn(idVar, dbAttr, oa.getType());
+                        appendColumn(idVar, dbAttr, oa.getType());
                     }
                 }
                 return true;
@@ -109,7 +111,7 @@
                     DbJoin join = (DbJoin) joins.get(i);
                     DbAttribute src = join.getSource();
 
-                    parent.appendColumn(idVar, src);
+                    appendColumn(idVar, src);
                 }
             }
         };
@@ -119,5 +121,41 @@
         descriptor.visitAllProperties(visitor);
 
         return true;
+    }
+
+    private void appendColumn(String identifier, DbAttribute column) {
+        appendColumn(identifier, column, TypesMapping.getJavaBySqlType(column.getType()));
+    }
+
+    private void appendColumn(String identifier, DbAttribute column, String javaType) {
+        DbEntity table = (DbEntity) column.getEntity();
+        String alias = context.createAlias(identifier, table.getFullyQualifiedName());
+        String columnName = alias + "." + column.getName();
+
+        Set columns = getColumns();
+
+        if (columns.add(columnName)) {
+            // using #result directive:
+            // 1. to ensure that DB default captalization rules won't lead to changing
+            // result columns capitalization, as #result() gives SQLTemplate a hint as to
+            // what name is expected by the caller.
+            // 2. to ensure proper type conversion
+            context.append(columns.size() > 1 ? ", " : " ").append("#result('").append(
+                    columnName).append("' '").append(javaType).append("' '").append(
+                    column.getName()).append("')");
+        }
+    }
+
+    private Set getColumns() {
+
+        String columnsKey = getClass().getName() + ":columns";
+        Set columns = (Set) context.getTranslationValue(columnsKey);
+
+        if (columns == null) {
+            columns = new HashSet();
+            context.putTranslationVariable(columnsKey, columns);
+        }
+
+        return columns;
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java?view=diff&rev=546073&r1=546072&r2=546073
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLSelectTranslator.java
Mon Jun 11 03:18:35 2007
@@ -18,14 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.access.jdbc;
 
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.ejbql.EJBQLDelegatingVisitor;
 import org.apache.cayenne.ejbql.EJBQLExpression;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
 
 /**
  * A translator of EJBQL select statements into SQL.
@@ -35,70 +29,37 @@
  */
 class EJBQLSelectTranslator extends EJBQLDelegatingVisitor {
 
-    private EJBQLTranslationContext parent;
-    private Set columns;
-
-    EJBQLSelectTranslator(EJBQLTranslationContext parent) {
-        this.parent = parent;
-    }
-
-    void appendColumn(String identifier, DbAttribute column) {
-        appendColumn(identifier, column, TypesMapping.getJavaBySqlType(column.getType()));
-    }
+    private EJBQLTranslationContext context;
 
-    void appendColumn(String identifier, DbAttribute column, String javaType) {
-        DbEntity table = (DbEntity) column.getEntity();
-        String alias = parent.createAlias(identifier, table.getFullyQualifiedName());
-        String columnName = alias + "." + column.getName();
-
-        if (columns == null) {
-            columns = new HashSet();
-        }
-
-        if (columns.add(columnName)) {
-            // using #result directive:
-            // 1. to ensure that DB default captalization rules won't lead to changing
-            // result columns capitalization, as #result() gives SQLTemplate a hint as to
-            // what name is expected by the caller.
-            // 2. to ensure proper type conversion
-            parent
-                    .getBuffer()
-                    .append(columns.size() > 1 ? ", " : " ")
-                    .append("#result('")
-                    .append(columnName)
-                    .append("' '")
-                    .append(javaType)
-                    .append("' '")
-                    .append(column.getName())
-                    .append("')");
-        }
+    EJBQLSelectTranslator(EJBQLTranslationContext context) {
+        this.context = context;
     }
 
-    EJBQLTranslationContext getParent() {
-        return parent;
+    EJBQLTranslationContext getContext() {
+        return context;
     }
 
     public boolean visitDistinct(EJBQLExpression expression) {
-        parent.getBuffer().append(" DISTINCT");
+        context.append(" DISTINCT");
         return true;
     }
 
     public boolean visitFrom(EJBQLExpression expression) {
-        parent.getBuffer().append(" FROM");
-        setDelegate(new EJBQLFromTranslator(this));
+        context.append(" FROM");
+        setDelegate(new EJBQLFromTranslator(context));
         return true;
     }
 
     public boolean visitOrderBy(EJBQLExpression expression) {
-        parent.getBuffer().append(" ORDER BY");
+        context.append(" ORDER BY");
         setDelegate(new EJBQLSelectOrderByTranslator());
         return true;
     }
 
     public boolean visitSelect(EJBQLExpression expression, int finishedChildIndex) {
         if (finishedChildIndex < 0) {
-            parent.getBuffer().append("SELECT");
-            setDelegate(new EJBQLSelectColumnsTranslator(this));
+            context.append("SELECT");
+            setDelegate(new EJBQLSelectColumnsTranslator(context));
         }
 
         return true;
@@ -106,8 +67,8 @@
 
     public boolean visitWhere(EJBQLExpression expression, int finishedChildIndex) {
         if (finishedChildIndex < 0) {
-            parent.getBuffer().append(" WHERE");
-            setDelegate(new EJBQLConditionTranslator(this));
+            context.append(" WHERE");
+            setDelegate(new EJBQLConditionTranslator(context));
         }
         return true;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java?view=diff&rev=546073&r1=546072&r2=546073
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLTranslationContext.java
Mon Jun 11 03:18:35 2007
@@ -36,6 +36,7 @@
     private Map bindingVariables;
     private StringBuffer buffer;
     private EJBQLCompiledExpression compiledExpression;
+    private Map translationVariables;
 
     EJBQLTranslationContext(EJBQLCompiledExpression compiledExpression) {
         this.compiledExpression = compiledExpression;
@@ -51,8 +52,33 @@
         return query;
     }
 
-    StringBuffer getBuffer() {
-        return buffer;
+    void putTranslationVariable(String var, Object value) {
+        if (translationVariables == null) {
+            translationVariables = new HashMap();
+        }
+
+        translationVariables.put(var, value);
+    }
+
+    Object getTranslationValue(String var) {
+        return translationVariables != null ? translationVariables.get(var) : null;
+    }
+
+    /**
+     * Appends a piece of SQL to the internal buffer.
+     */
+    EJBQLTranslationContext append(String chunk) {
+        buffer.append(chunk);
+        return this;
+    }
+
+    /**
+     * Appends a piece of SQL to the internal buffer.
+     */
+
+    public EJBQLTranslationContext append(char chunk) {
+        buffer.append(chunk);
+        return this;
     }
 
     EJBQLCompiledExpression getCompiledExpression() {



Mime
View raw message