cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r642289 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/ framework/cayenne-j...
Date Fri, 28 Mar 2008 16:57:06 GMT
Author: aadamchik
Date: Fri Mar 28 09:56:55 2008
New Revision: 642289

URL: http://svn.apache.org/viewvc?rev=642289&view=rev
Log:
CAY-1018 Enums fetched via SQLTemplate

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcActionBuilder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8SQLTemplateAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSQLTemplateAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteActionBuilder.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSQLTemplateAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/EnumTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Fri Mar 28 09:56:55 2008
@@ -37,6 +37,7 @@
 CAY-992 Modeler does not escape entity names
 CAY-998 ROP paginated lists must recover from server LRU query cache overflow
 CAY-1003 the paged queries in ROP can fail to fetch the subsequent pages if the client and
server are in different timezones
+CAY-1018 Enums fetched via SQLTemplate
 
 ----------------------------------
 Release: 3.0M3

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/SQLTemplateAction.java
Fri Mar 28 09:56:55 2008
@@ -28,20 +28,24 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.collections.IteratorUtils;
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.OperationObserver;
 import org.apache.cayenne.access.QueryLogger;
 import org.apache.cayenne.access.types.ExtendedTypeMap;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.SQLAction;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.util.Util;
+import org.apache.commons.collections.IteratorUtils;
 
 /**
  * Implements a strategy for execution of SQLTemplates.
@@ -53,10 +57,16 @@
 
     protected DbAdapter adapter;
     protected SQLTemplate query;
+    protected ObjEntity entity;
 
-    public SQLTemplateAction(SQLTemplate query, DbAdapter adapter) {
+    /**
+     * @since 3.0
+     */
+    public SQLTemplateAction(SQLTemplate query, DbAdapter adapter,
+            EntityResolver entityResolver) {
         this.query = query;
         this.adapter = adapter;
+        this.entity = query.getMetaData(entityResolver).getObjEntity();
     }
 
     /**
@@ -199,9 +209,31 @@
         boolean iteratedResult = callback.isIteratedResult();
 
         ExtendedTypeMap types = adapter.getExtendedTypes();
-        RowDescriptor descriptor = (compiled.getResultColumns().length > 0)
-                ? new RowDescriptor(compiled.getResultColumns(), types)
-                : new RowDescriptor(resultSet, types);
+        RowDescriptor descriptor;
+
+        // SQLTemplate #result columns take precedence over other ways to determine the
+        // type
+        if (compiled.getResultColumns().length > 0) {
+            descriptor = new RowDescriptor(compiled.getResultColumns(), types);
+        }
+        else if (entity != null) {
+            Map<String, String> typeOverrides = new HashMap<String, String>();
+
+            // TODO: andrus 2008/03/28 support flattened attributes with aliases...
+            for (ObjAttribute attribute : entity.getAttributes()) {
+                String column = attribute.getDbAttributePath();
+                if (column == null || column.indexOf('.') > 0) {
+                    continue;
+                }
+                
+                typeOverrides.put(column, attribute.getType());
+            }
+
+            descriptor = new RowDescriptor(resultSet, types, typeOverrides);
+        }
+        else {
+            descriptor = new RowDescriptor(resultSet, types);
+        }
 
         if (query.getColumnNamesCapitalization() != null) {
             if (SQLTemplate.LOWERCASE_COLUMN_NAMES.equals(query

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcActionBuilder.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcActionBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/JdbcActionBuilder.java
Fri Mar 28 09:56:55 2008
@@ -88,7 +88,7 @@
     }
 
     public SQLAction sqlAction(SQLTemplate query) {
-        return new SQLTemplateAction(query, adapter);
+        return new SQLTemplateAction(query, adapter, entityResolver);
     }
 
     /**
@@ -97,7 +97,7 @@
      */
     public SQLAction updateAction(Query query) {
         if (query instanceof SQLTemplate) {
-            return new SQLTemplateAction((SQLTemplate) query, adapter);
+            return new SQLTemplateAction((SQLTemplate) query, adapter, entityResolver);
         }
 
         return new UpdateAction(query, adapter, entityResolver);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8ActionBuilder.java
Fri Mar 28 09:56:55 2008
@@ -38,6 +38,6 @@
 
     @Override
     public SQLAction sqlAction(SQLTemplate query) {
-        return new Oracle8SQLTemplateAction(query, adapter);
+        return new Oracle8SQLTemplateAction(query, adapter, getEntityResolver());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8SQLTemplateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8SQLTemplateAction.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8SQLTemplateAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/Oracle8SQLTemplateAction.java
Fri Mar 28 09:56:55 2008
@@ -30,6 +30,7 @@
 import org.apache.cayenne.access.jdbc.SQLStatement;
 import org.apache.cayenne.access.jdbc.SQLTemplateAction;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.SQLTemplate;
 
 /**
@@ -40,8 +41,8 @@
  */
 class Oracle8SQLTemplateAction extends SQLTemplateAction {
 
-    Oracle8SQLTemplateAction(SQLTemplate query, DbAdapter adapter) {
-        super(query, adapter);
+    Oracle8SQLTemplateAction(SQLTemplate query, DbAdapter adapter, EntityResolver resolver)
{
+        super(query, adapter, resolver);
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleActionBuilder.java
Fri Mar 28 09:56:55 2008
@@ -40,7 +40,7 @@
     
     @Override
     public SQLAction sqlAction(SQLTemplate query) {
-        return new OracleSQLTemplateAction(query, adapter);
+        return new OracleSQLTemplateAction(query, adapter, getEntityResolver());
     }
 
     @Override

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSQLTemplateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSQLTemplateAction.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSQLTemplateAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/oracle/OracleSQLTemplateAction.java
Fri Mar 28 09:56:55 2008
@@ -43,6 +43,7 @@
 import org.apache.cayenne.access.jdbc.SQLStatement;
 import org.apache.cayenne.access.jdbc.SQLTemplateAction;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.SQLTemplate;
 
 /**
@@ -51,8 +52,8 @@
  */
 class OracleSQLTemplateAction extends SQLTemplateAction {
 
-    OracleSQLTemplateAction(SQLTemplate query, DbAdapter adapter) {
-        super(query, adapter);
+    OracleSQLTemplateAction(SQLTemplate query, DbAdapter adapter, EntityResolver resolver)
{
+        super(query, adapter, resolver);
     }
 
     @Override
@@ -680,7 +681,7 @@
 
         public String getColumnClassName(int column) throws SQLException {
             String className = delegate.getColumnClassName(column);
-            
+
             if (BigDecimal.class.getName().equals(className)
                     && getColumnType(column) == Types.INTEGER) {
                 className = Integer.class.getName();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteActionBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteActionBuilder.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteActionBuilder.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteActionBuilder.java
Fri Mar 28 09:56:55 2008
@@ -36,6 +36,6 @@
 
     @Override
     public SQLAction sqlAction(SQLTemplate query) {
-        return new SQLiteSQLTemplateAction(query, adapter);
+        return new SQLiteSQLTemplateAction(query, adapter, getEntityResolver());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSQLTemplateAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSQLTemplateAction.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSQLTemplateAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/sqlite/SQLiteSQLTemplateAction.java
Fri Mar 28 09:56:55 2008
@@ -29,6 +29,7 @@
 import org.apache.cayenne.access.jdbc.SQLStatement;
 import org.apache.cayenne.access.jdbc.SQLTemplateAction;
 import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.SQLTemplate;
 
 /**
@@ -37,8 +38,8 @@
  */
 class SQLiteSQLTemplateAction extends SQLTemplateAction {
 
-    public SQLiteSQLTemplateAction(SQLTemplate query, DbAdapter adapter) {
-        super(query, adapter);
+    public SQLiteSQLTemplateAction(SQLTemplate query, DbAdapter adapter, EntityResolver resolver)
{
+        super(query, adapter, resolver);
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/EnumTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/EnumTest.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/EnumTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/EnumTest.java
Fri Mar 28 09:56:55 2008
@@ -77,6 +77,6 @@
 
         EnumEntity e = (EnumEntity) DataObjectUtils.objectForQuery(context, q);
         assertNotNull(e);
-       // assertSame(Enum1.one, e.getEnumAttribute());
+        assertSame(Enum1.one, e.getEnumAttribute());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java?rev=642289&r1=642288&r2=642289&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/jdbc/SQLTemplateActionTest.java
Fri Mar 28 09:56:55 2008
@@ -52,7 +52,8 @@
     public void testProperties() throws Exception {
         DbAdapter adapter = new JdbcAdapter();
         SQLTemplate template = new SQLTemplate(Object.class, "AAAAA");
-        SQLTemplateAction action = new SQLTemplateAction(template, adapter);
+        SQLTemplateAction action = new SQLTemplateAction(template, adapter, getDomain()
+                .getEntityResolver());
         assertSame(adapter, action.getAdapter());
         assertSame(template, action.getQuery());
     }
@@ -246,7 +247,9 @@
     public void testExecuteUpdateNoParameters() throws Exception {
         getAccessStack().createTestData(DataContextCase.class, "testArtists", null);
 
-        SQLTemplate template = new SQLTemplate(Object.class, "delete from ARTIST where ARTIST_NAME
like 'a%'");
+        SQLTemplate template = new SQLTemplate(
+                Object.class,
+                "delete from ARTIST where ARTIST_NAME like 'a%'");
 
         DbAdapter adapter = getAccessStackAdapter().getAdapter();
         SQLAction action = adapter.getAction(template, getNode());
@@ -331,7 +334,8 @@
         SQLTemplate template = new SQLTemplate(Artist.class, "A\nBC");
         SQLTemplateAction action = new SQLTemplateAction(
                 template,
-                getAccessStackAdapter().getAdapter());
+                getAccessStackAdapter().getAdapter(),
+                getDomain().getEntityResolver());
 
         assertEquals("A BC", action.extractTemplateString());
     }
@@ -346,6 +350,8 @@
         map.put("id", new Integer(artistId));
 
         template.setParameters(map);
-        getNode().performQueries(Collections.singleton((Query) template), new QueryResult());
+        getNode().performQueries(
+                Collections.singleton((Query) template),
+                new QueryResult());
     }
 }



Mime
View raw message