spring data - intro (odessa java techtalks)
DESCRIPTION
Igor Anishchenko Odessa Java TechTalks Lohika - September, 2012 This session starts with a high-level look at all that the Spring Data project has to offer. Then we’ll dive deeper into a few select Spring Data modules, including Spring Data JPA, Spring Data MongoDB and Spring Data Redis. Implementing a data access layer of an application has been cumbersome for quite a while. Too much boilerplate code had to be written! Spring Data is a project that makes it easier to build Spring-powered applications that use new data, offering a reasonably consistent programming model regardless of which type of database you choose. In addition to supporting the new “NoSQL” databases such as document and graph databases, Spring Data also greatly simplifies working with RDBMS-oriented datastores using JPA -simplifies the development of creating a JPA-based data access layer.TRANSCRIPT
![Page 1: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/1.jpg)
Igor AnishchenkoLohika - September, 2012
Spring Data
![Page 2: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/2.jpg)
Relational Database
![Page 3: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/3.jpg)
Clouds
![Page 4: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/4.jpg)
Scaling
![Page 5: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/5.jpg)
![Page 6: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/6.jpg)
Column families
![Page 7: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/7.jpg)
Graphs
![Page 8: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/8.jpg)
Key Value
![Page 9: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/9.jpg)
Documents
![Page 10: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/10.jpg)
MongoDB
Document Database
JSON documentsJSON queries
![Page 11: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/11.jpg)
The most important difference is the data model:
MongoDB
![Page 12: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/12.jpg)
Mongo data model
A Mongo system (see deployment above) holds a set of databases A database holds a set of collections A collection holds a set of documents A document is a set of fields A field is a key-value pair
A key is a name (string) A value is a
basic type like string, integer, float, timestamp, binary, etc.,
a document, or an array of values
![Page 13: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/13.jpg)
MongoDB• Flexible data model
• Data can be inserted without a defined schema,
and the format of the data being inserted can
change at any time
• Easy scalability
• Databases automatically spreads data across
servers, requiring no participation from the
applications.
• Servers can be added and removed without
downtime
• Transparently cache data in system
![Page 14: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/14.jpg)
Mongo Infrastructure API
![Page 15: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/15.jpg)
Mongo Query API
![Page 16: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/16.jpg)
JPA?
![Page 17: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/17.jpg)
" This document is the specification of the Java API for the management of persistence and object/relational mapping with Java EE and Java SE. The technical objective of this work is to provide an object/relational mapping facility for the Java application developer using a Java domain model to man- age a relational database.
![Page 18: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/18.jpg)
" This document is the specification of the Java API for the management of persistence and object/relational mapping with Java EE and Java SE. The technical objective of this work is to provide an object/relational mapping facility for the Java application developer using a Java domain model to man- age a relational database.
![Page 19: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/19.jpg)
JPA?
![Page 20: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/20.jpg)
Decision Time?
As a developer - what are you looking for?
![Page 21: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/21.jpg)
Spring Data
![Page 22: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/22.jpg)
Mission statement
“… provides a familiar and consistent Spring-based programming model for NoSQL and relational stores while retaining store-specific features and capabilities”
![Page 23: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/23.jpg)
... history• The Spring Data project was coined at
2010• Originated by Rod Johnson (SpringSource)
and Neo Technologies) early that year• They were trying to integrate the Neo4j
graph database with the Spring framework and evaluated different approaches
• Current version
![Page 24: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/24.jpg)
Spring Data
JDBC JPAsupport for relational stores...
![Page 25: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/25.jpg)
Spring Data
JDBC JPAsupport for relational stores...
![Page 26: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/26.jpg)
Spring Data
JDBC JPAsupport for relational stores...
![Page 27: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/27.jpg)
Spring Data
JDBC JPAsupport for relational stores...
![Page 28: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/28.jpg)
Spring Data
JDBC JPAsupport for relational stores...
![Page 29: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/29.jpg)
Building blocks of Spring Data modules
Core components
![Page 30: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/30.jpg)
Spring Core• IoC/DI
• Spring namespace
• Configuring resources to access the stores
• Integration with core Spring functionality like JMX is provided which means that some stores will expose statistics through their native API
![Page 31: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/31.jpg)
Mapping
![Page 32: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/32.jpg)
• A very core part of the Spring Data modules is a mapping and conversion API that allows obtaining meta-data about domain classes
• Most of the NoSQL Java APIs do not provide support to map domain objects onto the stores data abstractions
• With native Java drivers You would usually have to write a significant amount of code to map data onto your domain objects
...Mapping
![Page 33: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/33.jpg)
JPA - Entity mapping
![Page 34: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/34.jpg)
Entity mapping - MongoDB
![Page 35: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/35.jpg)
Templates
![Page 36: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/36.jpg)
... Templates• Heavily used in spring (JdbcTemplate, JmsTemplate)
• JdbcTemplate - simplifies the use of JDBC and helps to:• avoid common errors• executes core JDBC workflow• SQL queries or updates, iteration over ResultSets and • catching JDBC exceptions
• Spring takes this concept and provided templates for noSQL stores• RedisTemplate• MongoTemplate
• Offer helper methods that allow us to execute commonly needed operations like persisting an object with a single statement while automatically taking care of appropriate resource management and exception translation
![Page 37: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/37.jpg)
MongoTemplate usage
![Page 38: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/38.jpg)
MongoOperation/-Template
![Page 39: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/39.jpg)
Repositories
![Page 40: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/40.jpg)
GenericDao
![Page 41: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/41.jpg)
... Repositories• Provides a repository abstraction on top of the Template
implementation
• Will reduce the effort to implement data access objects to a plain interface definition for the most common scenarios like standard CRUD operations as well as executing queries in case the store supports that.
• This abstraction is actually the most top layer and blends the APIs of the different stores as much as reasonably possible.
• Interface based programming model, so you have an interface for the queries you want to trigger and then those methods will be generated without a need to implement this interface
![Page 42: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/42.jpg)
Repositories - JPA
![Page 43: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/43.jpg)
Repositories - MongoDB
![Page 44: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/44.jpg)
Querydsl
![Page 45: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/45.jpg)
DEMO
![Page 46: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/46.jpg)
Summary• Abstraction over stores drivers• Mapping support• Templates• Repositories / custom repositories• Querydsl• Spring namespace• Cross-store persistence
![Page 47: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/47.jpg)
?
???
? ?
![Page 48: Spring Data - Intro (Odessa Java TechTalks)](https://reader036.vdocument.in/reader036/viewer/2022062513/554f9fffb4c9057b298b4852/html5/thumbnails/48.jpg)
Resourceswww.springframework.org/spring-data
http://github.com/SpringSource/spring-data-mongodb
O'Reilly's Open Feedback Publishing System is the book:http://ofps.oreilly.com/titles/9781449323950/
http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis