forked from michaellavelle/spring-data-dynamodb
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #114: Scanning by nested properties
- Loading branch information
Showing
8 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/java/org/socialsignin/spring/data/dynamodb/repository/query/nested/Address.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.socialsignin.spring.data.dynamodb.repository.query.nested; | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBDocument; | ||
|
||
@DynamoDBDocument | ||
public class Address { | ||
private String city; | ||
private String country; | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
public String getCountry() { | ||
return country; | ||
} | ||
public void setCountry(String country) { | ||
this.country = country; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ava/org/socialsignin/spring/data/dynamodb/repository/query/nested/NestedPropertiesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.socialsignin.spring.data.dynamodb.repository.query.nested; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.socialsignin.spring.data.dynamodb.core.ConfigurationTI; | ||
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = {ConfigurationTI.class, NestedPropertiesIT.TestAppConfig.class}) | ||
public class NestedPropertiesIT { | ||
|
||
@Configuration | ||
@EnableDynamoDBRepositories(basePackages = "org.socialsignin.spring.data.dynamodb.query.nested") | ||
public static class TestAppConfig { | ||
} | ||
|
||
@Autowired | ||
private PersonRepository personRepository; | ||
|
||
@Test | ||
public void testNestedProperty() { | ||
|
||
Address usaAddress = new Address(); | ||
usaAddress.setCity("New York"); | ||
usaAddress.setCountry("USA"); | ||
|
||
Address deAddress = new Address(); | ||
deAddress.setCity("Frankfurt"); | ||
deAddress.setCity("Germany"); | ||
|
||
Person p1 = new Person(); | ||
p1.setName("personName"); | ||
p1.setPhone("phone"); | ||
p1.setArea("area"); | ||
p1.setAddress(usaAddress); | ||
|
||
Person p2 = new Person(); | ||
p2.setName("otherName"); | ||
p2.setPhone("42"); | ||
p2.setArea("otherArea"); | ||
p2.setAddress(deAddress); | ||
|
||
/// personRepository.save(p1); | ||
|
||
List<Person> actual = personRepository.findByAddressCountry("USA"); | ||
assertEquals(1, actual.size()); | ||
|
||
actual = personRepository.findByPhone("42"); | ||
assertEquals(1, actual.size()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/org/socialsignin/spring/data/dynamodb/repository/query/nested/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.socialsignin.spring.data.dynamodb.repository.query.nested; | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; | ||
import org.springframework.data.annotation.Id; | ||
|
||
@DynamoDBTable(tableName = "Person") | ||
public class Person { | ||
|
||
@Id | ||
private PersonId personId; | ||
|
||
private String phone; | ||
private Address address; | ||
|
||
@DynamoDBHashKey | ||
public String getName() { | ||
return personId != null ? personId.getName() : null; | ||
} | ||
|
||
@DynamoDBRangeKey | ||
public String getArea() { | ||
return personId != null ? personId.getArea() : null; | ||
} | ||
public Address getAddress() { | ||
return address; | ||
} | ||
public String getPhone() { | ||
return phone; | ||
} | ||
public void setPhone(String phone) { | ||
this.phone = phone; | ||
} | ||
public void setName(String name) { | ||
if (personId == null) { | ||
personId = new PersonId(); | ||
} | ||
this.personId.setName(name); | ||
} | ||
public void setArea(String area) { | ||
if (personId == null) { | ||
personId = new PersonId(); | ||
} | ||
this.personId.setArea(area); | ||
} | ||
public void setAddress(Address address) { | ||
this.address = address; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/org/socialsignin/spring/data/dynamodb/repository/query/nested/PersonId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.socialsignin.spring.data.dynamodb.repository.query.nested; | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey; | ||
|
||
import java.io.Serializable; | ||
|
||
public class PersonId implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private String name; | ||
private String area; | ||
|
||
@DynamoDBRangeKey | ||
public String getArea() { | ||
return area; | ||
} | ||
|
||
@DynamoDBHashKey | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public PersonId() {} | ||
|
||
public PersonId(String name, String area) { | ||
this.name = name; | ||
this.area = area; | ||
} | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
public void setArea(String area) { | ||
this.area = area; | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
.../java/org/socialsignin/spring/data/dynamodb/repository/query/nested/PersonRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.socialsignin.spring.data.dynamodb.repository.query.nested; | ||
|
||
import org.socialsignin.spring.data.dynamodb.repository.EnableScan; | ||
import org.springframework.data.repository.PagingAndSortingRepository; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface PersonRepository extends PagingAndSortingRepository<Person, PersonId> { | ||
|
||
Person findByNameAndArea(@Param("name") String name, @Param("area") String area); | ||
|
||
@EnableScan | ||
List<Person> findByArea(@Param("area") String area); | ||
|
||
@EnableScan | ||
List<Person> findByPhone(@Param("phone") String phone); | ||
|
||
@EnableScan | ||
List<Person> findByAddressCountry(@Param("country") String country); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"AttributeDefinitions": [ | ||
{ | ||
"AttributeName": "Name", | ||
"AttributeType": "S" | ||
}, | ||
{ | ||
"AttributeName": "Area", | ||
"AttributeType": "S" | ||
} | ||
], | ||
"KeySchema": [ | ||
{ | ||
"AttributeName": "Name", | ||
"KeyType": "HASH" | ||
}, | ||
{ | ||
"AttributeName": "Area", | ||
"KeyType": "RANGE" | ||
} | ||
], | ||
"ProvisionedThroughput": { | ||
"ReadCapacityUnits": "10", | ||
"WriteCapacityUnits": "10" | ||
}, | ||
"TableName": "person" | ||
} |