diff --git a/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java index 7fa6812de..a66b7c7ab 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepository.java @@ -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 extends SimpleJpaRepository implements QueryDslPredicateExecutor { @@ -142,6 +143,13 @@ public class QueryDslJpaRepository 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}. * diff --git a/src/test/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepositoryTests.java index 00731dcc2..335440dbe 100644 --- a/src/test/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/support/QueryDslJpaRepositoryTests.java @@ -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)); + } }