cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1053880 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test: java/org/apache/cayenne/access/ java/org/apache/cayenne/testdo/quotemap/auto/ java/org/apache/cayenne/unit/ resources/
Date Thu, 30 Dec 2010 12:58:23 GMT
Author: oltka
Date: Thu Dec 30 12:58:23 2010
New Revision: 1053880

URL: http://svn.apache.org/viewvc?rev=1053880&view=rev
Log:
CAY-1509 added tests, fixed problem with quote in ALTER TABLE ... DROP CONSTRAINT ...

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quoted-identifiers.map.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java?rev=1053880&r1=1053879&r2=1053880&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/QuotedIdentifiersTest.java
Thu Dec 30 12:58:23 2010
@@ -23,8 +23,12 @@ import java.util.Date;
 import java.util.List;
 
 import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.di.Inject;
+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.test.jdbc.DBHelper;
@@ -52,11 +56,13 @@ public class QuotedIdentifiersTest exten
 
         QuoteAdress quoteAdress = context.newObject(QuoteAdress.class);
         quoteAdress.setCity("city");
+        quoteAdress.setGroup("324");
 
         Quote_Person quote_Person = context.newObject(Quote_Person.class);
         quote_Person.setSalary(10000);
         quote_Person.setName("Arcadi");
-
+        quote_Person.setGroup("107324");
+        
         context.commitChanges();
 
         SelectQuery q = new SelectQuery(QuoteAdress.class);
@@ -73,8 +79,10 @@ public class QuotedIdentifiersTest exten
         Quote_Person quote_Person2 = context.newObject(Quote_Person.class);
         quote_Person2.setSalary(100);
         quote_Person2.setName("Name");
+        quote_Person2.setGroup("1111");
         quote_Person2.setDAte(new Date());
-
+        quote_Person2.setAddress_Rel(quoteAdress);
+        
         context.commitChanges();
 
         DbEntity entity = context
@@ -97,6 +105,38 @@ public class QuotedIdentifiersTest exten
         SelectQuery qQuote_Person2 = new SelectQuery(Quote_Person.class);
         List objects4 = context.performQuery(qQuote_Person2);
         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(),
"address_Rel");
+        List objects10 = context.performQuery(relationshipQuery);
+        assertEquals(1, objects10.size());
+        
     }
-
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java?rev=1053880&r1=1053879&r2=1053880&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_QuoteAdress.java
Thu Dec 30 12:58:23 2010
@@ -11,8 +11,9 @@ 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 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 +22,11 @@ public abstract class _QuoteAdress exten
         return (String)readProperty("city");
     }
 
+    public void setGroup(String group) {
+        writeProperty("group", group);
+    }
+    public String getGroup() {
+        return (String)readProperty("group");
+    }
+
 }

Modified: cayenne/main/trunk/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/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java?rev=1053880&r1=1053879&r2=1053880&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/testdo/quotemap/auto/_Quote_Person.java
Thu Dec 30 12:58:23 2010
@@ -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.
@@ -14,8 +15,10 @@ public abstract class _Quote_Person exte
 
     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 = "address_Rel";
 
     public static final String ID_PK_COLUMN = "id";
 
@@ -33,6 +36,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 +57,13 @@ public abstract class _Quote_Person exte
         return (Integer)readProperty("salary");
     }
 
+    public void setAddress_Rel(QuoteAdress address_Rel) {
+        setToOneTarget("address_Rel", address_Rel, true);
+    }
+
+    public QuoteAdress getAddress_Rel() {
+        return (QuoteAdress)readProperty("address_Rel");
+    }
+
+
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java?rev=1053880&r1=1053879&r2=1053880&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/AccessStackAdapter.java
Thu Dec 30 12:58:23 2010
@@ -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/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quoted-identifiers.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quoted-identifiers.map.xml?rev=1053880&r1=1053879&r2=1053880&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quoted-identifiers.map.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/resources/quoted-identifiers.map.xml
Thu Dec 30 12:58:23 2010
@@ -8,21 +8,34 @@
 	<db-entity name="QUOTED_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="QUOTED_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="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="QUOTED_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="QUOTED_ADDRESS" toMany="false">
+		<db-attribute-pair source="address_id" target="ADDRESS ID"/>
+	</db-relationship>
+	<obj-relationship name="person_Rel" source="QuoteAdress" target="Quote_Person" deleteRule="Nullify"
db-relationship-path="personRel"/>
+	<obj-relationship name="address_Rel" source="Quote_Person" target="QuoteAdress" deleteRule="Nullify"
db-relationship-path="addressRel"/>
 </data-map>



Mime
View raw message