Add support for marking a repository with @Region rather than the entity
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package org.springframework.data.gemfire.repository.sample;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
public class Animal {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Foo [id=" + id + ", name=" + name + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package org.springframework.data.gemfire.repository.sample;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class AnimalRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
CatRepository catRepo;
|
||||
|
||||
@Autowired
|
||||
DogRepository dogRepo;
|
||||
|
||||
@Test
|
||||
public void foo() {
|
||||
|
||||
Animal felix = new Animal();
|
||||
felix.setId(1);
|
||||
felix.setName("Felix");
|
||||
|
||||
Animal leo = new Animal();
|
||||
leo.setId(2);
|
||||
leo.setName("Leo");
|
||||
|
||||
Animal fido = new Animal();
|
||||
fido.setId(1);
|
||||
fido.setName("Fido");
|
||||
|
||||
Animal leo_ = catRepo.save(leo);
|
||||
assertNotNull(leo_);
|
||||
|
||||
Animal felix_ = catRepo.save(felix);
|
||||
assertNotNull(felix_);
|
||||
|
||||
Animal fido_ = dogRepo.save(fido);
|
||||
assertNotNull(fido_);
|
||||
|
||||
assertEquals(2L, catRepo.count());
|
||||
assertEquals(1L, dogRepo.count());
|
||||
|
||||
Animal foundFelix = catRepo.findOne(1L);
|
||||
assertEquals(felix, foundFelix);
|
||||
|
||||
Animal findOther = catRepo.findByName("Leo");
|
||||
assertEquals(leo, findOther);
|
||||
|
||||
Animal foundFido = dogRepo.findBy("Fido");
|
||||
assertEquals(fido, foundFido);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.springframework.data.gemfire.repository.sample;
|
||||
|
||||
import org.springframework.data.gemfire.mapping.Region;
|
||||
import org.springframework.data.gemfire.repository.GemfireRepository;
|
||||
import org.springframework.data.gemfire.repository.Query;
|
||||
|
||||
@Region("Cats")
|
||||
public interface CatRepository extends GemfireRepository<Animal, Long> {
|
||||
|
||||
Animal findByName(String name);
|
||||
|
||||
@Query("SELECT * FROM /Foo x WHERE x.name = $1")
|
||||
Animal findBy(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.springframework.data.gemfire.repository.sample;
|
||||
|
||||
import org.springframework.data.gemfire.mapping.Region;
|
||||
import org.springframework.data.gemfire.repository.GemfireRepository;
|
||||
import org.springframework.data.gemfire.repository.Query;
|
||||
|
||||
@Region("Dogs")
|
||||
public interface DogRepository extends GemfireRepository<Animal, Long> {
|
||||
|
||||
Animal findByName(String name);
|
||||
|
||||
@Query("SELECT * FROM /FooTwo x WHERE x.name = $1")
|
||||
Animal findBy(String name);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user