Using Spring Data and MongoDB with Cloud Foundry

22
© 2009 VMware Inc. All rights reserved Using Spring and MongoDB with Cloud Foundry Chris Harris, Architect

description

Presentation delivered at MongoUK 2011

Transcript of Using Spring Data and MongoDB with Cloud Foundry

Page 1: Using Spring Data and MongoDB with Cloud Foundry

© 2009 VMware Inc. All rights reserved

Using Spring and MongoDB with Cloud FoundryChris Harris, Architect

Page 2: Using Spring Data and MongoDB with Cloud Foundry

2

Spring Data

Page 3: Using Spring Data and MongoDB with Cloud Foundry

3

Data Access Challenge #1: Scale Horizontally

Page 4: Using Spring Data and MongoDB with Cloud Foundry

4

Data Access Challenge #2: Heterogeneous data access needs

Page 5: Using Spring Data and MongoDB with Cloud Foundry

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

Page 6: Using Spring Data and MongoDB with Cloud Foundry

6

NoSQL offers several data store categories

ColumnKey-Value Document Graph

Page 7: Using Spring Data and MongoDB with Cloud Foundry

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)

Page 8: Using Spring Data and MongoDB with Cloud Foundry

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

Page 9: Using Spring Data and MongoDB with Cloud Foundry

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

Page 10: Using Spring Data and MongoDB with Cloud Foundry

10

Spring MongoDB

Page 11: Using Spring Data and MongoDB with Cloud Foundry

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

Page 12: Using Spring Data and MongoDB with Cloud Foundry

12

Simple Domain Class

Page 13: Using Spring Data and MongoDB with Cloud Foundry

13

Mongo Template

Direct Usage of the Mongo Template:

Page 14: Using Spring Data and MongoDB with Cloud Foundry

14

Generic Repository

Interface for generic CRUD operations on a repository for a specific type

Page 15: Using Spring Data and MongoDB with Cloud Foundry

15

Paging and Sorting Repository

Extends “CrudRepository”

Usage:

Paging and Sorting Repository:

Page 16: Using Spring Data and MongoDB with Cloud Foundry

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 :

Page 17: Using Spring Data and MongoDB with Cloud Foundry

17

Cross Store

Page 18: Using Spring Data and MongoDB with Cloud Foundry

18

JPA and MongoDB

JPA “Customer” with a “SurveyInfo” Document

Page 19: Using Spring Data and MongoDB with Cloud Foundry

19

Using a Cross-Store

Saving a Customer with a SurveryInfo

Mongo Document:

Page 20: Using Spring Data and MongoDB with Cloud Foundry

20

Cloud Foundry

Page 21: Using Spring Data and MongoDB with 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

Page 22: Using Spring Data and MongoDB with Cloud Foundry

22

Cloud Foundry MongoDB Demo