cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1099180 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/exp/ test/java/org/apache/cayenne/exp/ test/java/org/apache/cayenne/query/
Date Tue, 03 May 2011 18:36:34 GMT
Author: aadamchik
Date: Tue May  3 18:36:33 2011
New Revision: 1099180

URL: http://svn.apache.org/viewvc?rev=1099180&view=rev
Log:
CAY-1563 CayenneCase unit tests conversion(3)

patches by Dzmitry Kazimirchyk:
ExpressionFactoryTest (+ refactoring of test locations)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java?rev=1099180&r1=1099179&r2=1099180&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/ExpressionFactory.java
Tue May  3 18:36:33 2011
@@ -176,7 +176,7 @@ public class ExpressionFactory {
      * all lists into LIST expressions. Applied only in path expressions.
      */
     protected static Object wrapPathOperand(Object op) {
-        if (op instanceof Collection) {
+        if (op instanceof Collection<?>) {
             return new ASTList((Collection<?>) op);
         }
         else if (op instanceof Object[]) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java?rev=1099180&r1=1099179&r2=1099180&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
Tue May  3 18:36:33 2011
@@ -20,26 +20,28 @@
 package org.apache.cayenne.exp;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
-import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.Persistent;
+import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.parser.ASTLike;
 import org.apache.cayenne.exp.parser.ASTLikeIgnoreCase;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.testdo.testmap.Artist;
 import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
-public class ExpressionFactoryTest extends CayenneCase {
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ExpressionFactoryTest extends ServerCase {
 
-    // non-existent type
-    private static final int badType = -50;
+    @Inject
+    private ObjectContext context;
 
     public void testExpressionOfBadType() throws Exception {
+
+        // non existing type
+        int badType = -50;
+
         try {
             ExpressionFactory.expressionOfType(badType);
             fail();
@@ -78,7 +80,7 @@ public class ExpressionFactoryTest exten
         Expression path = (Expression) exp.getOperand(0);
         assertEquals(Expression.OBJ_PATH, path.getType());
     }
-    
+
     public void testNotBetweenDbExp() throws Exception {
         Object v1 = new Object();
         Object v2 = new Object();
@@ -153,9 +155,6 @@ public class ExpressionFactoryTest exten
     }
 
     public void testInExp1() throws Exception {
-        Object[] v = new Object[] {
-                "a", "b"
-        };
         Expression exp = ExpressionFactory.inExp("abc", "a", "b");
         assertEquals(Expression.IN, exp.getType());
     }
@@ -173,7 +172,7 @@ public class ExpressionFactoryTest exten
         Expression exp = ExpressionFactory.inExp("abc", v);
         assertEquals(Expression.FALSE, exp.getType());
     }
-    
+
     public void testLikeExp() throws Exception {
         String v = "abc";
         Expression exp = ExpressionFactory.likeExp("abc", v);
@@ -191,12 +190,12 @@ public class ExpressionFactoryTest exten
         Expression path = (Expression) exp.getOperand(0);
         assertEquals(Expression.DB_PATH, path.getType());
     }
-    
+
     public void testLikeExpEscape() throws Exception {
         String v = "abc";
         Expression exp = ExpressionFactory.likeExp("=abc", v, '=');
         assertEquals(Expression.LIKE, exp.getType());
-        
+
         assertEquals('=', ((ASTLike) exp).getEscapeChar());
 
         Expression path = (Expression) exp.getOperand(0);
@@ -212,7 +211,7 @@ public class ExpressionFactoryTest exten
         Expression path = (Expression) exp.getOperand(0);
         assertEquals(Expression.OBJ_PATH, path.getType());
     }
-    
+
     public void testLikeIgnoreCaseExpEscape() throws Exception {
         String v = "abc";
         Expression exp = ExpressionFactory.likeIgnoreCaseExp("=abc", v, '=');
@@ -237,7 +236,7 @@ public class ExpressionFactoryTest exten
         Expression exp = ExpressionFactory.notLikeIgnoreCaseExp("abc", v);
         assertEquals(Expression.NOT_LIKE_IGNORE_CASE, exp.getType());
     }
-    
+
     // testing CAY-941 bug
     public void testLikeExpNull() throws Exception {
         Expression exp = ExpressionFactory.likeExp("abc", null);
@@ -247,92 +246,50 @@ public class ExpressionFactoryTest exten
         assertEquals(Expression.OBJ_PATH, path.getType());
         assertNull(exp.getOperand(1));
     }
-    
-    //CAY-416
+
+    // CAY-416
     public void testCollectionMatch() {
-        ObjectContext dc = createDataContext();
-        Artist artist = dc.newObject(Artist.class);
-        Painting p1 = dc.newObject(Painting.class), p2 = dc.newObject(Painting.class), 
-            p3 = dc.newObject(Painting.class);
+        Artist artist = context.newObject(Artist.class);
+        Painting p1 = context.newObject(Painting.class), p2 = context
+                .newObject(Painting.class), p3 = context.newObject(Painting.class);
         p1.setPaintingTitle("p1");
         p2.setPaintingTitle("p2");
         p3.setPaintingTitle("p3");
         artist.addToPaintingArray(p1);
         artist.addToPaintingArray(p2);
-        
+
         assertTrue(ExpressionFactory.matchExp("paintingArray", p1).match(artist));
         assertFalse(ExpressionFactory.matchExp("paintingArray", p3).match(artist));
         assertFalse(ExpressionFactory.noMatchExp("paintingArray", p1).match(artist));
         assertTrue(ExpressionFactory.noMatchExp("paintingArray", p3).match(artist));
-        
-        assertTrue(ExpressionFactory.matchExp("paintingArray.paintingTitle", "p1").match(artist));
-        assertFalse(ExpressionFactory.matchExp("paintingArray.paintingTitle", "p3").match(artist));
-        assertFalse(ExpressionFactory.noMatchExp("paintingArray.paintingTitle", "p1").match(artist));
-        assertTrue(ExpressionFactory.noMatchExp("paintingArray.paintingTitle", "p3").match(artist));
-        
+
+        assertTrue(ExpressionFactory.matchExp("paintingArray.paintingTitle", "p1").match(
+                artist));
+        assertFalse(ExpressionFactory
+                .matchExp("paintingArray.paintingTitle", "p3")
+                .match(artist));
+        assertFalse(ExpressionFactory
+                .noMatchExp("paintingArray.paintingTitle", "p1")
+                .match(artist));
+        assertTrue(ExpressionFactory
+                .noMatchExp("paintingArray.paintingTitle", "p3")
+                .match(artist));
+
         assertTrue(ExpressionFactory.inExp("paintingTitle", "p1").match(p1));
         assertFalse(ExpressionFactory.notInExp("paintingTitle", "p3").match(p3));
     }
-    
-    public void testMatchObject() {
-        ObjectContext dc = createDataContext();
-        
-        Artist a1 = dc.newObject(Artist.class);
-        a1.setArtistName("a1");
-        Artist a2 = dc.newObject(Artist.class);
-        a2.setArtistName("a2");
-        Artist a3 = dc.newObject(Artist.class);
-        a3.setArtistName("a3");
-        dc.commitChanges();
-        
-        SelectQuery query = new SelectQuery(Artist.class);
-        
-        query.setQualifier(ExpressionFactory.matchExp(a2));
-        Object res = Cayenne.objectForQuery(dc, query);//exception if >1 result
-        assertSame(res, a2);
-        assertTrue(query.getQualifier().match(res));
-        
-        query.setQualifier(ExpressionFactory.matchAnyExp(a1, a3));
-        query.addOrdering("artistName", SortOrder.ASCENDING);
-        List<Persistent> list = dc.performQuery(query);
-        assertEquals(list.size(), 2);
-        assertSame(list.get(0), a1);
-        assertSame(list.get(1), a3);
-        assertTrue(query.getQualifier().match(a1));
-        assertTrue(query.getQualifier().match(a3));
-        
-        assertEquals(query.getQualifier(), 
-                ExpressionFactory.matchAnyExp(Arrays.asList(a1, a3)));
-    }
-    
+
     public void testIn() {
-        ObjectContext dc = createDataContext();
-        
-        Artist a1 = dc.newObject(Artist.class);
+        Artist a1 = context.newObject(Artist.class);
         a1.setArtistName("a1");
-        Painting p1 = dc.newObject(Painting.class);
+        Painting p1 = context.newObject(Painting.class);
         p1.setPaintingTitle("p1");
-        Painting p2 = dc.newObject(Painting.class);
+        Painting p2 = context.newObject(Painting.class);
         p2.setPaintingTitle("p2");
         a1.addToPaintingArray(p1);
         a1.addToPaintingArray(p2);
-        dc.commitChanges();
-        
+
         Expression in = ExpressionFactory.inExp("paintingArray", p1);
         assertTrue(in.match(a1));
     }
-    
-    /**
-     * Tests INs with more than 1000 elements
-     */
-    public void testLongIn() {
-        //not all adapters strip INs, so we just make sure query with such qualifier fires
OK
-        Object[] numbers = new String[2009];
-        for (int i = 0; i < numbers.length; i++) {
-            numbers[i] = "" + i;
-        }
-        
-        SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.inExp("artistName",
numbers));
-        createDataContext().performQuery(query);
-    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java?rev=1099180&r1=1099179&r2=1099180&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/query/SelectQueryTest.java
Tue May  3 18:36:33 2011
@@ -19,11 +19,14 @@
 
 package org.apache.cayenne.query;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.cayenne.Cayenne;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.Persistent;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
@@ -47,13 +50,13 @@ import org.apache.cayenne.unit.di.server
 public class SelectQueryTest extends ServerCase {
 
     @Inject
-    protected ObjectContext context;
+    private ObjectContext context;
 
     @Inject
-    protected DBHelper dbHelper;
+    private DBHelper dbHelper;
 
     @Inject
-    protected AccessStackAdapter accessStackAdapter;
+    private AccessStackAdapter accessStackAdapter;
 
     @Override
     protected void setUpAfterInjection() throws Exception {
@@ -99,7 +102,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         query.setFetchLimit(7);
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertNotNull(objects);
         assertEquals(7, objects.size());
     }
@@ -125,7 +128,7 @@ public class SelectQueryTest extends Ser
         DbEntity artistDbEntity = context.getEntityResolver().getDbEntity("ARTIST");
 
         SelectQuery query = new SelectQuery(artistDbEntity);
-        List results = context.performQuery(query);
+        List<?> results = context.performQuery(query);
 
         assertEquals(20, results.size());
         assertTrue(results.get(0) instanceof DataRow);
@@ -149,12 +152,12 @@ public class SelectQueryTest extends Ser
         query.setQualifier(Expression.fromString("db:ARTIST_ID > 3"));
         query.setFetchOffset(5);
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         int size = objects.size();
 
         SelectQuery sizeQ = new SelectQuery(Artist.class);
         sizeQ.setQualifier(Expression.fromString("db:ARTIST_ID > 3"));
-        List objects1 = context.performQuery(sizeQ);
+        List<?> objects1 = context.performQuery(sizeQ);
         int sizeAll = objects1.size();
         assertEquals(size, sizeAll - 5);
     }
@@ -164,21 +167,21 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         query.setQualifier(Expression.fromString("db:ARTIST_ID > 3"));
         query.setFetchLimit(7);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(7, objects.size());
     }
 
     public void testSelectAllObjectsRootEntityName() throws Exception {
         createArtistsDataSet();
         SelectQuery query = new SelectQuery("Artist");
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(20, objects.size());
     }
 
     public void testSelectAllObjectsRootClass() throws Exception {
         createArtistsDataSet();
         SelectQuery query = new SelectQuery(Artist.class);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(20, objects.size());
     }
 
@@ -189,7 +192,7 @@ public class SelectQueryTest extends Ser
                 .lookupObjEntity(Artist.class);
         SelectQuery query = new SelectQuery(artistEntity);
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(20, objects.size());
     }
 
@@ -198,7 +201,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.likeExp("artistName", "artist1");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
     }
 
@@ -207,7 +210,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.notLikeExp("artistName", "artist11%");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(19, objects.size());
     }
 
@@ -218,7 +221,7 @@ public class SelectQueryTest extends Ser
                 "artistName",
                 "aRtIsT11%");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(19, objects.size());
     }
 
