diff --git a/src/main/java/org/socialsignin/spring/data/dynamodb/repository/config/EnableDynamoDBRepositories.java b/src/main/java/org/socialsignin/spring/data/dynamodb/repository/config/EnableDynamoDBRepositories.java index f226c4cd..92967d66 100644 --- a/src/main/java/org/socialsignin/spring/data/dynamodb/repository/config/EnableDynamoDBRepositories.java +++ b/src/main/java/org/socialsignin/spring/data/dynamodb/repository/config/EnableDynamoDBRepositories.java @@ -180,4 +180,10 @@ * bean name */ String mappingContextRef() default ""; + + /** + * Configures whether nested repository-interfaces (e.g. defined as inner classes) should be discovered by the + * repositories infrastructure. + */ + boolean considerNestedRepositories() default false; } diff --git a/src/test/java/org/socialsignin/spring/data/dynamodb/domain/sample/NestedRepostioryDocument.java b/src/test/java/org/socialsignin/spring/data/dynamodb/domain/sample/NestedRepostioryDocument.java new file mode 100644 index 00000000..4625dc29 --- /dev/null +++ b/src/test/java/org/socialsignin/spring/data/dynamodb/domain/sample/NestedRepostioryDocument.java @@ -0,0 +1,42 @@ +/** + * Copyright © 2018 spring-data-dynamodb (https://github.com/boostchicken/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.domain.sample; + +import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; +import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; +import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; +import org.springframework.data.repository.CrudRepository; + +@DynamoDBTable(tableName = "nested_repo_test") +public class NestedRepostioryDocument { + @DynamoDBHashKey + public String hashKey; + + @DynamoDBAttribute + public String someData; + + public NestedRepostioryDocument() { + } + + public String getHashKey() { return hashKey; } + public void setHashKey(String hashKey) {this.hashKey = hashKey; } + + public String getSomeData() {return someData; } + public void setSomeData(String someData) { this.someData = someData; } + + public interface Repository extends CrudRepository { + } +} diff --git a/src/test/java/org/socialsignin/spring/data/dynamodb/repository/config/ConsiderNestingRepositoriesTest.java b/src/test/java/org/socialsignin/spring/data/dynamodb/repository/config/ConsiderNestingRepositoriesTest.java new file mode 100644 index 00000000..3158ec8d --- /dev/null +++ b/src/test/java/org/socialsignin/spring/data/dynamodb/repository/config/ConsiderNestingRepositoriesTest.java @@ -0,0 +1,50 @@ +/** + * Copyright © 2018 spring-data-dynamodb (https://github.com/boostchicken/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.config; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.socialsignin.spring.data.dynamodb.domain.sample.NestedRepostioryDocument; +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.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.Optional; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {DynamoDBLocalResource.class, ConsiderNestingRepositoriesTest.TestAppConfig.class}) +@TestPropertySource(properties = {"spring.data.dynamodb.entity2ddl.auto=create"}) +public class ConsiderNestingRepositoriesTest { + + @Configuration + @EnableDynamoDBRepositories(basePackages = "org.socialsignin.spring.data.dynamodb.domain.sample", considerNestedRepositories = true) + public static class TestAppConfig { + } + + @Autowired + private NestedRepostioryDocument.Repository repostitory; + + @Test + public void testNestedRepositoriesAreSupported() { + // make any call to the repository to make sure it is working + assertEquals(repostitory.findById("someId"), Optional.empty()); + } +}