cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1057144 - in /cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/trans/ main/java/org/apache/cayenne/dba/hsqldb/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/...
Date Mon, 10 Jan 2011 10:29:28 GMT
Author: oltka
Date: Mon Jan 10 10:29:27 2011
New Revision: 1057144

URL: http://svn.apache.org/viewvc?rev=1057144&view=rev
Log:
CAY-1506 - Reserverd words mapping in WHERE clause

* added tests, fixed problem with quote in ALTER TABLE ... DROP CONSTRAINT ...;
* fixed problem in HSQLDBAdapter (2 times added quotes); fixed problem with column without
quotes

Modified:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/resources/quotemap.map.xml

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java?rev=1057144&r1=1057143&r2=1057144&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
Mon Jan 10 10:29:27 2011
@@ -280,9 +280,7 @@ public abstract class QueryAssemblerHelp
     }
 
     protected void processColumn(DbAttribute dbAttr) throws IOException {
-        String alias = (queryAssembler.supportsTableAliases()) ? queryAssembler
-                .getCurrentAlias() : null;
-        out.append(dbAttr.getAliasedName(alias));
+        processColumnWithQuoteSqlIdentifiers(dbAttr, null);
     }
     
     protected void processColumnWithQuoteSqlIdentifiers(DbAttribute dbAttr, Expression pathExp)
