© 2009 VMware Inc. All rights reserved Using Spring and MongoDB with Cloud Foundry Chris Harris, Architect
May 11, 2015
© 2009 VMware Inc. All rights reserved
Using Spring and MongoDB with Cloud FoundryChris Harris, Architect
2
Spring Data
3
Data Access Challenge #1: Scale Horizontally
4
Data Access Challenge #2: Heterogeneous data access needs
5
New demands on data access
•... until we needed inexpensive horizontal scaling for some large web based applications ...•... and we needed to deploy our apps in the cloud ...
image courtesy of Bitcurrent
6
NoSQL offers several data store categories
ColumnKey-Value Document Graph
7
Spring Frameworkbuilt-in data access support
•Transaction abstractions•Common data access exception hierarchy•JDBC - JdbcTemplate•ORM - Hibernate, JPA support•OXM - Object to XML mapping•Serializer/Deserializer strategies (Spring 3.0)•Cache support (Spring 3.1)
8
•Spring Data Key-value•Spring Data Document•Spring Data Graph•Spring Data Column•Spring Data Blob•Spring Data JPA Repository / JDBC Extensions•Spring Gemfire / Spring Hadoop ...•Grails iNcOnSeQuentiaL
9
Spring Data Building Blocks
•Low level data access APIs✓MongoTemplate, RedisTemplate ...
•Object Mapping (Java and GORM)•Cross Store Persistence Programming model•Generic Repository support •Productivity support in Roo and Grails
10
Spring MongoDB
11
Spring Data Document Mongo
•MongoTemplate•MongoConverter interface for mapping Mongo documents•SimpleMongoConverter for basic POJO mapping support•Leverage Spring 3.0 TypeConverters and SpEL•Exception translation
•Advanced Mapping•Annotation based (@Document, @Id, @DbRef)
•MongoRepository•Built on Hades support for JPA Repositories
12
Simple Domain Class
13
Mongo Template
Direct Usage of the Mongo Template:
14
Generic Repository
Interface for generic CRUD operations on a repository for a specific type
15
Paging and Sorting Repository
Extends “CrudRepository”
Usage:
Paging and Sorting Repository:
16
Custom Repository
Custom Repository:
Keyword Sample Logical result
GreaterThan findByAgeGreaterThan(int age) {"age" : {"$gt" : age}}
LessThan findByAgeLessThan(int age) {"age" : {"$lt" : age}}
Between findByAgeBetween(int from, int to) {"age" : {"$gt" : from, "$lt" : to}}
NotNull findByFirstnameNotNull() {”firstname" : {"$ne" : null}}
Null findByFirstnameNull() {”firstname" : null}
Like findByFirstnameLike(String name) "firstname" : firstname} (regex)
etc….
Keywords :
17
Cross Store
18
JPA and MongoDB
JPA “Customer” with a “SurveyInfo” Document
19
Using a Cross-Store
Saving a Customer with a SurveryInfo
Mongo Document:
20
Cloud Foundry
21
Clou
d Pro
vider
Inte
rfaceApplication Service Interface
Private Clouds
PublicClouds
MicroClouds
Choice of clouds
.js
Data Services
Other Services
Msg Services
.COM
…
22
Cloud Foundry MongoDB Demo