├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── dynamodb-spring-boot-autoconfigure ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── wonwoo │ │ │ └── dynamodb │ │ │ └── autoconfigure │ │ │ ├── CreateTable.java │ │ │ ├── DynamoAutoConfiguration.java │ │ │ ├── DynamoDataAutoConfiguration.java │ │ │ ├── DynamoDbCreateTable.java │ │ │ ├── DynamoDbCreateTableBeanPostProcessor.java │ │ │ ├── DynamoDbMapping.java │ │ │ ├── DynamoProperties.java │ │ │ ├── DynamoRepositoriesAutoConfiguration.java │ │ │ ├── DynamoRepositoriesAutoConfigureRegistrar.java │ │ │ └── EmbeddedDynamoAutoConfiguration.java │ └── resources │ │ └── META-INF │ │ ├── additional-spring-configuration-metadata.json │ │ └── spring.factories │ └── test │ └── java │ └── com │ └── github │ └── wonwoo │ └── dynamodb │ ├── DynamoDbMappingTests.java │ ├── TestAutoConfigurationPackage.java │ ├── TestAutoConfigurationPackageRegistrar.java │ ├── autoconfigure │ ├── DynamoAutoConfigurationTests.java │ ├── DynamoDataAutoConfigurationTests.java │ ├── DynamoDbCreateTableTests.java │ ├── DynamoPropertiesTests.java │ ├── DynamoRepositoriesAutoConfigurationTests.java │ ├── EmbeddedDynamoAutoConfigurationTests.java │ └── person │ │ ├── Person.java │ │ └── PersonRepository.java │ └── empty │ └── EmptyDataPackage.java ├── dynamodb-spring-boot-core ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── github │ │ └── wonwoo │ │ └── dynamodb │ │ └── repository │ │ ├── DynamoDBRepository.java │ │ ├── DynamoDBRepositoryFactory.java │ │ ├── DynamoDBRepositoryFactoryBean.java │ │ └── SimpleDynamoDBRepository.java │ └── test │ └── java │ └── com │ └── github │ └── wonwoo │ └── dynamodb │ └── repository │ ├── DynamoDBRepositoryFactoryTests.java │ ├── EmptyRepository.java │ ├── Person.java │ ├── PersonRepository.java │ └── SimpleDynamoDBRepositoryTests.java ├── dynamodb-spring-boot-sample ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── wonwoo │ │ │ └── dynamodb │ │ │ ├── SampleApplication.java │ │ │ └── domain │ │ │ ├── Person.java │ │ │ └── PersonRepository.java │ └── resources │ │ └── application.properties │ └── test │ ├── java │ └── com │ │ └── github │ │ └── wonwoo │ │ └── dynamodb │ │ └── PersonRepositoryTests.java │ └── resources │ └── application.properties ├── dynamodb-spring-boot-starter-test └── pom.xml ├── dynamodb-spring-boot-starter └── pom.xml ├── dynamodb-spring-boot-test-autoconfigure ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── github │ │ │ └── wonwoo │ │ │ └── dynamodb │ │ │ └── test │ │ │ └── autoconfigure │ │ │ ├── AutoConfigureDynamo.java │ │ │ ├── DynamoTest.java │ │ │ └── DynamoTypeExcludeFilter.java │ └── resources │ │ └── META-INF │ │ └── spring.factories │ └── test │ └── java │ └── com │ └── github │ └── wonwoo │ └── dynamodb │ └── test │ └── autoconfigure │ ├── DynamoTestIntegrationTest.java │ ├── DynamoTypeExcludeFilterTests.java │ ├── EmptyApplication.java │ ├── ExampleComponent.java │ ├── ExampleService.java │ ├── Person.java │ └── PersonRepository.java └── pom.xml /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: dynamodb-spring-boot -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | script: mvn clean install jacoco:report coveralls:report -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dynamodb-spring-boot 2 | 3 | [![Coverage Status](https://coveralls.io/repos/github/wonwoo/dynamodb-spring-boot/badge.svg?branch=master)](https://coveralls.io/github/wonwoo/dynamodb-spring-boot?branch=master) [![Build Status](https://travis-ci.org/wonwoo/dynamodb-spring-boot.svg?branch=master)](https://travis-ci.org/wonwoo/dynamodb-spring-boot) [![Build Status](https://semaphoreci.com/api/v1/wonwoo/dynamodb-spring-boot/branches/master/badge.svg)](https://semaphoreci.com/wonwoo/dynamodb-spring-boot) [ ![Download](https://api.bintray.com/packages/wonwoo/dynamodb-spring-boot/dynamodb-spring-boot/images/download.svg) ](https://bintray.com/wonwoo/dynamodb-spring-boot/dynamodb-spring-boot/_latestVersion) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.wonwoo/dynamodb-spring-boot/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.wonwoo/dynamodb-spring-boot) 4 | 5 | 6 | ### spring boot version 7 | 8 | | dynamodb-spring-boot-starter version | spring-data-dynamodb version | Spring Boot version | 9 | | ------------------------------------- | --------------------------------------- |--------------------------------| 10 | | 0.1.2 | 4.5.x | >= 1.4.0 < 2.0 | 11 | | 1.0.x | 5.0.x | >= 2.0 | 12 | 13 | 14 | ### dynamodb-spring-boot Example 15 | 16 | 1. application.properties 17 | ``` 18 | spring.data.dynamodb.access-key= 19 | spring.data.dynamodb.secret-key= 20 | ``` 21 | 22 | 2. PersonRepository 23 | ```java 24 | @EnableScan 25 | public interface PersonRepository extends DynamoDBRepository { 26 | } 27 | ``` 28 | 29 | 3. Person 30 | 31 | ```java 32 | @DynamoDBTable(tableName = "persons") 33 | public class Person { 34 | 35 | @DynamoDBHashKey 36 | @DynamoDBAutoGeneratedKey 37 | private String id; 38 | private String name; 39 | 40 | public Person() { 41 | 42 | } 43 | // getter setter etc 44 | } 45 | ``` 46 | 47 | 4. Sample 48 | ```java 49 | @Bean 50 | CommandLineRunner commandLineRunner(PersonRepository personRepository) { 51 | return args -> { 52 | personRepository.save(Arrays.asList( 53 | new Person("kevin"), 54 | new Person("josh long")) 55 | ); 56 | personRepository.findAll() 57 | .forEach(System.out::println); 58 | }; 59 | } 60 | ``` 61 | 62 | #### Maven Install 63 | 64 | ```xml 65 | 66 | com.github.wonwoo 67 | dynamodb-spring-boot-starter 68 | {version}-RELEASE 69 | 70 | ``` 71 | 72 | #### Create DDL 73 | ``` 74 | spring.data.dynamodb.ddl.enabled=true 75 | ``` 76 | 77 | `spring.data.dynamodb.ddl.enabled` default by `false` 78 | 79 | ### dynamodb-spring-boot-test Example 80 | 81 | #### @DynamoTest 82 | 83 | ```java 84 | @DynamoTest 85 | @RunWith(SpringRunner.class) 86 | public class PersonRepositoryTests { 87 | 88 | @Autowired 89 | private PersonRepository personRepository; 90 | 91 | @Test 92 | public void save() { 93 | List persons = personRepository.findAll(); 94 | assertThat(persons).hasSize(2); 95 | } 96 | } 97 | 98 | ``` 99 | 100 | #### Maven Install 101 | 102 | ```xml 103 | 104 | com.github.wonwoo 105 | dynamodb-spring-boot-starter-test 106 | {version}-RELEASE 107 | test 108 | 109 | ``` 110 | 111 | 112 | #### Embedded Dynamodb setting 113 | 114 | 1. maven dependency 115 | ```xml 116 | 117 | com.amazonaws 118 | DynamoDBLocal 119 | {local.version} 120 | test 121 | 122 | 123 | 124 | com.almworks.sqlite4java 125 | sqlite4java 126 | {local.version} 127 | test 128 | 129 | 130 | ``` 131 | 132 | 2. maven plugins 133 | 134 | ```xml 135 | 136 | 137 | org.apache.maven.plugins 138 | maven-dependency-plugin 139 | 140 | 141 | copy-dependencies 142 | process-test-resources 143 | 144 | copy-dependencies 145 | 146 | 147 | ${project.build.directory}/dependencies 148 | false 149 | false 150 | true 151 | 152 | 153 | 154 | 155 | 156 | maven-surefire-plugin 157 | ${maven-surefire-plugin.version} 158 | 159 | -Dsqlite4java.library.path=${basedir}/target/dependencies 160 | 161 | 162 | 163 | ``` 164 | 165 | ### Sample code github 166 | 167 | [Sample](https://github.com/wonwoo/dynamodb-spring-boot/tree/master/dynamodb-spring-boot-sample) 168 | 169 | [SampleApplication](https://github.com/wonwoo/dynamodb-spring-boot/blob/master/dynamodb-spring-boot-sample/src/main/java/com/github/wonwoo/dynamodb/SampleApplication.java) 170 | 171 | [PersonRepositoryTests](https://github.com/wonwoo/dynamodb-spring-boot/blob/master/dynamodb-spring-boot-sample/src/test/java/com/github/wonwoo/dynamodb/PersonRepositoryTests.java) 172 | 173 | # Read more here 174 | - [spring-data-dynamodb](https://github.com/spring-data-dynamodb/spring-data-dynamodb) 175 | - [spring-data-dynamodb-wiki](https://github.com/spring-data-dynamodb/spring-data-dynamodb/wiki) 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dynamodb-spring-boot 7 | com.github.wonwoo 8 | 1.0.2-SNAPSHOT 9 | 10 | jar 11 | 4.0.0 12 | 13 | 14 | 15 | The Apache Software License, Version 2.0 16 | https://opensource.org/licenses/Apache-2.0 17 | repo 18 | 19 | 20 | 21 | 22 | https://github.com/wonwoo/dynamodb-spring-boot 23 | 24 | 25 | dynamodb-spring-boot-autoconfigure 26 | 27 | 28 | 1.8 29 | 1.8 30 | 1.8 31 | 1.8 32 | 33 | 34 | 35 | 36 | com.github.wonwoo 37 | dynamodb-spring-boot-core 38 | 39 | 40 | 41 | com.github.derjust 42 | spring-data-dynamodb 43 | true 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-configuration-processor 49 | true 50 | 51 | 52 | 53 | com.amazonaws 54 | DynamoDBLocal 55 | true 56 | 57 | 58 | 59 | 60 | com.almworks.sqlite4java 61 | sqlite4java 62 | true 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-test 68 | test 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-dependency-plugin 77 | 78 | 79 | copy-dependencies 80 | process-test-resources 81 | 82 | copy-dependencies 83 | 84 | 85 | ${project.build.directory}/dependencies 86 | false 87 | false 88 | true 89 | 90 | 91 | 92 | 93 | 94 | maven-surefire-plugin 95 | ${maven-surefire-plugin.version} 96 | 97 | ${surefireArgLine} -Dsqlite4java.library.path=${basedir}/target/dependencies 98 | 99 | **/*Tests.java 100 | **/*Test.java 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/CreateTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.amazonaws.services.dynamodbv2.model.CreateTableResult; 20 | 21 | /** 22 | * @author wonwoo 23 | */ 24 | public interface CreateTable { 25 | 26 | boolean isTable(String tableName); 27 | 28 | CreateTableResult createTable(String tableName, String hashKeyName); 29 | 30 | boolean waitTableExists(String tableName, long secondsBetweenPolls, long timeoutSeconds); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import org.springframework.boot.autoconfigure.AutoConfigureBefore; 20 | import org.springframework.boot.autoconfigure.condition.*; 21 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 22 | import org.springframework.boot.context.properties.bind.Binder; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.context.annotation.ConditionContext; 25 | import org.springframework.context.annotation.Conditional; 26 | import org.springframework.context.annotation.Configuration; 27 | import org.springframework.core.env.Environment; 28 | import org.springframework.core.type.AnnotatedTypeMetadata; 29 | import org.springframework.util.StringUtils; 30 | 31 | import com.amazonaws.auth.AWSCredentialsProvider; 32 | import com.amazonaws.auth.AWSStaticCredentialsProvider; 33 | import com.amazonaws.auth.BasicAWSCredentials; 34 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 35 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; 36 | 37 | /** 38 | * @author wonwoo 39 | */ 40 | @Configuration 41 | @ConditionalOnClass(AmazonDynamoDB.class) 42 | @Conditional(DynamoAutoConfiguration.AwsDynamoCondition.class) 43 | @EnableConfigurationProperties(DynamoProperties.class) 44 | @AutoConfigureBefore(EmbeddedDynamoAutoConfiguration.class) 45 | public class DynamoAutoConfiguration { 46 | 47 | private final DynamoProperties properties; 48 | 49 | public DynamoAutoConfiguration(DynamoProperties properties) { 50 | this.properties = properties; 51 | } 52 | 53 | @Bean 54 | @ConditionalOnMissingBean(name = "awsDynamoCredentialsProvider") 55 | public AWSCredentialsProvider awsDynamoCredentialsProvider() { 56 | return new AWSStaticCredentialsProvider(new BasicAWSCredentials( 57 | this.properties.getAccessKey(), this.properties.getSecretKey())); 58 | } 59 | 60 | @Bean 61 | @ConditionalOnMissingBean 62 | public AmazonDynamoDB amazonDynamoDB(AWSCredentialsProvider awsDynamoCredentialsProvider) { 63 | return AmazonDynamoDBClient 64 | .builder() 65 | .withCredentials(awsDynamoCredentialsProvider) 66 | .withRegion(properties.getRegions()) 67 | .build(); 68 | } 69 | 70 | protected static class AwsDynamoCondition extends SpringBootCondition { 71 | 72 | @Override 73 | public ConditionOutcome getMatchOutcome(ConditionContext context, 74 | AnnotatedTypeMetadata metadata) { 75 | ConditionMessage.Builder message = ConditionMessage 76 | .forCondition("DynamoDB"); 77 | Environment environment = context.getEnvironment(); 78 | Binder binder = Binder.get(environment); 79 | DynamoProperties dynamoProperties = binder.bind("spring.data.dynamodb", 80 | DynamoProperties.class) 81 | .orElseGet(DynamoProperties::new); 82 | String accessKey = dynamoProperties.getAccessKey(); 83 | String secretKey = dynamoProperties.getSecretKey(); 84 | if (StringUtils.hasLength(accessKey) && StringUtils.hasLength(secretKey)) { 85 | return ConditionOutcome.match( 86 | message.available("found accessKey and secretKey property")); 87 | } 88 | return ConditionOutcome.noMatch( 89 | message.because("not found accessKey and secretKey property")); 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoDataAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; 20 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate; 21 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBMappingContext; 22 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 26 | import org.springframework.boot.autoconfigure.domain.EntityScanner; 27 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 28 | import org.springframework.context.ApplicationContext; 29 | import org.springframework.context.annotation.Bean; 30 | import org.springframework.context.annotation.Configuration; 31 | 32 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 33 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig; 34 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 35 | 36 | /** 37 | * @author wonwoo 38 | */ 39 | @Configuration 40 | @ConditionalOnClass(DynamoDBTemplate.class) 41 | @AutoConfigureAfter({DynamoAutoConfiguration.class, EmbeddedDynamoAutoConfiguration.class}) 42 | @EnableConfigurationProperties(DynamoProperties.class) 43 | public class DynamoDataAutoConfiguration { 44 | 45 | private final ApplicationContext applicationContext; 46 | 47 | public DynamoDataAutoConfiguration(ApplicationContext applicationContext) { 48 | this.applicationContext = applicationContext; 49 | } 50 | 51 | @Bean 52 | @ConditionalOnMissingBean 53 | public DynamoDBMappingContext dynamoDBMappingContext() throws ClassNotFoundException { 54 | DynamoDBMappingContext context = new DynamoDBMappingContext(); 55 | context.setInitialEntitySet(new EntityScanner(this.applicationContext) 56 | .scan(DynamoDBTable.class)); 57 | return context; 58 | } 59 | 60 | @Bean 61 | @ConditionalOnMissingBean 62 | public DynamoDbMapping dynamoDbMapping(CreateTable createTable, 63 | DynamoDBMappingContext context) { 64 | return new DynamoDbMapping(createTable, context); 65 | } 66 | 67 | @Bean 68 | @ConditionalOnMissingBean 69 | public CreateTable createTable(AmazonDynamoDB amazonDynamoDB, 70 | DynamoProperties properties) { 71 | DynamoDbCreateTable createTable = new DynamoDbCreateTable(amazonDynamoDB); 72 | createTable.setReadCapacityUnits(properties.getReadCapacityUnits()); 73 | createTable.setWriteCapacityUnits(properties.getWriteCapacityUnits()); 74 | return createTable; 75 | } 76 | 77 | @Bean 78 | @ConditionalOnMissingBean 79 | public DynamoDBMapperConfig dynamoDBMapperConfig() { 80 | return DynamoDBMapperConfig.DEFAULT; 81 | } 82 | 83 | @Bean 84 | @ConditionalOnMissingBean 85 | public DynamoDBMapper dynamoDBMapper(AmazonDynamoDB amazonDynamoDB, DynamoDBMapperConfig dynamoDBMapperConfig) { 86 | return new DynamoDBMapper(amazonDynamoDB, dynamoDBMapperConfig); 87 | } 88 | 89 | @Bean 90 | @ConditionalOnMissingBean 91 | public DynamoDBTemplate dynamoDBTemplate(AmazonDynamoDB amazonDynamoDB, DynamoDBMapper dynamoDBMapper) { 92 | return new DynamoDBTemplate(amazonDynamoDB, dynamoDBMapper); 93 | } 94 | 95 | @ConditionalOnProperty(prefix = "spring.data.dynamodb.ddl", name = "enabled", havingValue = "true", matchIfMissing = false) 96 | @Configuration 97 | protected static class DynamoDbCreateTableAutoConfiguration { 98 | @Bean 99 | public DynamoDbCreateTableBeanPostProcessor dynamoDbCreateTableBeanPostProcessor() { 100 | return new DynamoDbCreateTableBeanPostProcessor(); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoDbCreateTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import com.amazonaws.AmazonClientException; 27 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 28 | import com.amazonaws.services.dynamodbv2.model.*; 29 | 30 | /** 31 | * @author wonwoo 32 | */ 33 | public class DynamoDbCreateTable implements CreateTable { 34 | 35 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 36 | 37 | private Long readCapacityUnits = 10L; 38 | private Long writeCapacityUnits = 10L; 39 | 40 | private final AmazonDynamoDB amazonDynamoDB; 41 | 42 | public DynamoDbCreateTable(AmazonDynamoDB amazonDynamoDB) { 43 | this.amazonDynamoDB = amazonDynamoDB; 44 | } 45 | 46 | @Override 47 | public boolean isTable(String tableName) { 48 | ListTablesResult tables = amazonDynamoDB.listTables(); 49 | List tableNames = tables.getTableNames(); 50 | return tableNames.size() != 0 && tableNames.stream().anyMatch(s -> s.equals(tableName)); 51 | } 52 | 53 | @Override 54 | public CreateTableResult createTable(String tableName, String hashKeyName) { 55 | List attributeDefinitions = new ArrayList<>(); 56 | attributeDefinitions.add(new AttributeDefinition(hashKeyName, ScalarAttributeType.S)); 57 | List ks = new ArrayList<>(); 58 | ks.add(new KeySchemaElement(hashKeyName, KeyType.HASH)); 59 | ProvisionedThroughput provisionedthroughput = 60 | new ProvisionedThroughput(this.readCapacityUnits, this.writeCapacityUnits); 61 | CreateTableRequest request = 62 | new CreateTableRequest() 63 | .withTableName(tableName) 64 | .withAttributeDefinitions(attributeDefinitions) 65 | .withKeySchema(ks) 66 | .withProvisionedThroughput(provisionedthroughput); 67 | 68 | return amazonDynamoDB.createTable(request); 69 | } 70 | 71 | private TableStatus tableStatus(String tableName) { 72 | DescribeTableRequest request = new DescribeTableRequest(); 73 | request.setTableName(tableName); 74 | try { 75 | DescribeTableResult result = amazonDynamoDB.describeTable(request); 76 | TableStatus tableStatus = TableStatus.fromValue(result.getTable().getTableStatus()); 77 | logger.debug("table status {} ", tableStatus); 78 | return tableStatus; 79 | } catch (ResourceNotFoundException e) { 80 | logger.debug("ResourceNotFound is TableName {}", tableName); 81 | return null; 82 | } catch (AmazonClientException e) { 83 | logger.error("Unknown error ", e); 84 | throw new IllegalStateException("Unknown Exception", e); 85 | } 86 | } 87 | 88 | @Override 89 | public boolean waitTableExists(String tableName, long secondsPolls, long timeout) { 90 | long sleepTime = TimeUnit.SECONDS.toMillis(timeout); 91 | 92 | while (!leaseTableExists(tableName)) { 93 | if (sleepTime <= 0) { 94 | return false; 95 | } 96 | long timeToSleepMillis = Math.min(TimeUnit.SECONDS.toMillis(secondsPolls), sleepTime); 97 | sleepTime -= sleep(timeToSleepMillis); 98 | } 99 | 100 | return true; 101 | } 102 | 103 | private boolean leaseTableExists(String tableName) { 104 | return TableStatus.ACTIVE == tableStatus(tableName); 105 | } 106 | 107 | private long sleep(long timeToSleepMillis) { 108 | long startTime = System.currentTimeMillis(); 109 | 110 | try { 111 | Thread.sleep(timeToSleepMillis); 112 | } catch (InterruptedException e) { 113 | logger.info("Interrupted while sleeping"); 114 | } 115 | 116 | return System.currentTimeMillis() - startTime; 117 | } 118 | 119 | public void setReadCapacityUnits(Long readCapacityUnits) { 120 | this.readCapacityUnits = readCapacityUnits; 121 | } 122 | 123 | public void setWriteCapacityUnits(Long writeCapacityUnits) { 124 | this.writeCapacityUnits = writeCapacityUnits; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoDbCreateTableBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import org.springframework.beans.BeansException; 20 | import org.springframework.beans.factory.config.BeanPostProcessor; 21 | 22 | /** 23 | * @author wonwoo 24 | */ 25 | public class DynamoDbCreateTableBeanPostProcessor implements BeanPostProcessor { 26 | 27 | @Override 28 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 29 | return bean; 30 | } 31 | 32 | @Override 33 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 34 | if (bean instanceof DynamoDbMapping) { 35 | ((DynamoDbMapping) bean).createTable(); 36 | } 37 | return bean; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoDbMapping.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import java.lang.annotation.Annotation; 20 | import java.lang.reflect.AnnotatedElement; 21 | import java.util.ArrayList; 22 | import java.util.Collection; 23 | import java.util.List; 24 | 25 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBMappingContext; 26 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBPersistentEntity; 27 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBPersistentEntityImpl; 28 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBPersistentProperty; 29 | import org.springframework.core.annotation.AnnotatedElementUtils; 30 | import org.springframework.data.util.TypeInformation; 31 | import org.springframework.util.StringUtils; 32 | 33 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 34 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 35 | import com.amazonaws.services.dynamodbv2.model.CreateTableResult; 36 | 37 | /** 38 | * @author wonwoo 39 | */ 40 | public class DynamoDbMapping { 41 | 42 | private final CreateTable createTable; 43 | private final DynamoDBMappingContext context; 44 | 45 | private static final String ACTIVE = "ACTIVE"; 46 | private static final long DEFAULT_SECONDS_BETWEEN_POLLS = 5L; 47 | private static final long DEFAULT_TIMEOUT_SECONDS = 30L; 48 | 49 | private long secondsBetweenPolls = DEFAULT_SECONDS_BETWEEN_POLLS; 50 | private long timeoutSeconds = DEFAULT_TIMEOUT_SECONDS; 51 | 52 | public DynamoDbMapping(CreateTable createTable, DynamoDBMappingContext context) { 53 | this.createTable = createTable; 54 | this.context = context; 55 | } 56 | 57 | public Collection> getPersistentEntities() { 58 | return context.getPersistentEntities(); 59 | } 60 | 61 | public DynamoDBPersistentEntityImpl getPersistentEntity(Class type) { 62 | DynamoDBPersistentEntityImpl persistentEntity = context.getPersistentEntity(type); 63 | if(persistentEntity == null) { 64 | throw new NullPointerException("persistentEntity is null"); 65 | } 66 | return persistentEntity; 67 | } 68 | 69 | public DynamoDBPersistentProperty getIdProperty(Class type) { 70 | return getPersistentEntity(type).getIdProperty(); 71 | } 72 | 73 | public TypeInformation getTypeInformation(Class type) { 74 | return getPersistentEntity(type).getTypeInformation(); 75 | } 76 | 77 | 78 | public List createTable() { 79 | List results = new ArrayList<>(); 80 | for (DynamoDBPersistentEntity entity : context.getPersistentEntities()) { 81 | DynamoDBPersistentProperty idProperty = entity.getIdProperty(); 82 | if(idProperty == null) { 83 | throw new NullPointerException("entity property Id is null"); 84 | } 85 | DynamoDBTable table = findMergedAnnotation(entity.getTypeInformation().getType(), DynamoDBTable.class); 86 | if (!createTable.isTable(table.tableName())) { 87 | CreateTableResult createTableTable = createTable.createTable(table.tableName(), getIdProperty(idProperty)); 88 | if(!ACTIVE.equals(createTableTable.getTableDescription().getTableStatus())) { 89 | createTable.waitTableExists(table.tableName(), this.secondsBetweenPolls, this.timeoutSeconds); 90 | } 91 | results.add(createTableTable); 92 | } 93 | } 94 | return results; 95 | } 96 | 97 | private String getIdProperty(DynamoDBPersistentProperty idProperty) { 98 | DynamoDBHashKey dynamoDBHashKey = idProperty.findAnnotation(DynamoDBHashKey.class); 99 | String attributeName = dynamoDBHashKey.attributeName(); 100 | if(StringUtils.hasText(attributeName)) { 101 | return attributeName; 102 | } 103 | return idProperty.getName(); 104 | } 105 | 106 | 107 | private A findMergedAnnotation(AnnotatedElement element, Class annotationType) { 108 | return AnnotatedElementUtils.findMergedAnnotation(element, annotationType); 109 | } 110 | 111 | public void setSecondsBetweenPolls(long secondsBetweenPolls) { 112 | this.secondsBetweenPolls = secondsBetweenPolls; 113 | } 114 | 115 | public void setTimeoutSeconds(long timeoutSeconds) { 116 | this.timeoutSeconds = timeoutSeconds; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | 21 | import com.amazonaws.regions.Regions; 22 | 23 | /** 24 | * @author wonwoo 25 | */ 26 | @ConfigurationProperties("spring.data.dynamodb") 27 | public class DynamoProperties { 28 | 29 | /** 30 | * aws accessKey 31 | */ 32 | private String accessKey; 33 | 34 | /** 35 | * aws secretKey 36 | */ 37 | private String secretKey; 38 | 39 | /** 40 | * regions default AP_NORTHEAST_2 41 | */ 42 | private Regions regions = Regions.AP_NORTHEAST_2; 43 | 44 | /** 45 | * dynamoDb Create Table readCapacityUnits default 10 46 | */ 47 | private Long readCapacityUnits = 10L; 48 | 49 | /** 50 | * dynamoDb Create Table writeCapacityUnits default 10 51 | */ 52 | private Long writeCapacityUnits = 10L; 53 | 54 | public String getAccessKey() { 55 | return accessKey; 56 | } 57 | 58 | public void setAccessKey(String accessKey) { 59 | this.accessKey = accessKey; 60 | } 61 | 62 | public String getSecretKey() { 63 | return secretKey; 64 | } 65 | 66 | public void setSecretKey(String secretKey) { 67 | this.secretKey = secretKey; 68 | } 69 | 70 | public Regions getRegions() { 71 | return regions; 72 | } 73 | 74 | public void setRegions(Regions regions) { 75 | this.regions = regions; 76 | } 77 | 78 | 79 | public void setReadCapacityUnits(Long readCapacityUnits) { 80 | this.readCapacityUnits = readCapacityUnits; 81 | } 82 | 83 | public void setWriteCapacityUnits(Long writeCapacityUnits) { 84 | this.writeCapacityUnits = writeCapacityUnits; 85 | } 86 | 87 | public Long getReadCapacityUnits() { 88 | return readCapacityUnits; 89 | } 90 | 91 | public Long getWriteCapacityUnits() { 92 | return writeCapacityUnits; 93 | } 94 | 95 | @Override 96 | public boolean equals(Object o) { 97 | if (this == o) return true; 98 | if (o == null || getClass() != o.getClass()) return false; 99 | 100 | DynamoProperties that = (DynamoProperties) o; 101 | 102 | if (accessKey != null ? !accessKey.equals(that.accessKey) : that.accessKey != null) return false; 103 | if (secretKey != null ? !secretKey.equals(that.secretKey) : that.secretKey != null) return false; 104 | if (regions != that.regions) return false; 105 | if (readCapacityUnits != null ? !readCapacityUnits.equals(that.readCapacityUnits) : that.readCapacityUnits != null) 106 | return false; 107 | return writeCapacityUnits != null ? writeCapacityUnits.equals(that.writeCapacityUnits) : that.writeCapacityUnits == null; 108 | } 109 | 110 | @Override 111 | public int hashCode() { 112 | int result = accessKey != null ? accessKey.hashCode() : 0; 113 | result = 31 * result + (secretKey != null ? secretKey.hashCode() : 0); 114 | result = 31 * result + (regions != null ? regions.hashCode() : 0); 115 | result = 31 * result + (readCapacityUnits != null ? readCapacityUnits.hashCode() : 0); 116 | result = 31 * result + (writeCapacityUnits != null ? writeCapacityUnits.hashCode() : 0); 117 | return result; 118 | } 119 | 120 | @Override 121 | public String toString() { 122 | return "DynamoProperties{" + 123 | "accessKey='" + accessKey + '\'' + 124 | ", secretKey='" + secretKey + '\'' + 125 | ", regions=" + regions + 126 | ", readCapacityUnits=" + readCapacityUnits + 127 | ", writeCapacityUnits=" + writeCapacityUnits + 128 | '}'; 129 | } 130 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoRepositoriesAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 20 | import com.github.wonwoo.dynamodb.repository.DynamoDBRepositoryFactoryBean; 21 | import org.socialsignin.spring.data.dynamodb.repository.DynamoDBCrudRepository; 22 | import org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBRepositoryConfigExtension; 23 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 26 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 27 | import org.springframework.context.annotation.Configuration; 28 | import org.springframework.context.annotation.Import; 29 | 30 | /** 31 | * @author wonwoo 32 | */ 33 | @Configuration 34 | @ConditionalOnClass({AmazonDynamoDB.class, DynamoDBCrudRepository.class}) 35 | @ConditionalOnMissingBean({DynamoDBRepositoryFactoryBean.class, 36 | DynamoDBRepositoryConfigExtension.class}) 37 | @ConditionalOnProperty(prefix = "spring.data.dynamodb.repositories", name = "enabled", havingValue = "true", matchIfMissing = true) 38 | @Import(DynamoRepositoriesAutoConfigureRegistrar.class) 39 | @AutoConfigureAfter(DynamoDataAutoConfiguration.class) 40 | public class DynamoRepositoriesAutoConfiguration { 41 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoRepositoriesAutoConfigureRegistrar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.github.wonwoo.dynamodb.repository.DynamoDBRepositoryFactoryBean; 20 | import org.socialsignin.spring.data.dynamodb.repository.config.DynamoDBRepositoryConfigExtension; 21 | import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; 22 | import org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport; 23 | import org.springframework.data.repository.config.RepositoryConfigurationExtension; 24 | 25 | import java.lang.annotation.Annotation; 26 | 27 | /** 28 | * @author wonwoo 29 | */ 30 | class DynamoRepositoriesAutoConfigureRegistrar extends AbstractRepositoryConfigurationSourceSupport { 31 | 32 | @Override 33 | protected Class getAnnotation() { 34 | return EnableDynamoDBRepositories.class; 35 | } 36 | 37 | @Override 38 | protected Class getConfiguration() { 39 | return EnableDynamoRepositoriesConfiguration.class; 40 | } 41 | 42 | @Override 43 | protected RepositoryConfigurationExtension getRepositoryConfigurationExtension() { 44 | return new DynamoDBRepositoryConfigExtension(); 45 | } 46 | 47 | @EnableDynamoDBRepositories(repositoryFactoryBeanClass = DynamoDBRepositoryFactoryBean.class) 48 | private static class EnableDynamoRepositoriesConfiguration { 49 | 50 | } 51 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/autoconfigure/EmbeddedDynamoAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.almworks.sqlite4java.SQLite; 20 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 21 | import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded; 22 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 25 | import org.springframework.context.annotation.Bean; 26 | import org.springframework.context.annotation.Configuration; 27 | 28 | /** 29 | * @author wonwoo 30 | */ 31 | @Configuration 32 | @ConditionalOnClass({DynamoDBEmbedded.class, SQLite.class}) 33 | @AutoConfigureAfter(DynamoAutoConfiguration.class) 34 | public class EmbeddedDynamoAutoConfiguration { 35 | 36 | @Bean(destroyMethod = "shutdown") 37 | @ConditionalOnMissingBean 38 | public AmazonDynamoDB amazonDynamoDB() { 39 | return DynamoDBEmbedded.create().amazonDynamoDB(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "spring.data.dynamodb.repositories.enabled", 5 | "type": "java.lang.Boolean", 6 | "description": "Enable Dynamodb repositories by default.", 7 | "defaultValue": true 8 | }, 9 | { 10 | "name": "spring.data.dynamodb.ddl.enabled", 11 | "type": "java.lang.Boolean", 12 | "description": "Enable Dynamodb create Table by default.", 13 | "defaultValue": false 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.github.wonwoo.dynamodb.autoconfigure.DynamoAutoConfiguration,\ 3 | com.github.wonwoo.dynamodb.autoconfigure.DynamoDataAutoConfiguration,\ 4 | com.github.wonwoo.dynamodb.autoconfigure.DynamoRepositoriesAutoConfiguration -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/DynamoDbMappingTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb; 18 | 19 | import java.util.Arrays; 20 | import java.util.Collection; 21 | import java.util.HashSet; 22 | import java.util.List; 23 | 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.mockito.Mock; 28 | import org.mockito.junit.MockitoJUnitRunner; 29 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBMappingContext; 30 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBPersistentEntityImpl; 31 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBPersistentProperty; 32 | import org.springframework.data.util.TypeInformation; 33 | 34 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 35 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 36 | import com.amazonaws.services.dynamodbv2.model.CreateTableResult; 37 | import com.amazonaws.services.dynamodbv2.model.ListTablesResult; 38 | import com.amazonaws.services.dynamodbv2.model.TableDescription; 39 | import com.amazonaws.services.dynamodbv2.model.TableStatus; 40 | import com.github.wonwoo.dynamodb.autoconfigure.CreateTable; 41 | import com.github.wonwoo.dynamodb.autoconfigure.DynamoDbMapping; 42 | 43 | import static org.assertj.core.api.Assertions.assertThat; 44 | import static org.mockito.ArgumentMatchers.any; 45 | import static org.mockito.ArgumentMatchers.anyLong; 46 | import static org.mockito.BDDMockito.given; 47 | import static org.mockito.Mockito.verify; 48 | 49 | /** 50 | * @author wonwoo 51 | */ 52 | @RunWith(MockitoJUnitRunner.class) 53 | public class DynamoDbMappingTests { 54 | 55 | private DynamoDBMappingContext context; 56 | 57 | @Mock 58 | private CreateTable createTable; 59 | 60 | 61 | private DynamoDbMapping dynamoDbMapping; 62 | 63 | @Before 64 | public void setup() { 65 | context = new DynamoDBMappingContext(); 66 | HashSet> initialEntitySet = new HashSet<>(); 67 | initialEntitySet.add(Person.class); 68 | initialEntitySet.add(Foo.class); 69 | context.setInitialEntitySet(initialEntitySet); 70 | context.afterPropertiesSet(); 71 | this.dynamoDbMapping = new DynamoDbMapping(createTable, context); 72 | this.dynamoDbMapping.setSecondsBetweenPolls(10); 73 | this.dynamoDbMapping.setTimeoutSeconds(30); 74 | } 75 | 76 | @Test 77 | public void getPersistentEntities() { 78 | Collection> entities = this.dynamoDbMapping.getPersistentEntities(); 79 | assertThat(entities).hasSize(2); 80 | } 81 | 82 | @Test 83 | public void getPersistentEntityPerson() { 84 | DynamoDBPersistentEntityImpl entity = this.dynamoDbMapping.getPersistentEntity(Person.class); 85 | DynamoDBPersistentProperty idProperty = entity.getIdProperty(); 86 | DynamoDBHashKey dynamoDBHashKey = idProperty.getRequiredAnnotation(DynamoDBHashKey.class); 87 | assertThat(dynamoDBHashKey.attributeName()).isEmpty(); 88 | assertThat(idProperty.getActualType()).isEqualTo(String.class); 89 | } 90 | 91 | @Test 92 | public void getPersistentEntityFoo() { 93 | DynamoDBPersistentEntityImpl entity = this.dynamoDbMapping.getPersistentEntity(Foo.class); 94 | DynamoDBPersistentProperty idProperty = entity.getIdProperty(); 95 | DynamoDBHashKey dynamoDBHashKey = idProperty.getRequiredAnnotation(DynamoDBHashKey.class); 96 | assertThat(dynamoDBHashKey.attributeName()).isNotBlank(); 97 | assertThat(dynamoDBHashKey.attributeName()).isEqualTo("uuid"); 98 | assertThat(idProperty.getActualType()).isEqualTo(String.class); 99 | } 100 | 101 | @Test 102 | public void getIdPropertyPerson() { 103 | DynamoDBPersistentProperty idProperty = this.dynamoDbMapping.getIdProperty(Person.class); 104 | DynamoDBHashKey dynamoDBHashKey = idProperty.getRequiredAnnotation(DynamoDBHashKey.class); 105 | assertThat(dynamoDBHashKey.attributeName()).isEmpty(); 106 | assertThat(idProperty.getActualType()).isEqualTo(String.class); 107 | } 108 | 109 | @Test 110 | public void getIdPropertyFoo() { 111 | DynamoDBPersistentProperty idProperty = this.dynamoDbMapping.getIdProperty(Foo.class); 112 | DynamoDBHashKey dynamoDBHashKey = idProperty.getRequiredAnnotation(DynamoDBHashKey.class); 113 | assertThat(dynamoDBHashKey.attributeName()).isNotBlank(); 114 | assertThat(dynamoDBHashKey.attributeName()).isEqualTo("uuid"); 115 | assertThat(idProperty.getActualType()).isEqualTo(String.class); 116 | } 117 | 118 | @Test 119 | public void getTypeInformationPerson() { 120 | TypeInformation typeInformation = this.dynamoDbMapping.getTypeInformation(Person.class); 121 | assertThat(typeInformation.getType()).isEqualTo(Person.class); 122 | } 123 | 124 | @Test 125 | public void getTypeInformationFoo() { 126 | TypeInformation typeInformation = this.dynamoDbMapping.getTypeInformation(Foo.class); 127 | assertThat(typeInformation.getType()).isEqualTo(Foo.class); 128 | } 129 | 130 | @Test 131 | public void createTable() { 132 | CreateTableResult value = new CreateTableResult(); 133 | TableDescription tableDescription = new TableDescription(); 134 | tableDescription.setItemCount(100L); 135 | tableDescription.setTableStatus(TableStatus.CREATING); 136 | value.setTableDescription(tableDescription); 137 | ListTablesResult listTablesResult = new ListTablesResult(); 138 | listTablesResult.setTableNames(Arrays.asList("foo", "bar")); 139 | 140 | given(createTable.isTable(any())).willReturn(false); 141 | given(createTable.createTable(any(), any())).willReturn(value); 142 | given(createTable.waitTableExists(any(), anyLong(), anyLong())).willReturn(true); 143 | List table = this.dynamoDbMapping.createTable(); 144 | assertThat(table).hasSize(2); 145 | assertThat(table.iterator().next().getTableDescription()).isEqualTo(tableDescription); 146 | assertThat(table.iterator().next().getTableDescription()).isEqualTo(tableDescription); 147 | verify(createTable).waitTableExists("persons", 10, 30); 148 | verify(createTable).waitTableExists("foo", 10, 30); 149 | } 150 | 151 | @DynamoDBTable(tableName = "foo") 152 | private static class Foo { 153 | @DynamoDBHashKey(attributeName = "uuid") 154 | private String id; 155 | 156 | public String getId() { 157 | return id; 158 | } 159 | 160 | public void setId(String id) { 161 | this.id = id; 162 | } 163 | } 164 | 165 | @DynamoDBTable(tableName = "persons") 166 | private static class Person { 167 | @DynamoDBHashKey 168 | private String id; 169 | 170 | public String getId() { 171 | return id; 172 | } 173 | 174 | public void setId(String id) { 175 | this.id = id; 176 | } 177 | } 178 | 179 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/TestAutoConfigurationPackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb; 18 | 19 | import java.lang.annotation.*; 20 | 21 | import org.springframework.context.annotation.Import; 22 | 23 | /** 24 | * @author wonwoo 25 | */ 26 | @Target(ElementType.TYPE) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | @Import(TestAutoConfigurationPackageRegistrar.class) 30 | public @interface TestAutoConfigurationPackage { 31 | 32 | Class value(); 33 | 34 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/TestAutoConfigurationPackageRegistrar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb; 18 | 19 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 20 | import org.springframework.boot.autoconfigure.AutoConfigurationPackages; 21 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; 22 | import org.springframework.core.annotation.AnnotationAttributes; 23 | import org.springframework.core.type.AnnotationMetadata; 24 | import org.springframework.util.ClassUtils; 25 | 26 | /** 27 | * @author wonwoo 28 | */ 29 | public class TestAutoConfigurationPackageRegistrar 30 | implements ImportBeanDefinitionRegistrar { 31 | 32 | @Override 33 | public void registerBeanDefinitions(AnnotationMetadata metadata, 34 | BeanDefinitionRegistry registry) { 35 | AnnotationAttributes attributes = AnnotationAttributes 36 | .fromMap(metadata.getAnnotationAttributes( 37 | TestAutoConfigurationPackage.class.getName(), true)); 38 | AutoConfigurationPackages.register(registry, 39 | ClassUtils.getPackageName(attributes.getString("value"))); 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoAutoConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | 20 | import org.junit.Test; 21 | import org.springframework.boot.autoconfigure.AutoConfigurations; 22 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 23 | 24 | import com.amazonaws.auth.AWSCredentialsProvider; 25 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; 28 | 29 | /** 30 | * @author wonwoo 31 | */ 32 | public class DynamoAutoConfigurationTests { 33 | 34 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); 35 | 36 | @Test 37 | public void notFoundDynamoDbAutoConfig() { 38 | contextRunner.withConfiguration(AutoConfigurations.of(DynamoAutoConfiguration.class)) 39 | .run(context -> { 40 | assertThat(context).doesNotHaveBean(AWSCredentialsProvider.class); 41 | assertThat(context).doesNotHaveBean(AmazonDynamoDB.class); 42 | }); 43 | } 44 | 45 | @Test 46 | public void dynamoDbAutoConfig() { 47 | contextRunner.withConfiguration(AutoConfigurations.of(DynamoAutoConfiguration.class)) 48 | .withPropertyValues("spring.data.dynamodb.access-key=test-access-key", "spring.data.dynamodb.secret-key=test-secret-key", 49 | "spring.data.dynamodb.readCapacityUnits=100", "spring.data.dynamodb.writeCapacityUnits=200") 50 | .run(context -> { 51 | assertThat(context).hasSingleBean(AWSCredentialsProvider.class); 52 | assertThat(context).hasSingleBean(AmazonDynamoDB.class); 53 | }); 54 | } 55 | 56 | 57 | @Test 58 | public void dynamoDbCamelCaseAutoConfig() { 59 | contextRunner.withConfiguration(AutoConfigurations.of(DynamoAutoConfiguration.class)) 60 | .withPropertyValues("spring.data.dynamodb.accessKey=testAccessKey", "spring.data.dynamodb.secretKey=testSecretKey", 61 | "spring.data.dynamodb.readCapacityUnits=100", "spring.data.dynamodb.writeCapacityUnits=200") 62 | .run(context -> { 63 | assertThat(context).hasSingleBean(AWSCredentialsProvider.class); 64 | assertThat(context).hasSingleBean(AmazonDynamoDB.class); 65 | }); 66 | } 67 | 68 | @Test 69 | public void dynamoDbUnderScoreAutoConfig() { 70 | contextRunner.withConfiguration(AutoConfigurations.of(DynamoAutoConfiguration.class)) 71 | .withPropertyValues("spring.data.dynamodb.access_key=test_access_key", "spring.data.dynamodb.secret_key=test_secret_key", 72 | "spring.data.dynamodb.readCapacityUnits=100", "spring.data.dynamodb.writeCapacityUnits=200") 73 | .run(context -> { 74 | assertThat(context).hasSingleBean(AWSCredentialsProvider.class); 75 | assertThat(context).hasSingleBean(AmazonDynamoDB.class); 76 | }); 77 | } 78 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoDataAutoConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 20 | import com.amazonaws.services.dynamodbv2.local.embedded.DynamoDBEmbedded; 21 | import com.github.wonwoo.dynamodb.autoconfigure.person.Person; 22 | import org.junit.Test; 23 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate; 24 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBMappingContext; 25 | import org.springframework.boot.autoconfigure.AutoConfigurations; 26 | import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; 27 | import org.springframework.boot.autoconfigure.domain.EntityScan; 28 | import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; 29 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 30 | import org.springframework.context.annotation.Bean; 31 | import org.springframework.context.annotation.Configuration; 32 | import org.springframework.test.util.ReflectionTestUtils; 33 | 34 | import java.util.Set; 35 | 36 | import static org.assertj.core.api.Assertions.assertThat; 37 | 38 | /** 39 | * @author wonwoo 40 | */ 41 | public class DynamoDataAutoConfigurationTests { 42 | 43 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() 44 | .withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, 45 | ValidationAutoConfiguration.class, DynamoAutoConfiguration.class, 46 | DynamoDataAutoConfiguration.class)); 47 | 48 | @Test 49 | @SuppressWarnings("unchecked") 50 | public void entitySetInitialEntity() throws Exception { 51 | contextRunner.withConfiguration(AutoConfigurations.of(EntityScanConfig.class)) 52 | .withPropertyValues("spring.data.dynamodb.access-key=test", "spring.data.dynamodb.secret-key=test") 53 | .run(context -> { 54 | DynamoDBMappingContext mappingContext = context 55 | .getBean(DynamoDBMappingContext.class); 56 | Set> initialEntitySet = (Set>) ReflectionTestUtils 57 | .getField(mappingContext, "initialEntitySet"); 58 | assertThat(initialEntitySet).containsOnly(Person.class); 59 | assertThat(context).hasSingleBean(CreateTable.class); 60 | assertThat(context).hasSingleBean(DynamoDBTemplate.class); 61 | assertThat(context).hasSingleBean(DynamoDbMapping.class); 62 | }); 63 | } 64 | 65 | @Test 66 | public void createTableAutoConfig() throws Exception { 67 | contextRunner.withConfiguration(AutoConfigurations.of(EntityScanConfig.class, AwsConfig.class)) 68 | .withPropertyValues("spring.data.dynamodb.access-key=test", "spring.data.dynamodb.secret-key=test", 69 | "spring.data.dynamodb.ddl.enabled=true") 70 | .run(context -> { 71 | assertThat(context).hasSingleBean(DynamoDbCreateTableBeanPostProcessor.class); 72 | }); 73 | } 74 | 75 | static class AwsConfig { 76 | @Bean 77 | public AmazonDynamoDB amazonDynamoDB() { 78 | return DynamoDBEmbedded.create().amazonDynamoDB(); 79 | } 80 | } 81 | 82 | @Configuration 83 | @EntityScan("com.github.wonwoo.dynamodb.autoconfigure.person") 84 | static class EntityScanConfig { 85 | 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoDbCreateTableTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import java.util.Collections; 20 | 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.mockito.Mock; 25 | import org.mockito.junit.MockitoJUnitRunner; 26 | 27 | import com.amazonaws.AmazonClientException; 28 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 29 | import com.amazonaws.services.dynamodbv2.model.*; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | import static org.mockito.ArgumentMatchers.any; 33 | import static org.mockito.BDDMockito.given; 34 | 35 | /** 36 | * @author wonwoo 37 | */ 38 | @RunWith(MockitoJUnitRunner.class) 39 | public class DynamoDbCreateTableTests { 40 | 41 | @Mock 42 | private AmazonDynamoDB amazonDynamoDB; 43 | 44 | private DynamoDbCreateTable dynamoDbCreateTable; 45 | 46 | @Before 47 | public void setup() { 48 | this.dynamoDbCreateTable = new DynamoDbCreateTable(this.amazonDynamoDB); 49 | } 50 | 51 | 52 | @Test 53 | public void isFoundTable() { 54 | ListTablesResult listTablesResult = new ListTablesResult(); 55 | listTablesResult.setTableNames(Collections.singleton("persons")); 56 | given(amazonDynamoDB.listTables()).willReturn(listTablesResult); 57 | assertThat(dynamoDbCreateTable.isTable("persons")).isTrue(); 58 | } 59 | 60 | @Test 61 | public void isNotFoundTable() { 62 | ListTablesResult listTablesResult = new ListTablesResult(); 63 | listTablesResult.setTableNames(Collections.singleton("persons")); 64 | given(amazonDynamoDB.listTables()).willReturn(listTablesResult); 65 | assertThat(dynamoDbCreateTable.isTable("foo")).isFalse(); 66 | } 67 | 68 | @Test 69 | public void createTable() { 70 | CreateTableResult createTableResult = new CreateTableResult(); 71 | TableDescription tableDescription = new TableDescription(); 72 | tableDescription.setTableStatus(TableStatus.CREATING); 73 | createTableResult.setTableDescription(tableDescription); 74 | given(amazonDynamoDB.createTable(any(CreateTableRequest.class))) 75 | .willReturn(createTableResult); 76 | CreateTableResult table = 77 | dynamoDbCreateTable.createTable("test", "id"); 78 | assertThat(table.getTableDescription().getTableStatus()).isEqualTo("CREATING"); 79 | 80 | 81 | } 82 | 83 | @Test 84 | public void waitTableExistsTrueTest() { 85 | given(this.amazonDynamoDB.describeTable(any(DescribeTableRequest.class))) 86 | .willAnswer(invocation -> describeTableResult(TableStatus.CREATING)) 87 | .willAnswer(invocation -> describeTableResult(TableStatus.CREATING)) 88 | .willReturn(describeTableResult(TableStatus.ACTIVE)); 89 | boolean exists = dynamoDbCreateTable.waitTableExists("test", 5, 30); 90 | assertThat(exists).isTrue(); 91 | } 92 | 93 | 94 | @Test 95 | public void waitTableResourceNotFoundExceptionTest() { 96 | given(this.amazonDynamoDB.describeTable(any(DescribeTableRequest.class))) 97 | .willThrow(new ResourceNotFoundException("table Not Found")) 98 | .willReturn(describeTableResult(TableStatus.ACTIVE)); 99 | boolean exists = dynamoDbCreateTable.waitTableExists("test", 5, 10); 100 | assertThat(exists).isTrue(); 101 | } 102 | 103 | 104 | @Test(expected = IllegalStateException.class) 105 | public void waitTableIllegalStateExceptionTest() { 106 | given(this.amazonDynamoDB.describeTable(any(DescribeTableRequest.class))) 107 | .willAnswer(invocation -> describeTableResult(TableStatus.CREATING)) 108 | .willThrow(new AmazonClientException("error")); 109 | dynamoDbCreateTable.waitTableExists("test", 5, 10); 110 | } 111 | 112 | @Test 113 | public void waitTableExistsFalseTest() { 114 | given(this.amazonDynamoDB.describeTable(any(DescribeTableRequest.class))) 115 | .willAnswer(invocation -> describeTableResult(TableStatus.CREATING)) 116 | .willAnswer(invocation -> describeTableResult(TableStatus.CREATING)) 117 | .willAnswer(invocation -> describeTableResult(TableStatus.CREATING)) 118 | .willReturn(describeTableResult(TableStatus.ACTIVE)); 119 | boolean exists = dynamoDbCreateTable.waitTableExists("test", 5, 10); 120 | assertThat(exists).isFalse(); 121 | } 122 | 123 | private DescribeTableResult describeTableResult(TableStatus tableStatus) { 124 | DescribeTableResult describeTableResult = new DescribeTableResult(); 125 | TableDescription tableDescription = new TableDescription(); 126 | tableDescription.setTableStatus(tableStatus); 127 | describeTableResult.setTable(tableDescription); 128 | return describeTableResult; 129 | } 130 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoPropertiesTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.amazonaws.regions.Regions; 20 | import org.junit.Test; 21 | 22 | import java.util.HashSet; 23 | import java.util.Set; 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | 27 | /** 28 | * @author wonwoo 29 | */ 30 | public class DynamoPropertiesTests { 31 | 32 | @Test 33 | public void defaultProperties() { 34 | DynamoProperties properties = new DynamoProperties(); 35 | properties.setAccessKey("foo"); 36 | properties.setSecretKey("bar"); 37 | assertThat(properties.getAccessKey()).isEqualTo("foo"); 38 | assertThat(properties.getSecretKey()).isEqualTo("bar"); 39 | assertThat(properties.getRegions()).isEqualTo(Regions.AP_NORTHEAST_2); 40 | assertThat(properties.getWriteCapacityUnits()).isEqualTo(10L); 41 | assertThat(properties.getReadCapacityUnits()).isEqualTo(10L); 42 | } 43 | 44 | @Test 45 | public void configProperties() { 46 | DynamoProperties properties = new DynamoProperties(); 47 | properties.setAccessKey("foo"); 48 | properties.setSecretKey("bar"); 49 | properties.setRegions(Regions.AP_NORTHEAST_1); 50 | properties.setReadCapacityUnits(200L); 51 | properties.setWriteCapacityUnits(500L); 52 | assertThat(properties.getAccessKey()).isEqualTo("foo"); 53 | assertThat(properties.getSecretKey()).isEqualTo("bar"); 54 | assertThat(properties.getRegions()).isEqualTo(Regions.AP_NORTHEAST_1); 55 | assertThat(properties.getReadCapacityUnits()).isEqualTo(200L); 56 | assertThat(properties.getWriteCapacityUnits()).isEqualTo(500L); 57 | } 58 | 59 | @Test 60 | public void hashTest() { 61 | Set properties = new HashSet<>(); 62 | DynamoProperties properties1 = new DynamoProperties(); 63 | properties1.setAccessKey("foo"); 64 | properties1.setSecretKey("bar"); 65 | properties.add(properties1); 66 | DynamoProperties properties2 = new DynamoProperties(); 67 | properties2.setAccessKey("foo"); 68 | properties2.setSecretKey("bar"); 69 | assertThat(properties.iterator().next()).isEqualTo(properties2); 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/DynamoRepositoriesAutoConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.github.wonwoo.dynamodb.TestAutoConfigurationPackage; 20 | import com.github.wonwoo.dynamodb.autoconfigure.person.Person; 21 | import com.github.wonwoo.dynamodb.autoconfigure.person.PersonRepository; 22 | import com.github.wonwoo.dynamodb.empty.EmptyDataPackage; 23 | import org.junit.Test; 24 | import org.springframework.boot.autoconfigure.AutoConfigurations; 25 | import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; 26 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 27 | import org.springframework.context.annotation.Configuration; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | /** 32 | * @author wonwoo 33 | */ 34 | public class DynamoRepositoriesAutoConfigurationTests { 35 | 36 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() 37 | .withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, 38 | DynamoAutoConfiguration.class, DynamoDataAutoConfiguration.class, 39 | DynamoRepositoriesAutoConfiguration.class)); 40 | 41 | 42 | @Test 43 | public void defaultRepository() throws Exception { 44 | 45 | contextRunner.withUserConfiguration(DefaultConfiguration.class) 46 | .withPropertyValues("spring.data.dynamodb.access-key=test", "spring.data.dynamodb.secret-key=test") 47 | .run(context -> assertThat(context).hasSingleBean(PersonRepository.class)); 48 | } 49 | 50 | @Test 51 | public void disabledRepositories() { 52 | contextRunner.withUserConfiguration(DefaultConfiguration.class) 53 | .withPropertyValues("spring.data.dynamodb.access-key=test", "spring.data.dynamodb.secret-key=test", 54 | "spring.data.dynamodb.repositories.enabled=none") 55 | .run(context -> assertThat(context).doesNotHaveBean(PersonRepository.class)); 56 | } 57 | 58 | @Test 59 | public void noRepositoryAvailable() throws Exception { 60 | contextRunner.withUserConfiguration(NoRepositoryConfiguration.class) 61 | .withPropertyValues("spring.data.dynamodb.access-key=test", "spring.data.dynamodb.secret-key=test") 62 | .run(context -> assertThat(context).doesNotHaveBean(PersonRepository.class)); 63 | } 64 | 65 | @Configuration 66 | @TestAutoConfigurationPackage(Person.class) 67 | static class DefaultConfiguration { 68 | 69 | } 70 | 71 | @Configuration 72 | @TestAutoConfigurationPackage(Person.class) 73 | static class DynamoNotAvailableConfiguration { 74 | 75 | } 76 | 77 | 78 | @Configuration 79 | @TestAutoConfigurationPackage(EmptyDataPackage.class) 80 | static class NoRepositoryConfiguration { 81 | 82 | } 83 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/EmbeddedDynamoAutoConfigurationTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure; 18 | 19 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 20 | import org.junit.Test; 21 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate; 22 | import org.springframework.boot.autoconfigure.AutoConfigurations; 23 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | 27 | /** 28 | * @author wonwoo 29 | */ 30 | public class EmbeddedDynamoAutoConfigurationTests { 31 | 32 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() 33 | .withConfiguration(AutoConfigurations.of(EmbeddedDynamoAutoConfiguration.class)); 34 | 35 | @Test 36 | public void dynamoLocalDbAutoConfig() { 37 | 38 | contextRunner.withUserConfiguration(DynamoDataAutoConfiguration.class) 39 | .run(context -> { 40 | assertThat(context).hasSingleBean(AmazonDynamoDB.class); 41 | assertThat(context).hasSingleBean(DynamoDBTemplate.class); 42 | }); 43 | } 44 | 45 | @Test 46 | public void dynamoLocalDbNotFoundDataAutoConfig() { 47 | contextRunner 48 | .run(context -> { 49 | assertThat(context).hasSingleBean(AmazonDynamoDB.class); 50 | assertThat(context).doesNotHaveBean(DynamoDBTemplate.class); 51 | }); 52 | } 53 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/person/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure.person; 18 | 19 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey; 20 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 21 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 22 | 23 | /** 24 | * @author wonwoo 25 | */ 26 | @DynamoDBTable(tableName = "persons") 27 | public class Person { 28 | 29 | @DynamoDBHashKey 30 | @DynamoDBAutoGeneratedKey 31 | private String id; 32 | private String firstName; 33 | private String lastName; 34 | 35 | 36 | public String getId() { 37 | return id; 38 | } 39 | 40 | public void setId(String id) { 41 | this.id = id; 42 | } 43 | 44 | public String getFirstName() { 45 | return firstName; 46 | } 47 | 48 | public void setFirstName(String firstName) { 49 | this.firstName = firstName; 50 | } 51 | 52 | public String getLastName() { 53 | return lastName; 54 | } 55 | 56 | public void setLastName(String lastName) { 57 | this.lastName = lastName; 58 | } 59 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/autoconfigure/person/PersonRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.autoconfigure.person; 18 | 19 | import org.springframework.data.repository.CrudRepository; 20 | 21 | /** 22 | * @author wonwoo 23 | */ 24 | public interface PersonRepository extends CrudRepository { 25 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/empty/EmptyDataPackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.empty; 18 | 19 | /** 20 | * @author wonwoo 21 | */ 22 | public class EmptyDataPackage { 23 | } 24 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dynamodb-spring-boot 7 | com.github.wonwoo 8 | 1.0.2-SNAPSHOT 9 | 10 | jar 11 | 4.0.0 12 | 13 | dynamodb-spring-boot-core 14 | 15 | 16 | 17 | The Apache Software License, Version 2.0 18 | https://opensource.org/licenses/Apache-2.0 19 | repo 20 | 21 | 22 | 23 | 24 | https://github.com/wonwoo/dynamodb-spring-boot 25 | 26 | 27 | 28 | UTF-8 29 | UTF-8 30 | 1.8 31 | 1.8 32 | 1.8 33 | 1.8 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-autoconfigure 40 | 41 | 42 | 43 | com.github.derjust 44 | spring-data-dynamodb 45 | true 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-test 51 | test 52 | 53 | 54 | 55 | 56 | 57 | 58 | org.apache.maven.plugins 59 | maven-surefire-plugin 60 | ${maven-surefire-plugin.version} 61 | 62 | ${surefireArgLine} 63 | 64 | **/*Tests.java 65 | **/*Test.java 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/main/java/com/github/wonwoo/dynamodb/repository/DynamoDBRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | import java.io.Serializable; 20 | import java.util.List; 21 | 22 | import org.socialsignin.spring.data.dynamodb.repository.DynamoDBCrudRepository; 23 | import org.socialsignin.spring.data.dynamodb.repository.DynamoDBPagingAndSortingRepository; 24 | import org.springframework.data.repository.NoRepositoryBean; 25 | 26 | /** 27 | * @author wonwoo 28 | */ 29 | @NoRepositoryBean 30 | public interface DynamoDBRepository 31 | extends DynamoDBPagingAndSortingRepository, DynamoDBCrudRepository { 32 | 33 | @Override 34 | List findAll(); 35 | 36 | @Override 37 | List findAllById(Iterable ids); 38 | 39 | @Override 40 | List saveAll(Iterable entities); 41 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/main/java/com/github/wonwoo/dynamodb/repository/DynamoDBRepositoryFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations; 20 | import org.springframework.data.repository.core.RepositoryMetadata; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * @author wonwoo 26 | */ 27 | public class DynamoDBRepositoryFactory extends org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBRepositoryFactory { 28 | 29 | private final DynamoDBOperations dynamoDBOperations; 30 | 31 | public DynamoDBRepositoryFactory(DynamoDBOperations dynamoDBOperations) { 32 | super(dynamoDBOperations); 33 | this.dynamoDBOperations = dynamoDBOperations; 34 | } 35 | 36 | @Override 37 | @SuppressWarnings({"unchecked", "rawtypes"}) 38 | protected DynamoDBRepository getDynamoDBRepository( 39 | RepositoryMetadata metadata) { 40 | return new SimpleDynamoDBRepository(getEntityInformation(metadata.getDomainType()), 41 | dynamoDBOperations, getEnableScanPermissions(metadata)); 42 | } 43 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/main/java/com/github/wonwoo/dynamodb/repository/DynamoDBRepositoryFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; 20 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig; 21 | import java.io.Serializable; 22 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations; 23 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate; 24 | import org.socialsignin.spring.data.dynamodb.mapping.DynamoDBMappingContext; 25 | import org.springframework.beans.BeansException; 26 | import org.springframework.context.ApplicationContext; 27 | import org.springframework.context.ApplicationContextAware; 28 | import org.springframework.data.repository.Repository; 29 | import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; 30 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 31 | 32 | /** 33 | * @author wonwoo 34 | */ 35 | public class DynamoDBRepositoryFactoryBean, S, ID extends Serializable> 36 | extends RepositoryFactoryBeanSupport implements ApplicationContextAware { 37 | 38 | private DynamoDBMapperConfig dynamoDBMapperConfig; 39 | 40 | private AmazonDynamoDB amazonDynamoDB; 41 | 42 | private DynamoDBOperations dynamoDBOperations; 43 | 44 | private ApplicationContext applicationContext; 45 | 46 | public DynamoDBRepositoryFactoryBean(Class repositoryInterface) { 47 | super(repositoryInterface); 48 | } 49 | 50 | public void setAmazonDynamoDB(AmazonDynamoDB amazonDynamoDB) { 51 | this.amazonDynamoDB = amazonDynamoDB; 52 | } 53 | 54 | @Override 55 | protected RepositoryFactorySupport createRepositoryFactory() { 56 | if (dynamoDBOperations == null) { 57 | DynamoDBTemplate dynamoDBTemplate = new DynamoDBTemplate(amazonDynamoDB, dynamoDBMapperConfig); 58 | dynamoDBTemplate.setApplicationContext(applicationContext); 59 | dynamoDBOperations = dynamoDBTemplate; 60 | } 61 | return new DynamoDBRepositoryFactory(dynamoDBOperations); 62 | } 63 | 64 | public void setDynamoDBMapperConfig(DynamoDBMapperConfig dynamoDBMapperConfig) { 65 | this.dynamoDBMapperConfig = dynamoDBMapperConfig; 66 | } 67 | 68 | public void setDynamoDBOperations(DynamoDBOperations dynamoDBOperations) { 69 | this.dynamoDBOperations = dynamoDBOperations; 70 | } 71 | 72 | public void setDynamoDBMappingContext(DynamoDBMappingContext dynamoDBMappingContext) { 73 | setMappingContext(dynamoDBMappingContext); 74 | } 75 | 76 | @Override 77 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 78 | this.applicationContext = applicationContext; 79 | } 80 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/main/java/com/github/wonwoo/dynamodb/repository/SimpleDynamoDBRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | import java.io.Serializable; 20 | import java.util.List; 21 | import java.util.stream.Collectors; 22 | import java.util.stream.StreamSupport; 23 | 24 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; 25 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations; 26 | import org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBEntityInformation; 27 | import org.socialsignin.spring.data.dynamodb.repository.support.EnableScanPermissions; 28 | import org.socialsignin.spring.data.dynamodb.repository.support.SimpleDynamoDBPagingAndSortingRepository; 29 | import org.springframework.util.Assert; 30 | 31 | import static com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.*; 32 | import static java.util.stream.Collectors.*; 33 | 34 | /** 35 | * @author wonwoo 36 | */ 37 | public class SimpleDynamoDBRepository 38 | extends SimpleDynamoDBPagingAndSortingRepository 39 | implements DynamoDBRepository { 40 | 41 | public SimpleDynamoDBRepository( 42 | DynamoDBEntityInformation entityInformation, 43 | DynamoDBOperations dynamoDBOperations, 44 | EnableScanPermissions enableScanPermissions) { 45 | super(entityInformation, dynamoDBOperations, enableScanPermissions); 46 | } 47 | 48 | @Override 49 | public List saveAll(Iterable entities) { 50 | Assert.notNull(entities, "entities not be null!"); 51 | return StreamSupport 52 | .stream(super.saveAll(entities).spliterator(), false) 53 | .collect(toList()); 54 | } 55 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/test/java/com/github/wonwoo/dynamodb/repository/DynamoDBRepositoryFactoryTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | import org.junit.Test; 20 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations; 21 | import org.springframework.data.repository.core.RepositoryMetadata; 22 | import org.springframework.data.repository.core.support.DefaultRepositoryMetadata; 23 | 24 | import static org.assertj.core.api.Assertions.assertThat; 25 | import static org.mockito.Mockito.mock; 26 | 27 | /** 28 | * @author wonwoo 29 | */ 30 | public class DynamoDBRepositoryFactoryTests { 31 | 32 | @Test 33 | public void getDynamoDBRepository() { 34 | DynamoDBOperations openOperations = mock(DynamoDBOperations.class); 35 | DynamoDBRepositoryFactory factory = new DynamoDBRepositoryFactory(openOperations); 36 | RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(PersonRepository.class); 37 | DynamoDBRepository dynamoDBRepository = factory.getDynamoDBRepository(repositoryMetadata); 38 | assertThat(dynamoDBRepository).isNotNull(); 39 | } 40 | 41 | @Test(expected = IllegalArgumentException.class) 42 | public void getNotFoundDynamoDBRepository() { 43 | new DefaultRepositoryMetadata(EmptyRepository.class); 44 | } 45 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/test/java/com/github/wonwoo/dynamodb/repository/EmptyRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | /** 20 | * @author wonwoo 21 | */ 22 | public interface EmptyRepository { 23 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/test/java/com/github/wonwoo/dynamodb/repository/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 20 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 21 | 22 | /** 23 | * @author wonwoo 24 | */ 25 | @DynamoDBTable(tableName = "person") 26 | public class Person { 27 | 28 | @DynamoDBHashKey 29 | private String id; 30 | 31 | Person() { 32 | 33 | } 34 | 35 | public Person(String id) { 36 | this.id = id; 37 | } 38 | 39 | public String getId() { 40 | return id; 41 | } 42 | 43 | public void setId(String id) { 44 | this.id = id; 45 | } 46 | 47 | @Override 48 | public boolean equals(Object o) { 49 | if (this == o) 50 | return true; 51 | if (o == null || getClass() != o.getClass()) 52 | return false; 53 | 54 | Person person = (Person) o; 55 | 56 | return id != null ? id.equals(person.id) : person.id == null; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return id != null ? id.hashCode() : 0; 62 | } 63 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/test/java/com/github/wonwoo/dynamodb/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.repository; 18 | 19 | import org.springframework.data.repository.Repository; 20 | 21 | /** 22 | * @author wonwoo 23 | */ 24 | public interface PersonRepository extends Repository { 25 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-core/src/test/java/com/github/wonwoo/dynamodb/repository/SimpleDynamoDBRepositoryTests.java: -------------------------------------------------------------------------------- 1 | package com.github.wonwoo.dynamodb.repository; 2 | 3 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; 4 | import org.junit.Rule; 5 | import org.junit.Test; 6 | import org.junit.rules.ExpectedException; 7 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations; 8 | import org.socialsignin.spring.data.dynamodb.exception.BatchWriteException; 9 | import org.springframework.data.repository.core.RepositoryMetadata; 10 | import org.springframework.data.repository.core.support.DefaultRepositoryMetadata; 11 | 12 | import java.util.Arrays; 13 | import java.util.Collections; 14 | import java.util.Iterator; 15 | import java.util.List; 16 | 17 | import static org.assertj.core.api.Assertions.assertThat; 18 | import static org.mockito.ArgumentMatchers.anyList; 19 | import static org.mockito.BDDMockito.given; 20 | import static org.mockito.Mockito.mock; 21 | 22 | public class SimpleDynamoDBRepositoryTests { 23 | 24 | @Rule 25 | public final ExpectedException exception = ExpectedException.none(); 26 | 27 | @Test 28 | @SuppressWarnings("unchecked") 29 | public void saveAllTest() { 30 | DynamoDBOperations openOperations = mock(DynamoDBOperations.class); 31 | given(openOperations.batchSave(anyList())).willReturn(Collections.emptyList()); 32 | DynamoDBRepositoryFactory factory = new DynamoDBRepositoryFactory(openOperations); 33 | RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(PersonRepository.class); 34 | DynamoDBRepository dynamoDBRepository = 35 | (DynamoDBRepository) factory.getDynamoDBRepository(repositoryMetadata); 36 | List person = dynamoDBRepository.saveAll(Arrays.asList(new Person("id1"), new Person("id2"))); 37 | Iterator iterator = person.iterator(); 38 | assertThat(iterator.next()).isEqualTo(new Person("id1")); 39 | assertThat(iterator.next()).isEqualTo(new Person("id2")); 40 | } 41 | 42 | @Test 43 | @SuppressWarnings("unchecked") 44 | public void saveAllFailedTest() { 45 | exception.expect(BatchWriteException.class); 46 | DynamoDBOperations openOperations = mock(DynamoDBOperations.class); 47 | DynamoDBMapper.FailedBatch failedBatch = new DynamoDBMapper.FailedBatch(); 48 | failedBatch.setException(new NullPointerException()); 49 | given(openOperations.batchSave(anyList())).willReturn(Collections.singletonList(failedBatch)); 50 | DynamoDBRepositoryFactory factory = new DynamoDBRepositoryFactory(openOperations); 51 | RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(PersonRepository.class); 52 | DynamoDBRepository dynamoDBRepository = 53 | (DynamoDBRepository) factory.getDynamoDBRepository(repositoryMetadata); 54 | dynamoDBRepository.saveAll(Arrays.asList(new Person("id1"), new Person("id2"))); 55 | } 56 | 57 | @Test 58 | @SuppressWarnings("unchecked") 59 | public void saveAllIllegalArgumentExceptionTest() { 60 | exception.expect(IllegalArgumentException.class); 61 | DynamoDBOperations openOperations = mock(DynamoDBOperations.class); 62 | DynamoDBRepositoryFactory factory = new DynamoDBRepositoryFactory(openOperations); 63 | RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(PersonRepository.class); 64 | DynamoDBRepository dynamoDBRepository = 65 | (DynamoDBRepository) factory.getDynamoDBRepository(repositoryMetadata); 66 | dynamoDBRepository.saveAll(null); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dynamodb-spring-boot 7 | com.github.wonwoo 8 | 1.0.2-SNAPSHOT 9 | 10 | jar 11 | 4.0.0 12 | 13 | dynamodb-spring-boot-sample 14 | 15 | 16 | 17 | The Apache Software License, Version 2.0 18 | https://opensource.org/licenses/Apache-2.0 19 | repo 20 | 21 | 22 | 23 | 24 | https://github.com/wonwoo/dynamodb-spring-boot 25 | 26 | 27 | 28 | UTF-8 29 | UTF-8 30 | 1.8 31 | 1.8 32 | 1.8 33 | 1.8 34 | 35 | 36 | 37 | 38 | com.github.wonwoo 39 | dynamodb-spring-boot-starter 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-web 45 | 46 | 47 | 48 | com.amazonaws 49 | DynamoDBLocal 50 | test 51 | 52 | 53 | 54 | com.almworks.sqlite4java 55 | sqlite4java 56 | test 57 | 58 | 59 | 60 | com.github.wonwoo 61 | dynamodb-spring-boot-starter-test 62 | test 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-test 68 | test 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.apache.maven.plugins 76 | maven-dependency-plugin 77 | 78 | 79 | copy-dependencies 80 | process-test-resources 81 | 82 | copy-dependencies 83 | 84 | 85 | ${project.build.directory}/dependencies 86 | false 87 | false 88 | true 89 | 90 | 91 | 92 | 93 | 94 | maven-surefire-plugin 95 | ${maven-surefire-plugin.version} 96 | 97 | -Dsqlite4java.library.path=${basedir}/target/dependencies 98 | 99 | **/*Tests.java 100 | **/*Test.java 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-sample/src/main/java/com/github/wonwoo/dynamodb/SampleApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb; 18 | 19 | import java.util.Arrays; 20 | 21 | import org.springframework.boot.CommandLineRunner; 22 | import org.springframework.boot.SpringApplication; 23 | import org.springframework.boot.autoconfigure.SpringBootApplication; 24 | import org.springframework.context.annotation.Bean; 25 | import org.springframework.data.domain.PageRequest; 26 | 27 | import com.github.wonwoo.dynamodb.domain.Person; 28 | import com.github.wonwoo.dynamodb.domain.PersonRepository; 29 | 30 | /** 31 | * @author wonwoo 32 | */ 33 | @SpringBootApplication 34 | public class SampleApplication { 35 | 36 | public static void main(String[] args) { 37 | SpringApplication.run(SampleApplication.class, args); 38 | } 39 | 40 | @Bean 41 | CommandLineRunner commandLineRunner(PersonRepository personRepository) { 42 | return args -> { 43 | personRepository.saveAll(Arrays.asList( 44 | new Person("kevin"), 45 | new Person("josh long")) 46 | ); 47 | 48 | personRepository.findAll(PageRequest.of(0, 3)) 49 | .forEach(System.out::println); 50 | 51 | System.out.println("find by Name"); 52 | personRepository.findByName("kevin") 53 | .forEach(System.out::println); 54 | }; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-sample/src/main/java/com/github/wonwoo/dynamodb/domain/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.domain; 18 | 19 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey; 20 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 21 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 22 | 23 | /** 24 | * @author wonwoo 25 | */ 26 | @DynamoDBTable(tableName = "persons") 27 | public class Person { 28 | 29 | @DynamoDBHashKey 30 | @DynamoDBAutoGeneratedKey 31 | private String id; 32 | private String name; 33 | 34 | public Person() { 35 | 36 | } 37 | 38 | public Person(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String getId() { 43 | return id; 44 | } 45 | 46 | public void setId(String id) { 47 | this.id = id; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "Person{" + 61 | "id='" + id + '\'' + 62 | ", name='" + name + '\'' + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-sample/src/main/java/com/github/wonwoo/dynamodb/domain/PersonRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.domain; 18 | 19 | import java.util.List; 20 | 21 | import org.socialsignin.spring.data.dynamodb.repository.EnableScan; 22 | import org.socialsignin.spring.data.dynamodb.repository.EnableScanCount; 23 | 24 | import com.github.wonwoo.dynamodb.repository.DynamoDBRepository; 25 | 26 | /** 27 | * @author wonwoo 28 | */ 29 | @EnableScan 30 | @EnableScanCount 31 | public interface PersonRepository extends DynamoDBRepository { 32 | 33 | List findByName(String name); 34 | } 35 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-sample/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.data.dynamodb.access-key= 2 | spring.data.dynamodb.secret-key= -------------------------------------------------------------------------------- /dynamodb-spring-boot-sample/src/test/java/com/github/wonwoo/dynamodb/PersonRepositoryTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 com.github.wonwoo.dynamodb; 17 | 18 | import com.github.wonwoo.dynamodb.domain.Person; 19 | import com.github.wonwoo.dynamodb.domain.PersonRepository; 20 | import com.github.wonwoo.dynamodb.test.autoconfigure.DynamoTest; 21 | import org.junit.Test; 22 | import org.junit.runner.RunWith; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | import org.springframework.test.context.junit4.SpringRunner; 25 | 26 | import java.util.List; 27 | 28 | import static org.assertj.core.api.Assertions.assertThat; 29 | 30 | /** 31 | * @author wonwoo 32 | */ 33 | @DynamoTest 34 | @RunWith(SpringRunner.class) 35 | public class PersonRepositoryTests { 36 | 37 | @Autowired 38 | private PersonRepository personRepository; 39 | 40 | @Test 41 | public void save() { 42 | List persons = personRepository.findAll(); 43 | assertThat(persons).hasSize(2); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-sample/src/test/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wonwoo/dynamodb-spring-boot/1eb036c59ac318e09ab09e67ebe6a3141a592561/dynamodb-spring-boot-sample/src/test/resources/application.properties -------------------------------------------------------------------------------- /dynamodb-spring-boot-starter-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dynamodb-spring-boot 7 | com.github.wonwoo 8 | 1.0.2-SNAPSHOT 9 | 10 | jar 11 | 4.0.0 12 | 13 | dynamodb-spring-boot-starter-test 14 | 15 | 16 | 17 | The Apache Software License, Version 2.0 18 | https://opensource.org/licenses/Apache-2.0 19 | repo 20 | 21 | 22 | 23 | 24 | https://github.com/wonwoo/dynamodb-spring-boot 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-test 31 | 32 | 33 | 34 | com.github.wonwoo 35 | dynamodb-spring-boot-test-autoconfigure 36 | 37 | 38 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dynamodb-spring-boot 7 | com.github.wonwoo 8 | 1.0.2-SNAPSHOT 9 | 10 | jar 11 | 4.0.0 12 | 13 | 14 | 15 | The Apache Software License, Version 2.0 16 | https://opensource.org/licenses/Apache-2.0 17 | repo 18 | 19 | 20 | 21 | 22 | https://github.com/wonwoo/dynamodb-spring-boot 23 | 24 | 25 | dynamodb-spring-boot-starter 26 | 27 | 28 | 29 | com.github.wonwoo 30 | dynamodb-spring-boot-autoconfigure 31 | 32 | 33 | 34 | com.github.derjust 35 | spring-data-dynamodb 36 | 37 | 38 | 39 | com.amazonaws 40 | aws-java-sdk-dynamodb 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | dynamodb-spring-boot 7 | com.github.wonwoo 8 | 1.0.2-SNAPSHOT 9 | 10 | jar 11 | 4.0.0 12 | 13 | dynamodb-spring-boot-test-autoconfigure 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-test-autoconfigure 19 | 20 | 21 | org.springframework 22 | spring-test 23 | 24 | 25 | commons-logging 26 | commons-logging 27 | 28 | 29 | 30 | 31 | com.github.wonwoo 32 | dynamodb-spring-boot-starter 33 | true 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-test 39 | test 40 | 41 | 42 | 43 | com.amazonaws 44 | DynamoDBLocal 45 | test 46 | 47 | 48 | 49 | com.almworks.sqlite4java 50 | sqlite4java 51 | test 52 | 53 | 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-dependency-plugin 59 | 60 | 61 | copy-dependencies 62 | process-test-resources 63 | 64 | copy-dependencies 65 | 66 | 67 | ${project.build.directory}/dependencies 68 | false 69 | false 70 | true 71 | 72 | 73 | 74 | 75 | 76 | org.apache.maven.plugins 77 | maven-surefire-plugin 78 | ${maven-surefire-plugin.version} 79 | 80 | ${surefireArgLine} -Dsqlite4java.library.path=${basedir}/target/dependencies 81 | 82 | **/*Tests.java 83 | **/*Test.java 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/test/autoconfigure/AutoConfigureDynamo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 20 | 21 | import java.lang.annotation.*; 22 | 23 | /** 24 | * @author wonwoo 25 | */ 26 | @Target(ElementType.TYPE) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | @Inherited 30 | @ImportAutoConfiguration 31 | public @interface AutoConfigureDynamo { 32 | } 33 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/test/autoconfigure/DynamoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 20 | import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; 21 | import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache; 22 | import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters; 23 | import org.springframework.boot.test.autoconfigure.properties.PropertyMapping; 24 | import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; 25 | import org.springframework.context.annotation.ComponentScan; 26 | import org.springframework.core.annotation.AliasFor; 27 | import org.springframework.test.context.BootstrapWith; 28 | 29 | import java.lang.annotation.*; 30 | 31 | /** 32 | * @author wonwoo 33 | */ 34 | @Target(ElementType.TYPE) 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Documented 37 | @Inherited 38 | @BootstrapWith(SpringBootTestContextBootstrapper.class) 39 | @OverrideAutoConfiguration(enabled = false) 40 | @TypeExcludeFilters(DynamoTypeExcludeFilter.class) 41 | @AutoConfigureCache 42 | @AutoConfigureDynamo 43 | @ImportAutoConfiguration 44 | public @interface DynamoTest { 45 | 46 | @PropertyMapping("spring.data.dynamodb.ddl.enabled") 47 | boolean createDdl() default true; 48 | 49 | boolean useDefaultFilters() default true; 50 | 51 | ComponentScan.Filter[] includeFilters() default {}; 52 | 53 | ComponentScan.Filter[] excludeFilters() default {}; 54 | 55 | @AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude") 56 | Class[] excludeAutoConfiguration() default {}; 57 | } 58 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/main/java/com/github/wonwoo/dynamodb/test/autoconfigure/DynamoTypeExcludeFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizableTypeExcludeFilter; 20 | import org.springframework.context.annotation.ComponentScan; 21 | import org.springframework.core.annotation.AnnotatedElementUtils; 22 | 23 | import java.util.Collections; 24 | import java.util.Set; 25 | 26 | /** 27 | * @author wonwoo 28 | */ 29 | class DynamoTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter { 30 | 31 | private final DynamoTest annotation; 32 | 33 | DynamoTypeExcludeFilter(Class testClass) { 34 | this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, 35 | DynamoTest.class); 36 | } 37 | 38 | @Override 39 | protected boolean hasAnnotation() { 40 | return this.annotation != null; 41 | } 42 | 43 | @Override 44 | protected ComponentScan.Filter[] getFilters(FilterType type) { 45 | switch (type) { 46 | case INCLUDE: 47 | return this.annotation.includeFilters(); 48 | case EXCLUDE: 49 | return this.annotation.excludeFilters(); 50 | } 51 | throw new IllegalStateException("Unsupported type " + type); 52 | } 53 | 54 | @Override 55 | protected boolean isUseDefaultFilters() { 56 | return this.annotation.useDefaultFilters(); 57 | } 58 | 59 | @Override 60 | protected Set> getDefaultIncludes() { 61 | return Collections.emptySet(); 62 | } 63 | 64 | @Override 65 | protected Set> getComponentIncludes() { 66 | return Collections.emptySet(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | com.github.wonwoo.dynamodb.test.autoconfigure.AutoConfigureDynamo=\ 2 | com.github.wonwoo.dynamodb.autoconfigure.DynamoDataAutoConfiguration,\ 3 | com.github.wonwoo.dynamodb.autoconfigure.DynamoRepositoriesAutoConfiguration,\ 4 | com.github.wonwoo.dynamodb.autoconfigure.DynamoAutoConfiguration,\ 5 | com.github.wonwoo.dynamodb.autoconfigure.EmbeddedDynamoAutoConfiguration -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/test/autoconfigure/DynamoTestIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.socialsignin.spring.data.dynamodb.core.DynamoDBTemplate; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.test.context.junit4.SpringRunner; 27 | 28 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression; 29 | import com.amazonaws.services.dynamodbv2.datamodeling.PaginatedScanList; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | /** 34 | * @author wonwoo 35 | */ 36 | @DynamoTest 37 | @RunWith(SpringRunner.class) 38 | public class DynamoTestIntegrationTest { 39 | 40 | @Autowired 41 | private PersonRepository personRepository; 42 | 43 | @Autowired 44 | private DynamoDBTemplate dynamoDBTemplate; 45 | 46 | @Test 47 | public void saveTest() { 48 | personRepository.saveAll(Collections.singletonList(new Person("wonwoo"))); 49 | List person = personRepository.findAll(); 50 | assertThat(person.iterator().next().getName()).isEqualTo("wonwoo"); 51 | } 52 | 53 | @Test 54 | public void dynamoTemplateTest() { 55 | dynamoDBTemplate.save(new Person("wonwoo")); 56 | DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); 57 | PaginatedScanList persons = dynamoDBTemplate.scan(Person.class, scanExpression); 58 | assertThat(persons.iterator().next().getName()).isEqualTo("wonwoo"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/test/autoconfigure/DynamoTypeExcludeFilterTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import org.junit.Test; 20 | import org.junit.runner.RunWith; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.context.annotation.ComponentScan; 23 | import org.springframework.stereotype.Component; 24 | import org.springframework.stereotype.Service; 25 | import org.springframework.test.context.junit4.SpringRunner; 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; 28 | 29 | /** 30 | * @author wonwoo 31 | */ 32 | @RunWith(SpringRunner.class) 33 | @DynamoTest(includeFilters = @ComponentScan.Filter(Component.class), 34 | excludeFilters = @ComponentScan.Filter(Service.class)) 35 | public class DynamoTypeExcludeFilterTests { 36 | 37 | @Autowired 38 | private ExampleComponent component; 39 | 40 | @Autowired(required = false) 41 | private ExampleService service; 42 | 43 | @Test 44 | public void testIncludeFilter() { 45 | assertThat(component.getMessage()).isEqualTo("Hello!"); 46 | } 47 | 48 | @Test 49 | public void testExcludeFilter() { 50 | assertThat(service).isNull(); 51 | } 52 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/test/autoconfigure/EmptyApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import org.springframework.boot.autoconfigure.SpringBootApplication; 20 | 21 | /** 22 | * @author wonwoo 23 | */ 24 | @SpringBootApplication 25 | class EmptyApplication { 26 | } 27 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/test/autoconfigure/ExampleComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 com.github.wonwoo.dynamodb.test.autoconfigure; 17 | 18 | import org.springframework.stereotype.Component; 19 | 20 | /** 21 | * @author wonwoo 22 | */ 23 | @Component 24 | public class ExampleComponent { 25 | 26 | public String getMessage() { 27 | return "Hello!"; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/test/autoconfigure/ExampleService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import org.springframework.stereotype.Service; 20 | 21 | /** 22 | * @author wonwoo 23 | */ 24 | @Service 25 | public class ExampleService { 26 | 27 | public String getMessage() { 28 | return "Hello World"; 29 | } 30 | } -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/test/autoconfigure/Person.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey; 20 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; 21 | import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; 22 | 23 | /** 24 | * @author wonwoo 25 | */ 26 | @DynamoDBTable(tableName = "persons") 27 | public class Person { 28 | 29 | @DynamoDBHashKey 30 | @DynamoDBAutoGeneratedKey 31 | private String id; 32 | private String name; 33 | 34 | public Person() { 35 | 36 | } 37 | 38 | public Person(String name) { 39 | this.name = name; 40 | } 41 | 42 | public String getId() { 43 | return id; 44 | } 45 | 46 | public void setId(String id) { 47 | this.id = id; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "Person{" + 61 | "id='" + id + '\'' + 62 | ", name='" + name + '\'' + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /dynamodb-spring-boot-test-autoconfigure/src/test/java/com/github/wonwoo/dynamodb/test/autoconfigure/PersonRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 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 | 17 | package com.github.wonwoo.dynamodb.test.autoconfigure; 18 | 19 | import org.socialsignin.spring.data.dynamodb.repository.EnableScan; 20 | 21 | import com.github.wonwoo.dynamodb.repository.DynamoDBRepository; 22 | 23 | /** 24 | * @author wonwoo 25 | */ 26 | @EnableScan 27 | public interface PersonRepository extends DynamoDBRepository { 28 | } 29 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.github.wonwoo 7 | dynamodb-spring-boot 8 | 1.0.2-SNAPSHOT 9 | 10 | 11 | 12 | wonwoo 13 | aoruqjfu@gmail.com 14 | 15 | 16 | 17 | 18 | 19 | The Apache Software License, Version 2.0 20 | https://opensource.org/licenses/Apache-2.0 21 | repo 22 | 23 | 24 | 25 | 26 | https://github.com/wonwoo/dynamodb-spring-boot 27 | 28 | 29 | 30 | 31 | dynamodb-spring-boot 32 | https://api.bintray.com/maven/wonwoo/dynamodb-spring-boot/dynamodb-spring-boot/;publish=1 33 | 34 | 35 | 36 | 37 | dynamodb-spring-boot-core 38 | dynamodb-spring-boot-autoconfigure 39 | dynamodb-spring-boot-starter 40 | dynamodb-spring-boot-sample 41 | dynamodb-spring-boot-test-autoconfigure 42 | dynamodb-spring-boot-starter-test 43 | 44 | pom 45 | 46 | dynamodb-spring-boot 47 | dynamodb Spring boot AutoConfigure 48 | https://github.com/wonwoo/dynamodb-spring-boot 49 | 50 | 51 | UTF-8 52 | UTF-8 53 | 1.8 54 | 2.0.0.RELEASE 55 | 5.0.3 56 | 1.11.86 57 | 1.11.232 58 | 1.0.392 59 | 2.20 60 | 0.7.6.201602180812 61 | 4.3.0 62 | ${project.build.directory}/coverage-reports/jacoco-it.exec 63 | ${project.build.directory}/coverage-reports/jacoco-ut.exec 64 | 1.8 65 | 1.8 66 | 1.8 67 | 1.8 68 | wonwoo/dynamodb-spring-boot 69 | dynamodb-spring-boot 70 | 71 | 72 | 73 | 74 | 75 | com.github.wonwoo 76 | dynamodb-spring-boot-starter-test 77 | ${project.version} 78 | 79 | 80 | com.github.wonwoo 81 | dynamodb-spring-boot-starter 82 | ${project.version} 83 | 84 | 85 | com.github.wonwoo 86 | dynamodb-spring-boot-core 87 | ${project.version} 88 | 89 | 90 | com.github.wonwoo 91 | dynamodb-spring-boot-autoconfigure 92 | ${project.version} 93 | 94 | 95 | com.github.wonwoo 96 | dynamodb-spring-boot-test-autoconfigure 97 | ${project.version} 98 | 99 | 100 | com.github.derjust 101 | spring-data-dynamodb 102 | ${spring-data-dynamodb.version} 103 | 104 | 105 | com.amazonaws 106 | DynamoDBLocal 107 | ${dynamodb-local.version} 108 | true 109 | 110 | 111 | 112 | com.amazonaws 113 | aws-java-sdk-bom 114 | ${aws-java-sdk.version} 115 | pom 116 | import 117 | 118 | 119 | com.almworks.sqlite4java 120 | sqlite4java 121 | ${sqlite4java.version} 122 | true 123 | 124 | 125 | org.springframework.boot 126 | spring-boot-dependencies 127 | ${spring-boot.version} 128 | pom 129 | import 130 | 131 | 132 | 133 | 134 | 135 | 136 | dynamodblocal 137 | AWS DynamoDB Local Release Repository 138 | https://s3-us-west-2.amazonaws.com/dynamodb-local/release 139 | 140 | 141 | 142 | 143 | 144 | deploy 145 | 146 | 147 | 148 | org.apache.maven.plugins 149 | maven-gpg-plugin 150 | 1.6 151 | 152 | 153 | sign-artifacts 154 | verify 155 | 156 | sign 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | org.apache.maven.plugins 170 | maven-compiler-plugin 171 | 172 | 1.8 173 | 1.8 174 | 175 | 176 | 177 | org.apache.maven.plugins 178 | maven-jar-plugin 179 | 2.3.2 180 | 181 | 182 | org.apache.maven.plugins 183 | maven-source-plugin 184 | 2.3 185 | 186 | 187 | attach-sources 188 | verify 189 | 190 | jar 191 | 192 | 193 | 194 | 195 | 196 | org.apache.maven.plugins 197 | maven-javadoc-plugin 198 | 2.9.1 199 | 200 | 201 | attach-javadocs 202 | verify 203 | 204 | jar 205 | 206 | 207 | 208 | 209 | 210 | 211 | org.jacoco 212 | jacoco-maven-plugin 213 | ${maven.jacoco.version} 214 | 215 | ${project.reporting.outputDirectory}/${project.version}/jacoco 216 | 217 | 218 | 219 | default-prepare-agent 220 | 221 | prepare-agent 222 | 223 | 224 | ${jacoco.ut.execution.data.file} 225 | surefireArgLine 226 | 227 | 228 | 229 | default-prepare-agent-integration 230 | 231 | prepare-agent-integration 232 | 233 | 234 | 235 | default-report 236 | 237 | report 238 | 239 | 240 | ${jacoco.ut.execution.data.file} 241 | ${project.reporting.outputDirectory}/jacoco-ut 242 | 243 | 244 | 245 | default-report-integration 246 | 247 | report-integration 248 | 249 | 250 | ${jacoco.it.execution.data.file} 251 | ${project.reporting.outputDirectory}/jacoco-it 252 | 253 | 254 | 255 | 256 | 257 | org.eluder.coveralls 258 | coveralls-maven-plugin 259 | ${coveralls.version} 260 | 261 | qwbEzR9eSd6aWEdGsL99XuU8NblkJdPDL 262 | 263 | dynamodb-spring-boot-autoconfigure/target/site/jacoco-it/jacoco.xml 264 | dynamodb-spring-boot-autoconfigure/target/site/jacoco-ut/jacoco.xml 265 | dynamodb-spring-boot-core/target/site/jacoco-it/jacoco.xml 266 | dynamodb-spring-boot-core/target/site/jacoco-ut/jacoco.xml 267 | dynamodb-spring-boot-test-autoconfigure/target/site/jacoco-it/jacoco.xml 268 | dynamodb-spring-boot-test-autoconfigure/target/site/jacoco-ut/jacoco.xml 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | --------------------------------------------------------------------------------