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
10 changed files
with
294 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/xsd/changes-1.0.0.xsd"> | ||
<properties> | ||
<title>spring-data-dynamodb Changes</title> | ||
<author email="[email protected]" >derjust</author> | ||
<author email="[email protected]">derjust</author> | ||
</properties> | ||
<body> | ||
<release version="5.0.2" date="" description="Maintenance release"> | ||
|
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
37 changes: 37 additions & 0 deletions
37
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,37 @@ | ||
/** | ||
* Copyright © 2013 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb) | ||
* | ||
* 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.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
...a/org/socialsignin/spring/data/dynamodb/repository/query/nested/NestedPropertiesTest.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.repository.config.EnableDynamoDBRepositories; | ||
import org.socialsignin.spring.data.dynamodb.utils.DynamoDBLocalResource; | ||
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 = {DynamoDBLocalResource.class, NestedPropertiesTest.TestAppConfig.class}) | ||
public class NestedPropertiesTest { | ||
|
||
@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()); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
/** | ||
* Copyright © 2013 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb) | ||
* | ||
* 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.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; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
/** | ||
* Copyright © 2013 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb) | ||
* | ||
* 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.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; | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
.../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,36 @@ | ||
/** | ||
* Copyright © 2013 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb) | ||
* | ||
* 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.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" | ||
} |