Skip to content

Commit 3a45e57

Browse files
Added propertry considerNestedRepositories to @EnableDynamoDBReposito… (#24)
* Added propertry considerNestedRepositories to @EnableDynamoDBRepositories * Removing pom changes Co-authored-by: John D <[email protected]>
1 parent a3e6ba0 commit 3a45e57

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

src/main/java/org/socialsignin/spring/data/dynamodb/repository/config/EnableDynamoDBRepositories.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,10 @@
180180
* bean name
181181
*/
182182
String mappingContextRef() default "";
183+
184+
/**
185+
* Configures whether nested repository-interfaces (e.g. defined as inner classes) should be discovered by the
186+
* repositories infrastructure.
187+
*/
188+
boolean considerNestedRepositories() default false;
183189
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright © 2018 spring-data-dynamodb (https://github.com/boostchicken/spring-data-dynamodb)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.socialsignin.spring.data.dynamodb.domain.sample;
17+
18+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
19+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
20+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
21+
import org.springframework.data.repository.CrudRepository;
22+
23+
@DynamoDBTable(tableName = "nested_repo_test")
24+
public class NestedRepostioryDocument {
25+
@DynamoDBHashKey
26+
public String hashKey;
27+
28+
@DynamoDBAttribute
29+
public String someData;
30+
31+
public NestedRepostioryDocument() {
32+
}
33+
34+
public String getHashKey() { return hashKey; }
35+
public void setHashKey(String hashKey) {this.hashKey = hashKey; }
36+
37+
public String getSomeData() {return someData; }
38+
public void setSomeData(String someData) { this.someData = someData; }
39+
40+
public interface Repository extends CrudRepository<NestedRepostioryDocument, String> {
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright © 2018 spring-data-dynamodb (https://github.com/boostchicken/spring-data-dynamodb)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.socialsignin.spring.data.dynamodb.repository.config;
17+
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
import org.socialsignin.spring.data.dynamodb.domain.sample.NestedRepostioryDocument;
21+
import org.socialsignin.spring.data.dynamodb.utils.DynamoDBLocalResource;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.test.context.ContextConfiguration;
25+
import org.springframework.test.context.TestPropertySource;
26+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
27+
28+
import java.util.Optional;
29+
30+
import static org.junit.Assert.assertEquals;
31+
32+
@RunWith(SpringJUnit4ClassRunner.class)
33+
@ContextConfiguration(classes = {DynamoDBLocalResource.class, ConsiderNestingRepositoriesTest.TestAppConfig.class})
34+
@TestPropertySource(properties = {"spring.data.dynamodb.entity2ddl.auto=create"})
35+
public class ConsiderNestingRepositoriesTest {
36+
37+
@Configuration
38+
@EnableDynamoDBRepositories(basePackages = "org.socialsignin.spring.data.dynamodb.domain.sample", considerNestedRepositories = true)
39+
public static class TestAppConfig {
40+
}
41+
42+
@Autowired
43+
private NestedRepostioryDocument.Repository repostitory;
44+
45+
@Test
46+
public void testNestedRepositoriesAreSupported() {
47+
// make any call to the repository to make sure it is working
48+
assertEquals(repostitory.findById("someId"), Optional.empty());
49+
}
50+
}

0 commit comments

Comments
 (0)