throws IOException {

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java?rev=1057144&r1=1057143&r2=1057144&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/dba/hsqldb/HSQLDBAdapter.java
Mon Jan 10 10:29:27 2011
@@ -112,7 +112,7 @@ public class HSQLDBAdapter extends JdbcA
 
         StringBuilder buf = new StringBuilder();
 
-        buf.append("ALTER TABLE ").append(context.quoteString(srcName));
+        buf.append("ALTER TABLE ").append(srcName);
         buf.append(" ADD CONSTRAINT ");
 
         buf.append(context.quoteString(getSchemaName(source)));

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java?rev=1057144&r1=1057143&r2=1057144&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContexQuoteTest.java
Mon Jan 10 10:29:27 2011
@@ -22,7 +22,11 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.query.ObjectIdQuery;
+import org.apache.cayenne.query.RelationshipQuery;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.UpdateBatchQuery;
 import org.apache.cayenne.testdo.quotemap.QuoteAdress;
@@ -31,78 +35,115 @@ import org.apache.cayenne.unit.AccessSta
 import org.apache.cayenne.unit.CayenneCase;
 import org.apache.cayenne.unit.CayenneResources;
 
+public class DataContexQuoteTest extends CayenneCase {
 
-
-public class DataContexQuoteTest extends CayenneCase{
     private DataContext context;
 
     @Override
     protected AccessStack buildAccessStack() {
         return CayenneResources.getResources().getAccessStack(QUOTEMAP_ACCESS_STACK);
     }
-    
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         deleteTestData();
         context = createDataContext();
     }
-    
+
     public void testPrefetchQuote() throws Exception {
-        
-        // work with tables QuoteAdress and Quote_Person. 
-        // In this table parameter quoteSqlIdentifiers = true. 
-        
+
+        // work with tables QuoteAdress and Quote_Person.
+        // In this table parameter quoteSqlIdentifiers = true.
+
         QuoteAdress quoteAdress = (QuoteAdress) context.newObject("QuoteAdress");
         quoteAdress.setCity("city");
-        
+        quoteAdress.setGroup("324");
+
         Quote_Person quote_Person = (Quote_Person) context.newObject("Quote_Person");
         quote_Person.setSalary(10000);
         quote_Person.setName("Arcadi");
-        
+        quote_Person.setGroup("107324");
+        quote_Person.setAddressRel(quoteAdress);
+
         context.commitChanges();
-        
+
         SelectQuery q = new SelectQuery(QuoteAdress.class);
         List objects = context.performQuery(q);
         assertEquals(1, objects.size());
-        
-        
+
         SelectQuery qQuote_Person = new SelectQuery(Quote_Person.class);
         List objects2 = context.performQuery(qQuote_Person);
         assertEquals(1, objects2.size());
-        
+
         QuoteAdress quoteAdress2 = (QuoteAdress) context.newObject("QuoteAdress");
         quoteAdress2.setCity("city2");
-        
+
         Quote_Person quote_Person2 = (Quote_Person) context.newObject("Quote_Person");
         quote_Person2.setSalary(100);
         quote_Person2.setName("Name");
+        quote_Person2.setGroup("1111");
         quote_Person2.setDAte(new Date());
         
+        quote_Person2.setAddressRel(quoteAdress2);
+
         context.commitChanges();
-        
+
         DbEntity entity = getDomain().getEntityResolver().lookupObjEntity(
                 QuoteAdress.class).getDbEntity();
-        List idAttributes = Collections.singletonList(entity
-                    .getAttribute("City"));
-        List updatedAttributes = Collections.singletonList(entity
-                    .getAttribute("City"));
+        List idAttributes = Collections.singletonList(entity.getAttribute("City"));
+        List updatedAttributes = Collections.singletonList(entity.getAttribute("City"));
 
         UpdateBatchQuery updateQuery = new UpdateBatchQuery(
-                    entity,
-                    idAttributes,
-                    updatedAttributes,
-                    null,
-                    1);
-        
+                entity,
+                idAttributes,
+                updatedAttributes,
+                null,
+                1);
+
         List objects3 = context.performQuery(updateQuery);
         assertEquals(0, objects3.size());
-  
+
         SelectQuery qQuote_Person2 = new SelectQuery(Quote_Person.class);
         List objects4 = context.performQuery(qQuote_Person);
         assertEquals(2, objects4.size());
- 
-        
+
+        SelectQuery qQuote_Person3 = new SelectQuery(
+                Quote_Person.class,
+                ExpressionFactory.matchExp("salary", 100));
+        List objects5 = context.performQuery(qQuote_Person3);
+        assertEquals(1, objects5.size());
+
+        SelectQuery qQuote_Person4 = new SelectQuery(
+                Quote_Person.class,
+                ExpressionFactory.matchExp("group", "107324"));
+        List objects6 = context.performQuery(qQuote_Person4);
+        assertEquals(1, objects6.size());
+
+        SelectQuery quoteAdress1 = new SelectQuery(QuoteAdress.class, ExpressionFactory
+                .matchExp("group", "324"));
+        List objects7 = context.performQuery(quoteAdress1);
+        assertEquals(1, objects7.size());
+
+        ObjectIdQuery queryObjectId = new ObjectIdQuery(new ObjectId(
+                "QuoteAdress",
+                QuoteAdress.GROUP_PROPERTY,
+                "324"));
+
+        List objects8 = context.performQuery(queryObjectId);
+        assertEquals(1, objects8.size());
+
+        ObjectIdQuery queryObjectId2 = new ObjectIdQuery(new ObjectId(
+                "Quote_Person",
+                "GROUP",
+                "1111"));
+        List objects9 = context.performQuery(queryObjectId2);
+        assertEquals(1, objects9.size());
+
+        RelationshipQuery relationshipQuery = new RelationshipQuery(quote_Person2
+                .getObjectId(), "addressRel");
+        List objects10 = context.performQuery(relationshipQuery);
+        assertEquals(1, objects10.size());
     }
 
 }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java?rev=1057144&r1=1057143&r2=1057144&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
