GithubHelp home page GithubHelp logo

ninjayoto / spring-data-dynamodb-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from derjust/spring-data-dynamodb-examples

0.0 2.0 0.0 63 KB

Examples for Spring-Data-DynamoDB available at https://github.com/derjust/spring-data-dynamodb/

License: Apache License 2.0

Java 100.00%

spring-data-dynamodb-examples's Introduction

๐Ÿ“š Spring Data DynamoDB Examples

Examples for Spring-Data-DynamoDB available at github.com/derjust/spring-data-dynamodb

Please also check the ๐Ÿ“– Wiki

The following examples exist and how they can be executed

๐Ÿš€ Simple Repository

This example show the most basic usage also referenced by the README.md of the main project.

Further explanation can be found

๐Ÿ“— Multi Repository

This example shows how to use multiple Spring Data repository types to access different storage backend.

In this example DynamoDB and MySQL is used.

Further explanation can be found

๐Ÿ“œ Code sample

The respective repository providers must be informed which interface to take care of. In a @Configurable bean the interfaces have to be assigned via include/exclude filters:

@SpringBootApplication
@EnableJpaRepositories(
  includeFilters = {
    @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
      CustomerRepository.class}
  )}
)
@EnableDynamoDBRepositories(
  includeFilters = {
    @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
      DeviceRepository.class}
  )}
)
@Configuration
public class Application {

๐Ÿ“• Custom repository methods

This example shows how to use custom methods as part of Spring Data repository interfaces to implement custom logic.

Further explanation can be found

๐Ÿ“œ Code sample

The repository interface is extend by an additional interface. It's implementation is found by the Impl suffix in the same package. Spring Data itself takes care of weaving in the implementation at runtime:

public interface UserRepository extends CrudRepository<User, Long>, CustomUserRepositoryMethods { }


public interface CustomUserRepositoryMethods {
    User calculateAge(User user);
}


public class CustomUserRepositoryMethodsImpl implements CustomUserRepositoryMethods {

    @Override
    public User calculateAge(User user) {
        /* custom code */
    }
}



// Regular method of the repository interface
User user = userRepository.findOne(id);
// Custom method available via the interface, too
userRepository.calculateAge(user);

๐Ÿ“˜ REST integration

This example shows how to use spring-data-dynamodb with spring-data-rest to automatically expose CRUD operations on DynamoDB entities via REST endpoints.

Further explanation can be found

๐Ÿ“œ Code sample

An additional DynamoDB bean must be registered and injected - everything else happens via auto-configuration:

@EnableDynamoDBRepositories(
		mappingContextRef = "dynamoDBMappingContext",
		includeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
				UserRepository.class}
		)}
)


@Bean
public DynamoDBMappingContext dynamoDBMappingContext() {
    return new DynamoDBMappingContext();
}

spring-data-dynamodb-examples's People

Contributors

davinpidoto avatar derjust avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.