backed out SGF-172 - moved to feature branch 1.3.x
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -47,7 +47,7 @@ class GemfireQueryCreator extends AbstractQueryCreator<QueryString, Predicates>
|
||||
|
||||
super(tree);
|
||||
|
||||
this.query = new QueryBuilder(entity,tree);
|
||||
this.query = new QueryBuilder(entity);
|
||||
this.indexes = new IndexProvider();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,4 @@ abstract class GemfireRepositoryQuery implements RepositoryQuery {
|
||||
public QueryMethod getQueryMethod() {
|
||||
return this.queryMethod;
|
||||
}
|
||||
|
||||
protected abstract boolean isCountQuery();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -53,11 +53,4 @@ public interface PersonRepository extends GemfireRepository<Person, Long> {
|
||||
Collection<Person> findByLastnameEndingWith(String lastname);
|
||||
|
||||
Collection<Person> 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);
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user