Declared and implemented the findAll(:Sort) method from the SDC's PagingAndSortingRepository abstraction in SDG given GemFire supports ORDER BY in Queries.
This commit is contained in:
@@ -17,14 +17,31 @@ package org.springframework.data.gemfire.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* Gemfire-specific extension of the {@link CrudRepository} interface.
|
||||
*
|
||||
* <p/>
|
||||
* @author Oliver Gierke
|
||||
* @author John Blum
|
||||
* @see java.io.Serializable
|
||||
* @see org.springframework.data.repository.CrudRepository
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface GemfireRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
|
||||
|
||||
/**
|
||||
* Returns all entities sorted by the given options.
|
||||
* <p/>
|
||||
* @param sort the Spring Data Commons Sort type defining the ordering criteria.
|
||||
* @return all entities sorted by the given options.
|
||||
* @see org.springframework.data.repository.PagingAndSortingRepository#findAll(org.springframework.data.domain.Sort)
|
||||
* @see org.springframework.data.domain.Sort
|
||||
* @see java.lang.Iterable
|
||||
*/
|
||||
Iterable<T> findAll(Sort sort);
|
||||
|
||||
T save(Wrapper<T, ID> wrapper);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.gemfire.GemfireCallback;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.data.gemfire.repository.GemfireRepository;
|
||||
@@ -101,12 +102,44 @@ public class SimpleGemfireRepository<T, ID extends Serializable> implements Gemf
|
||||
@Override
|
||||
public Collection<T> findAll() {
|
||||
SelectResults<T> results = template.find("select * from " + template.getRegion().getFullPath());
|
||||
return (Collection<T>)results.asList();
|
||||
return results.asList();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.gemfire.repository.GemfireRepository.sor(:org.springframework.data.domain.Sort)
|
||||
*/
|
||||
@Override
|
||||
public Iterable<T> findAll(final Sort sort) {
|
||||
SelectResults<T> selectResults = template.find(String.format("SELECT * FROM %1$s%2$s",
|
||||
template.getRegion().getFullPath(), toString(sort)));
|
||||
return selectResults.asList();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.domain.Sort
|
||||
*/
|
||||
private String toString(final Sort sort) {
|
||||
if (sort != null) {
|
||||
StringBuilder orderClause = new StringBuilder(" ORDER BY ");
|
||||
int count = 0;
|
||||
|
||||
for (Sort.Order order : sort) {
|
||||
orderClause.append(count++ > 0 ? ", " : "");
|
||||
orderClause.append(String.format("%1$s %2$s", order.getProperty(), order.getDirection()));
|
||||
}
|
||||
|
||||
return orderClause.toString();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.data.repository.CrudRepository#findAll(java.lang.
|
||||
* Iterable)
|
||||
|
||||
Reference in New Issue
Block a user