cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r718498 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/access/trans/ test/java/org/apache/cayenne/access/trans/
Date Tue, 18 Nov 2008 06:34:32 GMT
Author: aadamchik
Date: Mon Nov 17 22:34:32 2008
New Revision: 718498

URL: http://svn.apache.org/viewvc?rev=718498&view=rev
Log:
refactoring of the translator hierarchy

deprecating QueryTranslator, and moving its functions into subclasses

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/UpdateAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/ProcedureTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryTranslator.java?rev=718498&r1=718497&r2=718498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/QueryTranslator.java
Mon Nov 17 22:34:32 2008
@@ -32,38 +32,23 @@
 /**
  * Defines API for translation Cayenne queries to JDBC PreparedStatements.
  * 
+ * @deprecated since 3.0, as a part of translator inheritance hierarchy reorganization.
+ *             This class is no longer in use as a common superclass.
  */
 public abstract class QueryTranslator {
 
-    /** 
-     * Query being translated. 
-     */
     protected Query query;
-
-    /**
-     * JDBC database connection needed to create PreparedStatement. Prior to 1.2 this
-     * property was called "con".
-     */
     protected Connection connection;
-
-    /** Adapter helping to do SQL literal conversions, etc. */
     protected DbAdapter adapter;
-
-    /**
-     * Provides access to Cayenne mapping info.
-     * 
-     * @since 1.2
-     */
     protected EntityResolver entityResolver;
 
     /**
-     * Creates PreparedStatement. <code>logLevel</code> parameter is supplied
to allow
-     * control of logging of produced SQL.
+     * Creates and binds a PreparedStatement to execute query SQL via JDBC.
      */
     public abstract PreparedStatement createStatement() throws Exception;
 
-    /** 
-     * Returns query object being processed. 
+    /**
+     * Returns query object being processed.
      */
     public Query getQuery() {
         return query;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/UpdateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/UpdateAction.java?rev=718498&r1=718497&r2=718498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/UpdateAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/UpdateAction.java
Mon Nov 17 22:34:32 2008
@@ -26,8 +26,8 @@
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.access.QueryLogger;
-import org.apache.cayenne.access.QueryTranslator;
 import org.apache.cayenne.access.trans.DeleteTranslator;
+import org.apache.cayenne.access.trans.QueryAssembler;
 import org.apache.cayenne.access.trans.UpdateTranslator;
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.EntityResolver;
@@ -48,8 +48,8 @@
         this.query = query;
     }
 
-    protected QueryTranslator createTranslator(Connection connection) {
-        QueryTranslator translator;
+    protected QueryAssembler createTranslator(Connection connection) {
+        QueryAssembler translator;
 
         if (query instanceof UpdateQuery) {
             translator = new UpdateTranslator();
@@ -73,7 +73,7 @@
     public void performAction(Connection connection, OperationObserver observer)
             throws SQLException, Exception {
 
-        QueryTranslator translator = createTranslator(connection);
+        QueryAssembler translator = createTranslator(connection);
 
         PreparedStatement statement = translator.createStatement();
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java?rev=718498&r1=718497&r2=718498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/DeleteTranslator.java
Mon Nov 17 22:34:32 2008
@@ -59,7 +59,7 @@
         StringBuilder queryBuf = new StringBuilder("DELETE FROM ");
 
         // 1. append table name
-        DbEntity dbEnt = getRootDbEntity();
+        DbEntity dbEnt = getRootEntity().getDbEntity();
         queryBuf.append(dbEnt.getFullyQualifiedName());
 
         // 2. build qualifier

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/ProcedureTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/ProcedureTranslator.java?rev=718498&r1=718497&r2=718498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/ProcedureTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/ProcedureTranslator.java
Mon Nov 17 22:34:32 2008
@@ -20,13 +20,15 @@
 package org.apache.cayenne.access.trans;
 
 import java.sql.CallableStatement;
+import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.cayenne.access.QueryLogger;
-import org.apache.cayenne.access.QueryTranslator;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.Procedure;
 import org.apache.cayenne.map.ProcedureParameter;
 import org.apache.cayenne.query.ProcedureQuery;
@@ -34,7 +36,7 @@
 /**
  * Stored procedure query translator.
  */
-public class ProcedureTranslator extends QueryTranslator {
+public class ProcedureTranslator {
 
     /**
      * Helper class to make OUT and VOID parameters logger-friendly.
@@ -55,9 +57,32 @@
 
     private static NotInParam OUT_PARAM = new NotInParam("[OUT]");
 
+    protected ProcedureQuery query;
+    protected Connection connection;
+    protected DbAdapter adapter;
+    protected EntityResolver entityResolver;
     protected List<ProcedureParameter> callParams;
     protected List<Object> values;
 
+    public void setQuery(ProcedureQuery query) {
+        this.query = query;
+    }
+
+    public void setConnection(Connection connection) {
+        this.connection = connection;
+    }
+
+    public void setAdapter(DbAdapter adapter) {
+        this.adapter = adapter;
+    }
+
+    /**
+     * @since 1.2
+     */
+    public void setEntityResolver(EntityResolver entityResolver) {
+        this.entityResolver = entityResolver;
+    }
+
     /**
      * Creates an SQL String for the stored procedure call.
      */
@@ -94,7 +119,9 @@
         return buf.toString();
     }
 
-    @Override
+    /**
+     * Creates and binds a PreparedStatement to execute query SQL via JDBC.
+     */
     public PreparedStatement createStatement() throws Exception {
         long t1 = System.currentTimeMillis();
 
@@ -125,11 +152,11 @@
     }
 
     public Procedure getProcedure() {
-        return getEntityResolver().lookupProcedure(query);
+        return entityResolver.lookupProcedure(query);
     }
 
     public ProcedureQuery getProcedureQuery() {
-        return (ProcedureQuery) query;
+        return query;
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java?rev=718498&r1=718497&r2=718498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssembler.java
Mon Nov 17 22:34:32 2008
@@ -19,21 +19,32 @@
 
 package org.apache.cayenne.access.trans;
 
+import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.cayenne.access.QueryLogger;
-import org.apache.cayenne.access.QueryTranslator;
+import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.EntityInheritanceTree;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.JoinType;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.Query;
 
 /**
  * Abstract superclass of Query translators.
  */
-public abstract class QueryAssembler extends QueryTranslator {
+public abstract class QueryAssembler {
+
+    protected Query query;
+    protected Connection connection;
+    protected DbAdapter adapter;
+    protected EntityResolver entityResolver;
 
     /**
      * Holds PreparedStatement values.
@@ -51,7 +62,55 @@
      * @since 3.0
      */
     protected Map<String, String> getPathAliases() {
-        return query.getMetaData(getEntityResolver()).getPathSplitAliases();
+        return query.getMetaData(entityResolver).getPathSplitAliases();
+    }
+    
+    public EntityResolver getEntityResolver() {
+        return entityResolver;
+    }
+    
+    public DbAdapter getAdapter() {
+        return adapter;
+    }
+    
+    /**
+     * Returns an EntityInheritanceTree for the root entity.
+     * 
+     * @since 1.1
+     */
+    public EntityInheritanceTree getRootInheritanceTree() {
+        return getEntityResolver().lookupInheritanceTree(getRootEntity());
+    }
+    
+    /**
+     * Returns query object being processed.
+     */
+    public Query getQuery() {
+        return query;
+    }
+
+    public void setQuery(Query query) {
+        this.query = query;
+    }
+
+    public void setConnection(Connection connection) {
+        this.connection = connection;
+    }
+
+    public void setAdapter(DbAdapter adapter) {
+        this.adapter = adapter;
+    }
+
+    public void setEntityResolver(EntityResolver entityResolver) {
+        this.entityResolver = entityResolver;
+    }
+
+    public ObjEntity getRootEntity() {
+        return query.getMetaData(entityResolver).getObjEntity();
+    }
+
+    public DbEntity getRootDbEntity() {
+        return query.getMetaData(entityResolver).getDbEntity();
     }
 
     /**
@@ -108,7 +167,6 @@
     /**
      * Translates internal query into PreparedStatement.
      */
-    @Override
     public PreparedStatement createStatement() throws Exception {
         long t1 = System.currentTimeMillis();
         String sqlStr = createSqlString();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java?rev=718498&r1=718497&r2=718498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
Mon Nov 17 22:34:32 2008
@@ -283,7 +283,7 @@
         // * joined prefetch PK
 
         ClassDescriptor descriptor = query
-                .getMetaData(getEntityResolver())
+                .getMetaData(entityResolver)
                 .getClassDescriptor();
         ObjEntity oe = descriptor.getEntity();
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java?rev=718498&r1=718497&r2=718498&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/trans/TstQueryAssembler.java
Mon Nov 17 22:34:32 2008
@@ -48,7 +48,7 @@
     }
 
     public void dispose() throws SQLException {
-        super.getConnection().close();
+        connection.close();
     }
 
     @Override



Mime
View raw message