DATACOUCH-75 - Trim off find on custom repository finder.

This commit is contained in:
Michael Nitschinger
2014-03-12 13:13:02 +01:00
parent 9e1f730f66
commit b3a4069696
3 changed files with 11 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ import com.couchbase.client.protocol.views.Query;
import org.springframework.data.couchbase.core.CouchbaseOperations;
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.util.StringUtils;
/**
* Execute a repository query through the View mechanism.
@@ -69,7 +70,7 @@ public class ViewBasedCouchbaseQuery implements RepositoryQuery {
if (method.hasViewAnnotation()) {
return method.getViewAnnotation().designDocument();
} else {
return method.getEntityInformation().getJavaType().getSimpleName().toLowerCase();
return StringUtils.uncapitalize(method.getEntityInformation().getJavaType().getSimpleName());
}
}
@@ -82,7 +83,7 @@ public class ViewBasedCouchbaseQuery implements RepositoryQuery {
if (method.hasViewAnnotation()) {
return method.getViewAnnotation().viewName();
} else {
return method.getName();
return StringUtils.uncapitalize(method.getName().replaceFirst("find", ""));
}
}

View File

@@ -22,6 +22,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.data.couchbase.TestApplicationConfig;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.repository.support.CouchbaseRepositoryFactory;
@@ -72,4 +73,9 @@ public class CouchbaseRepositoryViewTests {
assertThat(value, is(100L));
}
@Test(expected = InvalidDataAccessResourceUsageException.class)
public void shouldTrimOffFindOnCustomFinder() {
repository.findAllSomething();
}
}

View File

@@ -31,4 +31,6 @@ public interface CustomUserRepository extends CouchbaseRepository<User, String>
@View(designDocument = "userCustom", viewName = "customCountView")
long count();
Iterable<User> findAllSomething();
}