@@ -231,7 +234,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.likeExp("artistName", "aRtIsT%");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(0, objects.size());
     }
 
@@ -240,7 +243,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.likeExp("artistName", "artist11%");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
     }
 
@@ -251,7 +254,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         query.andQualifier(ExpressionFactory.likeExp("artistName", "=_%", '='));
 
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
     }
 
@@ -260,17 +263,19 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.likeExp("artistName", "artist1%");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(11, objects.size());
     }
 
-    /** Test how "like ignore case" works when using uppercase parameter. */
+    /**
+     * Test how "like ignore case" works when using uppercase parameter.
+     */
     public void testSelectLikeIgnoreCaseObjects1() throws Exception {
         createArtistsDataSet();
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.likeIgnoreCaseExp("artistName", "ARTIST%");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(20, objects.size());
     }
 
@@ -280,7 +285,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.likeIgnoreCaseExp("artistName", "artist%");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(20, objects.size());
     }
 
@@ -291,39 +296,39 @@ public class SelectQueryTest extends Ser
             SelectQuery query = new SelectQuery(ClobTestEntity.class);
             Expression qual = ExpressionFactory.likeIgnoreCaseExp("clobCol", "clob%");
             query.setQualifier(qual);
-            List objects = context.performQuery(query);
+            List<?> objects = context.performQuery(query);
             assertEquals(2, objects.size());
         }
     }