Mon Jan 10 10:29:27 2011
@@ -1,6 +1,7 @@
 package org.apache.cayenne.testdo.quotemap.auto;
 
 import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.testdo.quotemap.Quote_Person;
 
 /**
  * Class _QuoteAdress was generated by Cayenne.
@@ -11,8 +12,10 @@ import org.apache.cayenne.CayenneDataObj
 public abstract class _QuoteAdress extends CayenneDataObject {
 
     public static final String CITY_PROPERTY = "city";
+    public static final String GROUP_PROPERTY = "group";
+    public static final String PERSON_REL_PROPERTY = "personRel";
 
-    public static final String ADRES_ID_PK_COLUMN = "ADRES ID";
+    public static final String ADDRESS_ID_PK_COLUMN = "ADDRESS ID";
 
     public void setCity(String city) {
         writeProperty("city", city);
@@ -21,4 +24,20 @@ public abstract class _QuoteAdress exten
         return (String)readProperty("city");
     }
 
+    public void setGroup(String group) {
+        writeProperty("group", group);
+    }
+    public String getGroup() {
+        return (String)readProperty("group");
+    }
+
+    public void setPersonRel(Quote_Person personRel) {
+        setToOneTarget("personRel", personRel, true);
+    }
+
+    public Quote_Person getPersonRel() {
+        return (Quote_Person)readProperty("personRel");
+    }
+
+
 }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java?rev=1057144&r1=1057143&r2=1057144&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java
Mon Jan 10 10:29:27 2011
@@ -3,6 +3,7 @@ package org.apache.cayenne.testdo.quotem
 import java.util.Date;
 
 import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.testdo.quotemap.QuoteAdress;
 
 /**
  * Class _Quote_Person was generated by Cayenne.
@@ -12,13 +13,23 @@ import org.apache.cayenne.CayenneDataObj
  */
 public abstract class _Quote_Person extends CayenneDataObject {
 
+    public static final String ADDRESS_ID_PROPERTY = "addressId";
     public static final String D_ATE_PROPERTY = "dAte";
     public static final String F_ULL_NAME_PROPERTY = "fULL_name";
+    public static final String GROUP_PROPERTY = "group";
     public static final String NAME_PROPERTY = "name";
     public static final String SALARY_PROPERTY = "salary";
+    public static final String ADDRESS_REL_PROPERTY = "addressRel";
 
     public static final String ID_PK_COLUMN = "id";
 
+    public void setAddressId(Integer addressId) {
+        writeProperty("addressId", addressId);
+    }
+    public Integer getAddressId() {
+        return (Integer)readProperty("addressId");
+    }
+
     public void setDAte(Date dAte) {
         writeProperty("dAte", dAte);
     }
@@ -33,6 +44,13 @@ public abstract class _Quote_Person exte
         return (String)readProperty("fULL_name");
     }
 
+    public void setGroup(String group) {
+        writeProperty("group", group);
+    }
+    public String getGroup() {
+        return (String)readProperty("group");
+    }
+
     public void setName(String name) {
         writeProperty("name", name);
     }
@@ -47,4 +65,13 @@ public abstract class _Quote_Person exte
         return (Integer)readProperty("salary");
     }
 
+    public void setAddressRel(QuoteAdress addressRel) {
+        setToOneTarget("addressRel", addressRel, true);
+    }
+
+    public QuoteAdress getAddressRel() {
+        return (QuoteAdress)readProperty("addressRel");
+    }
+
+
 }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java?rev=1057144&r1=1057143&r2=1057144&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
Mon Jan 10 10:29:27 2011
@@ -47,7 +47,6 @@ import org.apache.commons.logging.LogFac
  * databases support different feature sets that need to be tested differently. Many
  * things implemented in subclasses may become future candidates for inclusion in the
  * corresponding adapter code.
- * 
  */
 public class AccessStackAdapter {
 
@@ -97,13 +96,21 @@ public class AccessStackAdapter {
             }
 
             Object tableName = entry.getKey();
+            DbEntity entity = map.getDbEntity(tableName.toString());
+            if (entity == null) {
+                continue;
+            }
+            boolean status = entity.getDataMap() != null
+                    && entity.getDataMap().isQuotingSQLIdentifiers();
+            QuotingStrategy strategy = getAdapter().getQuotingStrategy(status);
+
             for (String constraint : constraints) {
                 StringBuilder drop = new StringBuilder();
-                drop
-                        .append("ALTER TABLE ")
-                        .append(tableName)
-                        .append(" DROP CONSTRAINT ")
-                        .append(constraint);
+
+                drop.append("ALTER TABLE ")
+                .append(strategy.quoteFullyQualifiedName(entity))
+                .append(" DROP CONSTRAINT ")
+                .append(constraint);
                 executeDDL(conn, drop.toString());
             }
         }
