DATAJPA-665 - Add QueryDslJpaRepository.exists(…) method wich accepts a Querydsl predicate.
Introduced QueryDslJpaRepository.exists(Predicate) method to QueryDslJpaRepository. Related ticket: DATACMNS-636. Original pull request: #131.
This commit is contained in:
committed by
Oliver Gierke
parent
e8436d5de7
commit
2a05e5e1c9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
* Copyright 2008-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,6 +46,7 @@ import com.mysema.query.types.path.PathBuilder;
|
||||
* {@link QueryDslPredicateExecutor}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements
|
||||
QueryDslPredicateExecutor<T> {
|
||||
@@ -142,6 +143,13 @@ public class QueryDslJpaRepository<T, ID extends Serializable> extends SimpleJpa
|
||||
return createQuery(predicate).count();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.querydsl.QueryDslPredicateExecutor#exists(com.mysema.query.types.Predicate)
|
||||
*/
|
||||
public boolean exists(Predicate predicate) {
|
||||
return createQuery(predicate).exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link JPQLQuery} for the given {@link Predicate}.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2014 the original author or authors.
|
||||
* Copyright 2008-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -325,4 +325,15 @@ public class QueryDslJpaRepositoryTests {
|
||||
assertThat(users, hasSize(3));
|
||||
assertThat(users, hasItems(dave, carter, oliver));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-665
|
||||
*/
|
||||
@Test
|
||||
public void shouldSupportExistsWithPredicate() throws Exception {
|
||||
|
||||
assertThat(repository.exists(user.firstname.eq("Dave")), is(true));
|
||||
assertThat(repository.exists(user.firstname.eq("Unknown")), is(false));
|
||||
assertThat(repository.exists((Predicate) null), is(true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user