mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-27 21:01:15 +08:00
Added iterate test
This commit is contained in:
parent
e27ace0f2d
commit
e993b80737
@ -138,8 +138,7 @@ public class MongodbQuery<K> implements SimpleQuery<MongodbQuery<K>>,
|
||||
|
||||
@Override
|
||||
public List<K> listDistinct() {
|
||||
queryMixin.setDistinct(true);
|
||||
return list();
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -164,8 +163,7 @@ public class MongodbQuery<K> implements SimpleQuery<MongodbQuery<K>>,
|
||||
|
||||
@Override
|
||||
public long countDistinct() {
|
||||
queryMixin.setDistinct(true);
|
||||
return count();
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private DBObject createQuery() {
|
||||
|
||||
@ -8,6 +8,7 @@ package com.mysema.query.mongodb;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
@ -88,6 +89,36 @@ public class MongodbQueryTest {
|
||||
assertQuery(user.firstName.matches("Jaakko").not(), u3, u4, u2);
|
||||
}
|
||||
|
||||
//This is not supported yet
|
||||
// @Test
|
||||
// public void testUniqueResult() {
|
||||
//
|
||||
// addUser("Dille", "Duplikaatti");
|
||||
// addUser("Dille", "Duplikaatti");
|
||||
//
|
||||
// assertEquals(2, where(user.firstName.eq("Dille")).count());
|
||||
// assertEquals(1, where(user.firstName.eq("Dille")).countDistinct());
|
||||
//
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testIterate() {
|
||||
|
||||
User a = addUser("A", "A");
|
||||
User b = addUser("A1", "B");
|
||||
User c = addUser("A2", "C");
|
||||
|
||||
Iterator<User> i = where(user.firstName.startsWith("A"))
|
||||
.orderBy(user.firstName.asc())
|
||||
.iterate();
|
||||
|
||||
assertEquals(a, i.next());
|
||||
assertEquals(b, i.next());
|
||||
assertEquals(c, i.next());
|
||||
assertEquals(false, i.hasNext());
|
||||
|
||||
}
|
||||
|
||||
private void assertQuery(Predicate e, User ... expected) {
|
||||
assertQuery(where(e).orderBy(user.lastName.asc(), user.firstName.asc()), expected );
|
||||
}
|
||||
@ -102,7 +133,7 @@ public class MongodbQueryTest {
|
||||
}
|
||||
|
||||
private void assertQuery(MongodbQuery<User> query, User ... expected ) {
|
||||
System.out.println(query.toString());
|
||||
//System.out.println(query.toString());
|
||||
List<User> results = query.list();
|
||||
|
||||
assertNotNull(results);
|
||||
|
||||
@ -5,8 +5,12 @@
|
||||
*/
|
||||
package com.mysema.query.mongodb.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.mysema.query.types.PathMetadataFactory;
|
||||
import com.mysema.query.types.path.DatePath;
|
||||
import com.mysema.query.types.path.EntityPathBase;
|
||||
import com.mysema.query.types.path.NumberPath;
|
||||
import com.mysema.query.types.path.StringPath;
|
||||
|
||||
public class QUser extends EntityPathBase<User> {
|
||||
@ -21,4 +25,6 @@ public class QUser extends EntityPathBase<User> {
|
||||
public final StringPath firstName = createString("firstName");
|
||||
public final StringPath lastName = createString("lastName");
|
||||
|
||||
public final DatePath<Date> created = createDate("date", Date.class);
|
||||
public final NumberPath<Integer> age = createNumber("age", Integer.class);
|
||||
}
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
*/
|
||||
package com.mysema.query.mongodb.domain;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import com.google.code.morphia.annotations.Entity;
|
||||
@ -18,11 +20,20 @@ public class User {
|
||||
String firstName;
|
||||
String lastName;
|
||||
|
||||
Date created;
|
||||
|
||||
int age;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String firstName, String lastName) {
|
||||
this.firstName = firstName; this.lastName = lastName;
|
||||
this.created = new Date();
|
||||
}
|
||||
|
||||
public User(String firstName, String lastName, int age, Date created) {
|
||||
this.firstName = firstName; this.lastName = lastName; this.age = age; this.created = created;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user