@@ -125,7 +132,6 @@ public class AccessStackAdapter {
     public void createdTables(Connection con, DataMap map) throws Exception {
 
     }
-    
 
     public boolean supportsStoredProcedures() {
         return false;
@@ -301,6 +307,10 @@ public class AccessStackAdapter {
             if (entity == null) {
                 continue;
             }
+            boolean status = entity.getDataMap() != null
+            && entity.getDataMap().isQuotingSQLIdentifiers();
+            QuotingStrategy strategy = getAdapter().getQuotingStrategy(status);
+
 
             // Get all constraints for the table
             ResultSet rs = metadata.getExportedKeys(entity.getCatalog(), entity
@@ -318,7 +328,7 @@ public class AccessStackAdapter {
                             constraintMap.put(fkTable, constraints);
                         }
 
-                        constraints.add(fk);
+                        constraints.add(strategy.quoteString(fk));
                     }
                 }
             }
@@ -333,7 +343,7 @@ public class AccessStackAdapter {
     public QuotingStrategy getQuotingStrategy(boolean status) {
         return adapter.getQuotingStrategy(status);
     }
-    
+
     public boolean supportsNullBoolean() {
         return true;
     }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/resources/quotemap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/resources/quotemap.map.xml?rev=1057144&r1=1057143&r2=1057144&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/resources/quotemap.map.xml
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/resources/quotemap.map.xml
Mon Jan 10 10:29:27 2011
@@ -5,24 +5,38 @@
   project-version="3.0.0.1">
 	<property name="defaultPackage" value="org.apache.cayenne.testdo.quotemap"/>
 	<property name="quoteSqlIdentifiers" value="true"/>
-	<db-entity name="QUOTE_ADRESS">
-		<db-attribute name="ADRES ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+	<db-entity name="QUOTE_ADDRESS">
+		<db-attribute name="ADDRESS ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="City" type="VARCHAR" length="200"/>
+		<db-attribute name="group" type="VARCHAR" length="100"/>
 	</db-entity>
 	<db-entity name="quote Person">
 		<db-attribute name="DAte" type="DATE"/>
 		<db-attribute name="FULL name" type="VARCHAR" length="300"/>
+		<db-attribute name="GROUP" type="VARCHAR" length="100"/>
 		<db-attribute name="NAME" type="VARCHAR" length="100"/>
+		<db-attribute name="address_id" type="INTEGER"/>
 		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="salary" type="INTEGER"/>
 	</db-entity>
-	<obj-entity name="QuoteAdress" className="org.apache.cayenne.testdo.quotemap.QuoteAdress"
dbEntityName="QUOTE_ADRESS">
+	<obj-entity name="QuoteAdress" className="org.apache.cayenne.testdo.quotemap.QuoteAdress"
dbEntityName="QUOTE_ADDRESS">
 		<obj-attribute name="city" type="java.lang.String" db-attribute-path="City"/>
+		<obj-attribute name="group" type="java.lang.String" db-attribute-path="group"/>
 	</obj-entity>
 	<obj-entity name="Quote_Person" className="org.apache.cayenne.testdo.quotemap.Quote_Person"
dbEntityName="quote Person">
+		<obj-attribute name="addressId" type="java.lang.Integer" db-attribute-path="address_id"/>
 		<obj-attribute name="dAte" type="java.util.Date" db-attribute-path="DAte"/>
 		<obj-attribute name="fULL_name" type="java.lang.String" db-attribute-path="FULL name"/>
+		<obj-attribute name="group" type="java.lang.String" db-attribute-path="GROUP"/>
 		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
 		<obj-attribute name="salary" type="java.lang.Integer" db-attribute-path="salary"/>
 	</obj-entity>
+	<db-relationship name="personRel" source="QUOTE_ADDRESS" target="quote Person" toMany="false">
+		<db-attribute-pair source="ADDRESS ID" target="address_id"/>
+	</db-relationship>
+	<db-relationship name="addressRel" source="quote Person" target="QUOTE_ADDRESS" toMany="false">
+		<db-attribute-pair source="address_id" target="ADDRESS ID"/>
+	</db-relationship>
+	<obj-relationship name="personRel" source="QuoteAdress" target="Quote_Person" deleteRule="Nullify"
db-relationship-path="personRel"/>
+	<obj-relationship name="addressRel" source="Quote_Person" target="QuoteAdress" deleteRule="Nullify"
db-relationship-path="addressRel"/>
 </data-map>



Mime
View raw message