-    
+
     public void testSelectEqualsClob() throws Exception {
         if (accessStackAdapter.supportsLobs()) {
             createClobDataSet();
             SelectQuery query = new SelectQuery(ClobTestEntity.class);
             Expression qual = ExpressionFactory.matchExp("clobCol", "clob1");
             query.setQualifier(qual);
-            List objects = context.performQuery(query);
+            List<?> objects = context.performQuery(query);
             assertEquals(1, objects.size());
         }
     }
-    
+
     public void testSelectNotEqualsClob() throws Exception {
         if (accessStackAdapter.supportsLobs()) {
             createClobDataSet();
             SelectQuery query = new SelectQuery(ClobTestEntity.class);
             Expression qual = ExpressionFactory.noMatchExp("clobCol", "clob1");
             query.setQualifier(qual);
-            List objects = context.performQuery(query);
+            List<?> objects = context.performQuery(query);
             assertEquals(1, objects.size());
         }
     }
-    
+
     public void testSelectIn() throws Exception {
         createArtistsDataSet();
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = Expression.fromString("artistName in ('artist1', 'artist2')");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
     }
 
@@ -335,7 +340,7 @@ public class SelectQueryTest extends Ser
         query = query.queryWithParameters(Collections.singletonMap("list", new Object[] {
                 "artist1", "artist2"
         }));
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(2, objects.size());
     }
 
