Fixes JIRA issues SGF-251 involving Spring Data GemFire Repositories not functionality properly for application domain objects (entities) stored in GemFire Subregions using the @Region annotation association.
This commit is contained in:
@@ -43,21 +43,25 @@ public class QueryStringUnitTests {
|
||||
|
||||
@Test
|
||||
public void replacesDomainObjectWithRegionNameCorrectly() {
|
||||
|
||||
QueryString query = new QueryString("SELECT * FROM /Person p WHERE p.firstname = $1");
|
||||
|
||||
when(region.getName()).thenReturn("foo");
|
||||
when(region.getFullPath()).thenReturn("/foo");
|
||||
|
||||
assertThat(query.forRegion(Person.class, region).toString(), is("SELECT * FROM /foo p WHERE p.firstname = $1"));
|
||||
|
||||
verify(region, never()).getName();
|
||||
}
|
||||
|
||||
//SGF-156
|
||||
@Test
|
||||
public void replacesDomainObjectWithPluralRegionNameCorrectly() {
|
||||
|
||||
QueryString query = new QueryString("SELECT * FROM /Persons p WHERE p.firstname = $1");
|
||||
|
||||
when(region.getName()).thenReturn("Persons");
|
||||
when(region.getFullPath()).thenReturn("/Persons");
|
||||
|
||||
assertThat(query.forRegion(Person.class, region).toString(), is("SELECT * FROM /Persons p WHERE p.firstname = $1"));
|
||||
|
||||
verify(region, never()).getName();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-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.sample;
|
||||
|
||||
import org.springframework.data.gemfire.mapping.Region;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* The Programmer class is a User representing/modeling a software engineer/developer.
|
||||
* <p/>
|
||||
* @author John J. Blum
|
||||
* @see org.springframework.data.gemfire.mapping.Region
|
||||
* @see org.springframework.data.gemfire.repository.sample.User
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Region("Programmers")
|
||||
@SuppressWarnings("unused")
|
||||
public class Programmer extends User {
|
||||
|
||||
protected static final String DEFAULT_PROGRAMMING_LANGUAGE = "?";
|
||||
|
||||
private String programmingLanguage;
|
||||
|
||||
public Programmer(final String username) {
|
||||
super(username);
|
||||
}
|
||||
|
||||
public String getProgrammingLanguage() {
|
||||
return (StringUtils.hasText(programmingLanguage) ? programmingLanguage : DEFAULT_PROGRAMMING_LANGUAGE);
|
||||
}
|
||||
|
||||
public void setProgrammingLanguage(final String programmingLanguage) {
|
||||
this.programmingLanguage = programmingLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%1$s programs in '%2$s.", getUsername(), getProgrammingLanguage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-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.sample;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.gemfire.repository.GemfireRepository;
|
||||
|
||||
/**
|
||||
* The ProgrammerRepository class is a Data Access Object (DAO) for Programmer domain objects supporting basic CRUD
|
||||
* and Query operations.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.repository.GemfireRepository
|
||||
* @see org.springframework.data.gemfire.repository.sample.Programmer
|
||||
* @since 1.3.4
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface ProgrammerRepository extends GemfireRepository<Programmer, String> {
|
||||
|
||||
public List<Programmer> findDistinctByProgrammingLanguageOrderByUsernameAsc(String programmingLanguage);
|
||||
|
||||
public List<Programmer> findDistinctByProgrammingLanguageLikeOrderByUsernameAsc(String programmingLanguage);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright 2010-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.sample;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.gemfire.repository.Wrapper;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
|
||||
/**
|
||||
* The SubRegionRepositoryTest class is a test suite of test cases testing the use of GemFire Repositories on GemFire
|
||||
* Cache Subregions.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.springframework.data.gemfire.repository.Wrapper
|
||||
* @see org.springframework.data.gemfire.repository.sample.Programmer
|
||||
* @see org.springframework.data.gemfire.repository.sample.ProgrammerRepository
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see com.gemstone.gemfire.cache.Region
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ContextConfiguration("subregionRepository.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SuppressWarnings("unused")
|
||||
public class SubRegionRepositoryIntegrationTest {
|
||||
|
||||
private static final Map<String, Programmer> PROGRAMMER_DATA = new HashMap<String, Programmer>(23, 0.90f);
|
||||
|
||||
static {
|
||||
createProgrammer("AdaLovelace", "Ada");
|
||||
createProgrammer("AlanKay", "Smalltalk");
|
||||
createProgrammer("BjarneStroustrup", "C++");
|
||||
createProgrammer("BrendanEich", "JavaScript");
|
||||
createProgrammer("DennisRitchie", "C");
|
||||
createProgrammer("GuidoVanRossum", "Python");
|
||||
createProgrammer("JamesGosling", "Java");
|
||||
createProgrammer("JamesStrachan", "Groovy");
|
||||
createProgrammer("JohnBackus", "Fortran");
|
||||
createProgrammer("JohnKemeny", "BASIC");
|
||||
createProgrammer("JohnMcCarthy", "LISP");
|
||||
createProgrammer("JoshuaBloch", "Java");
|
||||
createProgrammer("LarryWall", "Perl");
|
||||
createProgrammer("MartinOdersky", "Scala");
|
||||
createProgrammer("NiklausWirth", "Modula-2");
|
||||
createProgrammer("NiklausWirth", "Pascal");
|
||||
createProgrammer("ThomasKurtz", "BASIC");
|
||||
createProgrammer("YukihiroMatsumoto", "Ruby");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ProgrammerRepository programmersRepo;
|
||||
|
||||
@Resource(name = "/Users/Programmers")
|
||||
private Region<String, Programmer> programmers;
|
||||
|
||||
protected static Programmer createProgrammer(final String username, final String programmingLanguage) {
|
||||
Programmer programmer = new Programmer(username);
|
||||
programmer.setProgrammingLanguage(programmingLanguage);
|
||||
PROGRAMMER_DATA.put(username, programmer);
|
||||
return programmer;
|
||||
}
|
||||
|
||||
protected static List<Programmer> getProgrammers(final String... usernames) {
|
||||
List<Programmer> programmers = new ArrayList<Programmer>(usernames.length);
|
||||
|
||||
for (String username : usernames) {
|
||||
Programmer programmer = PROGRAMMER_DATA.get(username);
|
||||
|
||||
if (programmer != null) {
|
||||
programmers.add(PROGRAMMER_DATA.get(username));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(programmers);
|
||||
|
||||
return programmers;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
assertNotNull("The /Users/Programmers Subregion was null!", programmers);
|
||||
|
||||
if (programmers.isEmpty()) {
|
||||
programmers.putAll(PROGRAMMER_DATA);
|
||||
}
|
||||
|
||||
assertEquals(PROGRAMMER_DATA.size(), programmers.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubregionRepositoryInteractions() {
|
||||
assertEquals(PROGRAMMER_DATA.get("JamesGosling"), programmersRepo.findOne("JamesGosling"));
|
||||
|
||||
List<Programmer> javaProgrammers = programmersRepo.findDistinctByProgrammingLanguageOrderByUsernameAsc("Java");
|
||||
|
||||
assertNotNull(javaProgrammers);
|
||||
assertFalse(javaProgrammers.isEmpty());
|
||||
assertEquals(2, javaProgrammers.size());
|
||||
assertTrue(javaProgrammers.containsAll(getProgrammers("JamesGosling", "JoshuaBloch")));
|
||||
|
||||
List<Programmer> groovyProgrammers = programmersRepo.findDistinctByProgrammingLanguageLikeOrderByUsernameAsc("Groovy");
|
||||
|
||||
assertNotNull(groovyProgrammers);
|
||||
assertFalse(groovyProgrammers.isEmpty());
|
||||
assertEquals(1, groovyProgrammers.size());
|
||||
assertTrue(groovyProgrammers.containsAll(getProgrammers("JamesStrachan")));
|
||||
|
||||
programmersRepo.save(new Wrapper<Programmer, String>(createProgrammer("RodJohnson", "Java"), "RodJohnson"));
|
||||
programmersRepo.save(new Wrapper<Programmer, String>(createProgrammer("GuillaumeLaforge", "Groovy"), "GuillaumeLaforge"));
|
||||
programmersRepo.save(new Wrapper<Programmer, String>(createProgrammer("GraemeRocher", "Groovy"), "GraemeRocher"));
|
||||
|
||||
javaProgrammers = programmersRepo.findDistinctByProgrammingLanguageOrderByUsernameAsc("Java");
|
||||
|
||||
assertNotNull(javaProgrammers);
|
||||
assertFalse(javaProgrammers.isEmpty());
|
||||
assertEquals(3, javaProgrammers.size());
|
||||
assertTrue(javaProgrammers.containsAll(getProgrammers("JamesGosling", "JoshuaBloch", "RodJohnson")));
|
||||
|
||||
groovyProgrammers = programmersRepo.findDistinctByProgrammingLanguageLikeOrderByUsernameAsc("Groovy");
|
||||
|
||||
assertNotNull(groovyProgrammers);
|
||||
assertFalse(groovyProgrammers.isEmpty());
|
||||
assertEquals(3, groovyProgrammers.size());
|
||||
assertTrue(groovyProgrammers.containsAll(getProgrammers("GraemeRocher", "GuillaumeLaforge", "JamesStrachan")));
|
||||
|
||||
List<Programmer> javaLikeProgrammers = programmersRepo.findDistinctByProgrammingLanguageLikeOrderByUsernameAsc("Java%");
|
||||
|
||||
assertNotNull(javaLikeProgrammers);
|
||||
assertFalse(javaLikeProgrammers.isEmpty());
|
||||
assertEquals(4, javaLikeProgrammers.size());
|
||||
assertTrue(javaLikeProgrammers.containsAll(getProgrammers("BrendanEich", "JamesGosling", "JoshuaBloch", "RodJohnson")));
|
||||
|
||||
List<Programmer> pseudoCodeProgrammers = programmersRepo.findDistinctByProgrammingLanguageLikeOrderByUsernameAsc("PseudoCode");
|
||||
|
||||
assertNotNull(pseudoCodeProgrammers);
|
||||
assertTrue(pseudoCodeProgrammers.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,12 +27,14 @@ import org.springframework.util.ObjectUtils;
|
||||
* The User class represents an authorized user of a service or computer system, etc.
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @since 1.3.3 (Spring Data GemFire)
|
||||
* @since 7.0.1 (GemFire)
|
||||
* @see java.lang.Comparable
|
||||
* @see org.springframework.data.annotation.Id
|
||||
* @see org.springframework.data.gemfire.mapping.Region
|
||||
* @since 1.3.4
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Region("Users")
|
||||
public class User {
|
||||
@SuppressWarnings("unused")
|
||||
public class User implements Comparable<User> {
|
||||
|
||||
private Boolean active = true;
|
||||
|
||||
@@ -80,8 +82,9 @@ public class User {
|
||||
return username;
|
||||
}
|
||||
|
||||
private static boolean equalsIgnoreNull(final Object obj1, final Object obj2) {
|
||||
return (obj1 == null ? obj2 == null : obj1.equals(obj2));
|
||||
@Override
|
||||
public int compareTo(final User user) {
|
||||
return getUsername().compareTo(user.getUsername());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,8 +25,9 @@ import org.springframework.data.gemfire.repository.GemfireRepository;
|
||||
* <p/>
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.repository.GemfireRepository
|
||||
* @since 1.3.3 (Spring Data GemFire)
|
||||
* @since 7.0.1 (GemFire)
|
||||
* @see org.springframework.data.gemfire.repository.Query
|
||||
* @see org.springframework.data.gemfire.repository.sample.User
|
||||
* @since 1.3.4
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public interface UserRepository extends GemfireRepository<User, String> {
|
||||
|
||||
Reference in New Issue
Block a user