Spring Data


Spring Data
eBook: $17.99
Formats: PDF, PacktLib, ePub and Mobi formats
$15.29
save 15%!
Print + free eBook + free PacktLib access to the book: $42.98    Print cover: $24.99
$24.99
save 42%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Implement JPA repositories with lesser code
  • Includes functional sample projects that demonstrate the described concepts in action and help you start experimenting right away
  • Provides step-by-step instructions and a lot of code examples that are easy to follow and help you to get started from page one

Book Details

Language : English
Paperback : 160 pages [ 235mm x 191mm ]
Release Date : November 2012
ISBN : 1849519048
ISBN 13 : 9781849519045
Author(s) : Petri Kainulainen
Topics and Technologies : All Books, Application Development, Data, Open Source

Table of Contents

Preface
Chapter 1: Getting Started
Chapter 2: Getting Started with Spring Data JPA
Chapter 3: Building Queries with Spring Data JPA
Chapter 4: Adding Custom Functionality to JPA Repositories
Chapter 5: Getting Started with Spring Data Redis
Chapter 6: Building Applications with Spring Data Redis
Index
  • Chapter 1: Getting Started
    • Java Persistence API
      • Key concepts
      • Creating database queries
        • Native SQL queries
        • Java Persistence Query Language
        • The Criteria API
    • Redis
      • Supported data types
      • Persistence
      • Replication
      • Publish/subscribe messaging pattern
    • Summary
    • Chapter 2: Getting Started with Spring Data JPA
      • Downloading dependencies with Maven
      • Configuring the Spring application context
        • Creating the properties file
        • Creating the application context configuration class
          • Creating the application context configuration skeleton
          • Configuring the data source bean
          • Configuring the entity manager factory bean
          • Configuring the transaction manager bean
      • Loading the application context configuration
      • Implementing CRUD functionality for an entity
        • Domain model
          • Contact
          • Address
        • Creating a custom repository
          • Creating a custom repository in the old school way
          • Creating a custom repository with Spring Data JPA
        • CRUD
          • Create
          • Read
          • Update
          • Delete
      • Summary
      • Chapter 3: Building Queries with Spring Data JPA
        • Building queries
          • Query methods
            • Query generation from method name
            • Named queries
            • @Query annotation
          • JPA Criteria API
            • Adding the JPA Criteria API support to a repository
            • Creating the criteria query
            • Creating the service method
            • Pros and cons
          • Querydsl
            • Configuring Querydsl-Maven integration
            • Generating Querydsl query types
            • Adding Querydsl support to a repository
            • Creating the executed query
            • Executing the created query
            • Pros and cons
          • What technique should we use?
        • Sorting query results
          • Sorting with method name
            • Creating the query method
            • Modifying the service method
          • Sorting with query strings
            • JPQL queries
            • SQL queries
          • Sorting with the Sort class
            • JpaRepository
            • Query generation from the method name
            • @Query annotation
            • JPA Criteria API
          • Sorting with Querydsl
          • What technique should we use?
        • Paginating query results
          • Changing the service layer
            • Creating a class for pagination parameters
            • Changing the service interface
            • Creating PageRequest objects
          • Implementing pagination
            • JpaRepository
            • Query generation from the method name
            • Named queries
            • @Query annotation
            • JPA Criteria API
            • Querydsl
        • Summary
        • Chapter 4: Adding Custom Functionality to JPA Repositories
          • Adding custom functionality to a single repository
            • Creating the custom interface
            • Implementing the created interface
              • Configuring the repository class
              • Implementing the custom methods
            • Creating the repository interface
            • Creating the service implementation
            • What did we just do?
          • Adding custom functionality to all repositories
            • Creating the base repository interface
            • Implementing the base repository interface
            • Creating the repository factory bean
              • Creating the skeleton of the repository factory bean class
              • Creating the repository factory inner class
              • Creating the builder method for the repository factory
            • Configuring Spring Data JPA
            • Creating the repository interface
            • Implementing the service layer
            • What did we just do?
          • Summary
          • Chapter 5: Getting Started with Spring Data Redis
            • Installing Redis
            • Getting the required dependencies
            • Configuring the Spring application context
            • Configuring the Redis connection
              • Configuring the Jedis connector
              • Configuring the JRedis connector
              • Configuring the RJC connector
              • Configuring the SRP connector
            • Summary
            • Chapter 6: Building Applications with Spring Data Redis
              • Designing a Redis data model
              • Key components
                • Atomic counters
                • RedisTemplate
                  • Operations
                  • Serializers
              • Implementing a CRUD application
                • Using default serializers
                  • Configuring the application context
                  • CRUD
                • Storing data in JSON
                  • Configuring the application context
                  • CRUD
              • The publish/subscribe messaging pattern
                • Creating message listeners
                  • Implementing the MessageListener interface
                  • Creating a POJO message listener
                • Configuring the application context
                  • Configuring the message listener beans
                  • Configuring the message listener adapter bean
                  • Configuring the message listener container bean
                • Sending messages with RedisTemplate
                  • Create
                  • Update
                  • Delete
                • Verifying the wanted behaviour
              • Using Spring cache abstraction with Spring Data Redis
                • Configuring the Spring cache abstraction
                  • Enabling caching annotations
                  • Configuring the host and port of the used Redis instance
                  • Configuring the Redis connection factory bean
                  • Configuring the Redis template bean
                  • Configuring the cache manager bean
                • Identifying the cached methods
                  • Adding contact information to the cache
                  • Updating the contact information to the cache
                  • Deleting contact information from the cache
                • Verifying that the Spring cache abstraction is working
              • Summary

              Petri Kainulainen

              Petri Kainulainen is a software developer living in Tampere, Finland. He is specialized in application development with the Java programming language and the Spring framework. Petri has over 10 years of experience in software development, and during his career he has participated in the development projects of Finland's leading online market places as a software architect. He is currently working at Vincit Oy as a passionate software developer.
              Sorry, we don't have any reviews for this title yet.

              Code Downloads

              Download the code and support files for this book.


              Submit Errata

              Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


              Errata

              - 5 submitted: last submission 05 Jun 2013

              Errata Type: Code Page No.: 50 Errata Date: 25-04-2013

              @Query(value = "SELECT * FROM contacts c WHERE LOWER(c.first_name) LIKE LOWER(:searchTerm) OR LOWER(c.last_name) LIKE LOWER(:searchTerm), nativeQuery = true)
              Should be:
              @Query(value = "SELECT * FROM contacts c WHERE LOWER(c.first_name) LIKE LOWER(:searchTerm) OR LOWER(c.last_name) LIKE LOWER(:searchTerm)", nativeQuery = true)

              Errata Type: Code Page No.: 56 Errata Date: 14-05-2013

              There is a missing slash (/) at the closing version element:
              <version>2.8.0<version>
              Should be:
              <version>2.8.0</version>

              For more information on the usage of the APT Maven plugin in a multi-module Maven project (Page 57), you can refer to the blog post by Petri Kainulainen at http://www.petrikainulainen.net/programming/spring-framework/spring-data-jpa-tutorial-using-querydsl-in-a-multi-module-maven-project

              Errata Type: Grammar
              Page no:
              60

              In the last bullet point under the What technique should we use? section, there is a correction in language

              "...from a scratch" should be "...from scratch"

              Page no: 67

              In the fourth bullet pointunder the What technique should we use? section, there is a correction in language

              "When we are building our queries by using the JPA Criteria API, we must use the Sort class because that is only the method provided by the JpaSpecificationExecutor interface."
              Should be
              "When we are building our queries by using the JPA Criteria API, we must use the Sort class because that is the only method provided by the JpaSpecificationExecutor interface."

              Errata Type: Technical Page no: 73

              The page reads: At this point we are not interested in the metadata of the returned page. Thus, the declaration of the query method is given as follows

              It could read: At this point we are not interested in the metadata of the returned page. Thus, we return a List of Contact objects instead of a Page of Contact objects and the declaration of the query method is given as follows

              Sorry, there are currently no downloads available for this title.

              Frequently bought together

              Spring Data +    Spring Security 3.1 =
              50% Off
              the second eBook
              Price for both: $34.50

              Buy both these recommended eBooks together and get 50% off the cheapest eBook.

              What you will learn from this book

              • Configure your application by using Java configuration
              • Manage the information of your entities through repository interfaces
              • Learn efficient and easy ways to create database queries
              • Use an easy way to sort and paginate query results
              • Customize your JPA repositories with custom functions
              • Install Redis to a computer running Unix-like operating system
              • Use the Redis key-value store as the data storage for your application
              • Utilize the Redis publish/subscribe messaging pattern implementation

              In Detail

              Spring Framework has always had a good support for different data access technologies. However, developers had to use technology-specific APIs, which often led to a situation where a lot of boilerplate code had to be written in order to implement even the simplest operations. Spring Data changed all this. Spring Data makes it easier to implement Spring-powered applications that use cloud-based storage services, NoSQL databases, map-reduce frameworks or relational databases.

              "Spring Data" is a practical guide that is full of step-by-step instructions and examples which ensure that you can start using the Java Persistence API and Redis in your applications without extra hassle.

              This book provides a brief introduction to the underlying data storage technologies, gives step-by-step instructions that will help you utilize the discussed technologies in your applications, and provides a solid foundation for expanding your knowledge beyond the concepts described in this book.

              You will learn an easier way to manage your entities and to create database queries with Spring Data JPA. This book also demonstrates how you can add custom functions to your repositories. You will also learn how to use the Redis key-value store as data storage and to use its other features for enhancing your applications.

              "Spring Data" includes all the practical instructions and examples that provide you with all the information you need to create JPA repositories with Spring Data JPA and to utilize the performance of Redis in your applications by using Spring Data Redis.

              Approach

              This book is a standard tutorial which provides step-by-step instructions and a lot of code examples that are easy to follow and help you to get started from page one.

              Who this book is for

              This book is suited for developers who are working with Spring-powered applications, and are looking for an easier way to write data access code that uses relational databases. Also, if you are interested in learning how you can utilize Redis in your applications, this is the book for you. This book assumes that you have got some experience with the Spring Framework and the Java Persistence API. No previous experience with Redis is required.

              Code Download and Errata
              Packt Anytime, Anywhere
              Register Books
              Print Upgrades
              eBook Downloads
              Video Support
              Contact Us
              Awards Voting Nominations Previous Winners
              Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
              Resources
              Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software