@@ -347,7 +352,7 @@ public class SelectQueryTest extends Ser
         query = query.queryWithParameters(Collections.singletonMap(
                 "list",
                 new Object[] {}));
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(0, objects.size());
     }
 
@@ -359,7 +364,7 @@ public class SelectQueryTest extends Ser
         query = query.queryWithParameters(Collections.singletonMap(
                 "list",
                 new Object[] {}));
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(20, objects.size());
     }
 
@@ -368,7 +373,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.inExp("artistName");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(0, objects.size());
     }
 
@@ -377,7 +382,7 @@ public class SelectQueryTest extends Ser
         SelectQuery query = new SelectQuery(Artist.class);
         Expression qual = ExpressionFactory.notInExp("artistName");
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(20, objects.size());
     }
 
@@ -387,7 +392,7 @@ public class SelectQueryTest extends Ser
         Expression qual = ExpressionFactory.expTrue();
         qual = qual.andExp(ExpressionFactory.matchExp("artistName", "artist1"));
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
     }
 
@@ -398,7 +403,7 @@ public class SelectQueryTest extends Ser
         qual = qual.notExp();
         qual = qual.orExp(ExpressionFactory.matchExp("artistName", "artist1"));
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
     }
 
@@ -408,7 +413,7 @@ public class SelectQueryTest extends Ser
         Expression qual = ExpressionFactory.expFalse();
         qual = qual.andExp(ExpressionFactory.matchExp("artistName", "artist1"));
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(0, objects.size());
     }
 
@@ -418,7 +423,7 @@ public class SelectQueryTest extends Ser
         Expression qual = ExpressionFactory.expFalse();
         qual = qual.orExp(ExpressionFactory.matchExp("artistName", "artist1"));
         query.setQualifier(qual);
-        List objects = context.performQuery(query);
+        List<?> objects = context.performQuery(query);
         assertEquals(1, objects.size());
     }
 
@@ -541,4 +546,52 @@ public class SelectQueryTest extends Ser
         query.addPrefetch("toGallery");
         context.performQuery(query);
     }
+
+    public void testSelect_MatchObject() {
+
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("a1");
+        Artist a2 = context.newObject(Artist.class);
+        a2.setArtistName("a2");
+        Artist a3 = context.newObject(Artist.class);
+        a3.setArtistName("a3");
+        context.commitChanges();
+
+        SelectQuery query = new SelectQuery(Artist.class);
+
+        query.setQualifier(ExpressionFactory.matchExp(a2));
+        Object res = Cayenne.objectForQuery(context, query);// exception if >1 result
+        assertSame(res, a2);
+        assertTrue(query.getQualifier().match(res));
+
+        query.setQualifier(ExpressionFactory.matchAnyExp(a1, a3));
+        query.addOrdering("artistName", SortOrder.ASCENDING);
+        List<Persistent> list = context.performQuery(query);
+        assertEquals(list.size(), 2);
+        assertSame(list.get(0), a1);
+        assertSame(list.get(1), a3);
+        assertTrue(query.getQualifier().match(a1));
+        assertTrue(query.getQualifier().match(a3));
+
+        assertEquals(query.getQualifier(), ExpressionFactory.matchAnyExp(Arrays.asList(
+                a1,
+                a3)));
+    }
+
+    /**
+     * Tests INs with more than 1000 elements
+     */
+    public void testSelectLongIn() {
+        // not all adapters strip INs, so we just make sure query with such qualifier
+        // fires OK
+        Object[] numbers = new String[2009];
+        for (int i = 0; i < numbers.length; i++) {
+            numbers[i] = "" + i;
+        }
+
+        SelectQuery query = new SelectQuery(Artist.class, ExpressionFactory.inExp(
+                "artistName",
+                numbers));
+        context.performQuery(query);
+    }
 }



Mime
View raw message