diff --git a/gradle.properties b/gradle.properties index 9d65effe..59f30dc7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ junitVersion=4.8.2 gemfireVersion=7.0.1 spring.range="[3.2.0, 4.0.0)" springVersion=3.2.2.RELEASE -springDataCommonsVersion=1.6.0.BUILD-SNAPSHOT +springDataCommonsVersion=1.5.1.RELEASE log4jVersion=1.2.16 hamcrestVersion=1.2.1 version=1.3.0.BUILD-SNAPSHOT diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireQueryCreator.java b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireQueryCreator.java index 51d2ba27..0d28e039 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireQueryCreator.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireQueryCreator.java @@ -47,7 +47,7 @@ class GemfireQueryCreator extends AbstractQueryCreator super(tree); - this.query = new QueryBuilder(entity,tree); + this.query = new QueryBuilder(entity); this.indexes = new IndexProvider(); } diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireRepositoryQuery.java b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireRepositoryQuery.java index 36a88d4a..2c595ae5 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/GemfireRepositoryQuery.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/GemfireRepositoryQuery.java @@ -48,6 +48,4 @@ abstract class GemfireRepositoryQuery implements RepositoryQuery { public QueryMethod getQueryMethod() { return this.queryMethod; } - - protected abstract boolean isCountQuery(); } diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/PartTreeGemfireRepositoryQuery.java b/src/main/java/org/springframework/data/gemfire/repository/query/PartTreeGemfireRepositoryQuery.java index 08ec5a2c..4e3edc06 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/PartTreeGemfireRepositoryQuery.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/PartTreeGemfireRepositoryQuery.java @@ -65,7 +65,7 @@ public class PartTreeGemfireRepositoryQuery extends GemfireRepositoryQuery { QueryString query = new GemfireQueryCreator(tree, method.getPersistentEntity()).createQuery(parameterAccessor .getSort()); - RepositoryQuery repositoryQuery = new StringBasedGemfireRepositoryQuery(query.toString(), method, template,isCountQuery()); + RepositoryQuery repositoryQuery = new StringBasedGemfireRepositoryQuery(query.toString(), method, template); return repositoryQuery.execute(prepareStringParameters(parameters)); } @@ -102,12 +102,4 @@ public class PartTreeGemfireRepositoryQuery extends GemfireRepositoryQuery { return result; } - - /* (non-Javadoc) - * @see org.springframework.data.gemfire.repository.query.GemfireRepositoryQuery#isCountQuery() - */ - @Override - protected boolean isCountQuery() { - return this.tree.isCountProjection(); - } } diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/QueryBuilder.java b/src/main/java/org/springframework/data/gemfire/repository/query/QueryBuilder.java index 8dd87b75..7d1e2b8c 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/QueryBuilder.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/QueryBuilder.java @@ -35,8 +35,8 @@ class QueryBuilder { this.query = source; } - public QueryBuilder(GemfirePersistentEntity entity, PartTree tree) { - this(String.format(tree.isCountProjection()? "SELECT count(*) FROM /%s %s":"SELECT * FROM /%s %s", entity.getRegionName(), DEFAULT_ALIAS)); + public QueryBuilder(GemfirePersistentEntity entity) { + this(String.format("SELECT * FROM /%s %s", entity.getRegionName(), DEFAULT_ALIAS)); } public QueryString create(Predicate predicate) { diff --git a/src/main/java/org/springframework/data/gemfire/repository/query/StringBasedGemfireRepositoryQuery.java b/src/main/java/org/springframework/data/gemfire/repository/query/StringBasedGemfireRepositoryQuery.java index c65140d3..ee7f908d 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/query/StringBasedGemfireRepositoryQuery.java +++ b/src/main/java/org/springframework/data/gemfire/repository/query/StringBasedGemfireRepositoryQuery.java @@ -38,7 +38,6 @@ public class StringBasedGemfireRepositoryQuery extends GemfireRepositoryQuery { private static final String INVALID_EXECUTION = "Paging and modifying queries are not supported!"; - private final boolean isCountProjection; private final QueryString query; private final GemfireQueryMethod method; private final GemfireTemplate template; @@ -51,7 +50,7 @@ public class StringBasedGemfireRepositoryQuery extends GemfireRepositoryQuery { * @param template must not be {@literal null}. */ public StringBasedGemfireRepositoryQuery(GemfireQueryMethod method, GemfireTemplate template) { - this(method.getAnnotatedQuery(), method, template, null); + this(method.getAnnotatedQuery(), method, template); } /** @@ -63,8 +62,7 @@ public class StringBasedGemfireRepositoryQuery extends GemfireRepositoryQuery { * @param method must not be {@literal null}. * @param template must not be {@literal null}. */ - public StringBasedGemfireRepositoryQuery(String query, GemfireQueryMethod method, GemfireTemplate template, - Boolean isCountProjection) { + public StringBasedGemfireRepositoryQuery(String query, GemfireQueryMethod method, GemfireTemplate template) { super(method); @@ -73,11 +71,6 @@ public class StringBasedGemfireRepositoryQuery extends GemfireRepositoryQuery { this.query = new QueryString(StringUtils.hasText(query) ? query : method.getAnnotatedQuery()); this.method = method; this.template = template; - if (isCountProjection == null && StringUtils.hasText(method.getAnnotatedQuery())) { - this.isCountProjection = method.getAnnotatedQuery().toLowerCase().contains("count(*)"); - } else { - this.isCountProjection = isCountProjection; - } if (method.isPageQuery() || method.isModifyingQuery()) { throw new IllegalStateException(INVALID_EXECUTION); @@ -111,14 +104,6 @@ public class StringBasedGemfireRepositoryQuery extends GemfireRepositoryQuery { } else { throw new IncorrectResultSizeDataAccessException(1, result.size()); } - } else if (isCountProjection) { - int count = (Integer) result.iterator().next(); - - if (long.class.isAssignableFrom(method.getReturnedObjectType())) { - return (long) count; - } else { - return count; - } } else { throw new IllegalStateException("Unsupported query: " + query.toString()); } @@ -144,12 +129,4 @@ public class StringBasedGemfireRepositoryQuery extends GemfireRepositoryQuery { return source.getClass().isArray() ? CollectionUtils.arrayToList(source) : Collections.singleton(source); } - - /* (non-Javadoc) - * @see org.springframework.data.gemfire.repository.query.GemfireRepositoryQuery#isCountQuery() - */ - @Override - protected boolean isCountQuery() { - return this.isCountProjection; - } } diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java index ce2c7a04..18c0bee2 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java @@ -165,7 +165,7 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { return new StringBasedGemfireRepositoryQuery(namedQueries.getQuery(namedQueryName), queryMethod, - template,false); + template); } return new PartTreeGemfireRepositoryQuery(queryMethod, template); diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java b/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java index 0471f0b8..e00b3263 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/PersonRepository.java @@ -53,11 +53,4 @@ public interface PersonRepository extends GemfireRepository { Collection findByLastnameEndingWith(String lastname); Collection findByFirstnameContaining(String firstname); - - long countByFirstname(String firstname); - - int countByLastname(String lastname); - - @Query("SELECT count(*) FROM /Person p WHERE p.firstname = $1") - int countFirstNameManual(String firstName); } diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/PersonRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/PersonRepositoryIntegrationTests.java deleted file mode 100644 index 09db3f1d..00000000 --- a/src/test/java/org/springframework/data/gemfire/repository/support/PersonRepositoryIntegrationTests.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2002-2013 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. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ -package org.springframework.data.gemfire.repository.support; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.gemfire.repository.sample.Person; -import org.springframework.data.gemfire.repository.sample.PersonRepository; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -/** - * @author David Turanski - * - */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration -public class PersonRepositoryIntegrationTests { - @Autowired - PersonRepository repository; - - @Test - public void testCountProjections() { - Person dave1 = new Person(1L,"Dave","Matthews"); - Person dave2 = new Person(2L,"Dave","Turanski"); - repository.save(dave1); - repository.save(dave2); - assertEquals(2L,repository.countByFirstname("Dave")); - assertEquals(1,repository.countByLastname("Matthews")); - assertEquals(2,repository.countFirstNameManual("Dave")); - } -}