SlideShare a Scribd company logo
Data Access 2.0?
     …please welcome…


  Spring Data!

        Oliver Gierke
Oliver Gierke

Spring Data
Core/JPA/MongoDB

ogierke@vmware.com
www.olivergierke.de
olivergierke
What to expect?
How?

Why?


        What?
A Developer‘s View
What to expect?
     NOT!
What to expect?
     NOT!
Retrospect
Relational databases
Scaling
Data structures
Hibari Voldemort
   Membase
               Riak    Cassandra
    Redis
SimpleDB    (No)SQL            MongoDB

            OrientDB      CouchDB
   HBase
                       Sones
            Neo4J
Key Value
Column families
Graphs
Documents
Data access 2.0? Please welcome: Spring Data!
Document database
 JSON documents
   JSON queries
MongoDB Infrastructure API

     Mongo mongo = new Mongo(…);
     DB db = mongo.getDB("myDatabase");
     Collection collection = db.getCollection("myCollection");

     DBObject address = new BasicDBObject();
     address.put("city", "London");

     DBObject person = new BasicDBObject();
     person.put("firstname", "Dave");
     person.put("lastname", "Matthews");
     person.put("address", address);

     collection.save(person);




19
MongoDB Query API

 Mongo mongo = new Mongo(…);
 DB db = mongo.getDB("myDatabase");
 Collection collection = db.getCollection("myCollection");

 DBObject query = new BasicDBObject();
 query.put("address.city", "London");

 DBCursor cursor = collection.find(query);

 for (DBObject element : cursor) {
   // Map data onto object
 }




20
Graph database
    Nodes / Relationships
Traversals / Cypher / Gremlin
Neo4J Infrastructure API

     GraphDatabaseService database = new EmbeddedGraphDatabase(…);
     Transaction tx = database.beginTx();

     try {
        Node mrAnderson = database.createNode();
        mrAnderson.setProperty("name", "Thomas Anderson");
        Node morpheus = database.createNode();
        morpheus.setProperty("name", "Morpheus");

       Relationship friendship = mrAnderson.createRelationshipTo(
         morpheus, FriendTypes.KNOWS);

        tx.success();
     } finally {
        tx.finish();
     }


22
Neo4J Query API

     GraphDatabaseService database = new EmbeddedGraphDatabase(…);

     CypherParser parser = new CypherParser();
     Query query = parser.parse("start person = Person(id = *) match " +
       "person-[:colleagues]->colleague where colleague.firstname = {name}");

     Map<String, Object> parameters = new HashMap<String, Object>();
     parameters.put("name", "Dave");

     ExecutionEngine engine = new ExecutionEngine(database);
     ExecutionResult result = engine.execute(query, parameters);

     for (EntrySet<String, Object> element : result) {
       // Map data onto object
     }




23
Neo4J entity

     class Actor {

         private final Node node;

         public Actor(Node node) { … }

         public String getName() {
           return (String) node.getProperty(„name“);
         }

         …
     }




24
Forest for the woods?
JPA?
"
    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.
"
    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.
JPA?
There‘s some
Spring for that!
Spring Data
"   … provide a familiar and
    consistent Spring-based
    programming model while
    retaining store-specific
    features and capabilities.
Spring Data




  JDBC   JPA
Spring Data




  JDBC   JPA
Spring Data




  JDBC   JPA
Spring Data




  JDBC   JPA
Building blocks
Spring
Mapping
JPA entity mapping

 @Entity
 class Person {

     @Id
     @GeneratedValue(strategy=GenerationType.AUTO)
     private BigInteger id;
     private String firstname, lastname;

     @Column(name="email")
     private String emailAddress;

     @OneToMany
     private Set<Person> colleagues;
 }




40
Entity mapping - MongoDB

     @Document
     class Person {

         @Id private BigInteger id;
         @Indexed private String firstname, lastname;
         @Field("email") private String emailAddress;
         @DBRef private Set<Person> colleagues;

         public Person(String firstname) { … }

         @PersistenceConstructor
         public Person(String firstname, String lastname) { … }

         …
     }




41
Entity mapping - Neo4J

     @NodeEntity
     class Person {

         @GraphId private long id;
         @Indexed private String firstname, lastname;
         @RelatedTo(direction = Direction.INCOMING)
         private Set<Person> colleagues;

         public Person(String firstname) { … }

         @PersistenceConstructor
         public Person(String firstname, String lastname) { … }

         …
     }




42
Templates
MongoOperations / -Template

 public interface MongoOperations {

     // Generic callback-accepting methods
     <T> T execute(DbCallback<T> action);
     <T> T execute(Class<?> entityClass, CollectionCallback<T> action);
     <T> T execute(String collectionName, CollectionCallback<T> action);

     // Higher level access methods
     <T> List<T> find(Query query, Class<T> entityClass);
     void save(Object objectToSave, String collectionName);
     WriteResult updateFirst(Query query, Update update, Class<?>
         entityClass);

     // Geo API
     <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass);
 }



44
MongoTemplate usage

     // Setup infrastructure
     Mongo mongo = new Mongo();
     MongoDbFactory factory = new SimpleMongoDbFactory(mongo, „foo“);
     MongoTemplate template = new MongoTemplate(factory);

     // Create and save entity
     Person dave = new Person("Dave", "Matthews");
     dave.setEmailAddress("dave@dmband.com");
     template.save(person);

     // Query entity
     Query query = new Query(new Criteria("emailAddress")
                                         .is("dave@dmband.com"));
     assertThat(template.find(query), is(dave));




45
Repositories
Repositories - JPA

     <jpa:repositories base-package="com.acme.repositories" />

     public interface PersonRepository extends Repository<Person, BigInteger>
     {
       // Finder for a single entity
       Person findByEmailAddress(String emailAddress);

         // Finder for multiple entities
         List<Person> findByLastnameLike(String lastname);

         // Finder with pagination
         Page<Person> findByFirstnameLike(String firstname, Pageable page);
     }




47
Repositories - MongoDB

     public interface PersonRepository extends Repository<Person, BigInteger>
     {
       // Finder for a single entity
       Person findByEmailAddress(String emailAddress);

         // Finder for multiple entities
         List<Person> findByLastnameLike(String lastname);

         // Finder with pagination
         Page<Person> findByFirstnameLike(String firstname, Pageable page);

         // Geospatial queries
         List<Person> findByLocationNear(Point location, Distance distance);
         GeoResults<Person> findByLocationNear(Point location);
     }




48
Repositories - MongoDB

     <mongo:repositories base-package="com.acme.repositories" />

     @Component
     public class MyClient {

         @Autowired
         private PersonRepository repository;

         public List<Person> doSomething() {

             Point point = new Point(43.7, 48.8);
             Distance distance = new Distance(200, Metrics.KILOMETERS);
             return repository.findByLocationNear(point, distance);
         }
     }




49
Repositories - Neo4J

 interface PersonRepository extends GraphRepository<Person, Long>
    // Finder for a single entity
    Person findByEmailAddress(String emailAddress);

     // Finder for multiple entities
     List<Person> findByLastnameLike(String lastname);

     // Finder with pagination
     Page<Person> findByFirstnameLike(String firstname, Pageable page);

     @Query("start person = Person(id = *) " +
              "match person-[:colleagues]->colleague where " +
              "colleague.firstname = {name}")
     List<Person> getPersonsWithColleaguesName(
                                     @Param("name") Movie m);
 }



50
Repositories
        Querydsl




51
Querydsl

     QPerson $ = QPerson.person;
     BooleanExpression left = $.lastname.contains("eth");
     BooleanExpression right = $.firstname.is("Carter");

     public interface QueryDslPredicateExecutor<T> {
       T findOne(Predicate predicate);
       List<T> findAll(Predicate predicate);
     }

     public interface PersonRepository extends Repository<Person, BigInteger>,
       QueryDslPredicateExecutor { … }

     List<Person> result = repository.findAll(left.or(right));
     assertThat(result.size(), is(2));
     assertThat(result, hasItems(dave, carter));




52
Wrap up
Wrap up
Sophisticated mapping support
           Templates
         Repositories
            Querydsl
      Spring namespace
Geospatial support (MongoDB)
   Cross-store persistence
Questions?
Resources

•   www.springframework.org/spring-data

•   github.com/SpringSource/spring-data-mongodb

•   github.com/SpringSource/spring-data-neo4j

•   http://www.se-radio.net/2010/07/episode-165-nosql-and-
    mongodb-with-dwight-merriman

•   http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
Ad

More Related Content

What's hot (20)

Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
DATAVERSITY
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
Arawn Park
 
Green dao
Green daoGreen dao
Green dao
Droidcon Berlin
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
MongoDB
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
Booch Lin
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
MongoDB
 
2001: JNDI Its all in the Context
2001:  JNDI Its all in the Context2001:  JNDI Its all in the Context
2001: JNDI Its all in the Context
Russell Castagnaro
 
Ajax chap 5
Ajax chap 5Ajax chap 5
Ajax chap 5
Mukesh Tekwani
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
MongoDB
 
Ajax chap 4
Ajax chap 4Ajax chap 4
Ajax chap 4
Mukesh Tekwani
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
MongoDB
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applications
jeromevdl
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
ObjectBox - The new Mobile Database
ObjectBox - The new Mobile DatabaseObjectBox - The new Mobile Database
ObjectBox - The new Mobile Database
greenrobot
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
Haroon Idrees
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 
Jndi (1)
Jndi (1)Jndi (1)
Jndi (1)
laraibnaeem
 
Wed 1630 greene_robert_color
Wed 1630 greene_robert_colorWed 1630 greene_robert_color
Wed 1630 greene_robert_color
DATAVERSITY
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
Arawn Park
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
MongoDB
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
Booch Lin
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
MongoDB
 
2001: JNDI Its all in the Context
2001:  JNDI Its all in the Context2001:  JNDI Its all in the Context
2001: JNDI Its all in the Context
Russell Castagnaro
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
MongoDB
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
MongoDB
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applications
jeromevdl
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
ObjectBox - The new Mobile Database
ObjectBox - The new Mobile DatabaseObjectBox - The new Mobile Database
ObjectBox - The new Mobile Database
greenrobot
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
Haroon Idrees
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 

Viewers also liked (20)

Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
Oliver Gierke
 
Building Performance - ein Frontend-Build-Prozess für Java mit Maven
Building Performance - ein Frontend-Build-Prozess für Java mit MavenBuilding Performance - ein Frontend-Build-Prozess für Java mit Maven
Building Performance - ein Frontend-Build-Prozess für Java mit Maven
Oliver Ochs
 
Spring Roo 1.0.0 Technical Deep Dive
Spring Roo 1.0.0 Technical Deep DiveSpring Roo 1.0.0 Technical Deep Dive
Spring Roo 1.0.0 Technical Deep Dive
Ben Alex
 
Generic DAOs With Hades
Generic DAOs With HadesGeneric DAOs With Hades
Generic DAOs With Hades
Oliver Gierke
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?
Oliver Gierke
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
Oliver Gierke
 
Coding & Music Passion And Profession
Coding & Music   Passion And ProfessionCoding & Music   Passion And Profession
Coding & Music Passion And Profession
Oliver Gierke
 
REST based web applications with Spring 3
REST based web applications with Spring 3REST based web applications with Spring 3
REST based web applications with Spring 3
Oliver Gierke
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
Oliver Gierke
 
Mylyn - Increasing developer productivity
Mylyn - Increasing developer productivityMylyn - Increasing developer productivity
Mylyn - Increasing developer productivity
Oliver Gierke
 
Increasing developer procutivity with Mylyn (Devoxx 2010)
Increasing developer procutivity with Mylyn (Devoxx 2010)Increasing developer procutivity with Mylyn (Devoxx 2010)
Increasing developer procutivity with Mylyn (Devoxx 2010)
Oliver Gierke
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
Oliver Gierke
 
Sophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & HadesSophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & Hades
Oliver Gierke
 
Spring in action - Hades & Spring Roo
Spring in action - Hades & Spring RooSpring in action - Hades & Spring Roo
Spring in action - Hades & Spring Roo
Oliver Gierke
 
Real world dependency injection - DPC10
Real world dependency injection - DPC10Real world dependency injection - DPC10
Real world dependency injection - DPC10
Stephan Hochdörfer
 
Mylyn
MylynMylyn
Mylyn
Oliver Gierke
 
MongoDB basics in Russian
MongoDB basics in RussianMongoDB basics in Russian
MongoDB basics in Russian
Oleg Kachan
 
Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!
Oliver Gierke
 
CDI 2.0 is upon us Devoxx
CDI 2.0 is upon us DevoxxCDI 2.0 is upon us Devoxx
CDI 2.0 is upon us Devoxx
Antoine Sabot-Durand
 
Spring integration
Spring integrationSpring integration
Spring integration
Oliver Gierke
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
Oliver Gierke
 
Building Performance - ein Frontend-Build-Prozess für Java mit Maven
Building Performance - ein Frontend-Build-Prozess für Java mit MavenBuilding Performance - ein Frontend-Build-Prozess für Java mit Maven
Building Performance - ein Frontend-Build-Prozess für Java mit Maven
Oliver Ochs
 
Spring Roo 1.0.0 Technical Deep Dive
Spring Roo 1.0.0 Technical Deep DiveSpring Roo 1.0.0 Technical Deep Dive
Spring Roo 1.0.0 Technical Deep Dive
Ben Alex
 
Generic DAOs With Hades
Generic DAOs With HadesGeneric DAOs With Hades
Generic DAOs With Hades
Oliver Gierke
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?
Oliver Gierke
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
Oliver Gierke
 
Coding & Music Passion And Profession
Coding & Music   Passion And ProfessionCoding & Music   Passion And Profession
Coding & Music Passion And Profession
Oliver Gierke
 
REST based web applications with Spring 3
REST based web applications with Spring 3REST based web applications with Spring 3
REST based web applications with Spring 3
Oliver Gierke
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
Oliver Gierke
 
Mylyn - Increasing developer productivity
Mylyn - Increasing developer productivityMylyn - Increasing developer productivity
Mylyn - Increasing developer productivity
Oliver Gierke
 
Increasing developer procutivity with Mylyn (Devoxx 2010)
Increasing developer procutivity with Mylyn (Devoxx 2010)Increasing developer procutivity with Mylyn (Devoxx 2010)
Increasing developer procutivity with Mylyn (Devoxx 2010)
Oliver Gierke
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
Oliver Gierke
 
Sophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & HadesSophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & Hades
Oliver Gierke
 
Spring in action - Hades & Spring Roo
Spring in action - Hades & Spring RooSpring in action - Hades & Spring Roo
Spring in action - Hades & Spring Roo
Oliver Gierke
 
Real world dependency injection - DPC10
Real world dependency injection - DPC10Real world dependency injection - DPC10
Real world dependency injection - DPC10
Stephan Hochdörfer
 
MongoDB basics in Russian
MongoDB basics in RussianMongoDB basics in Russian
MongoDB basics in Russian
Oleg Kachan
 
Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!Data Access 2.0? Please welcome, Spring Data!
Data Access 2.0? Please welcome, Spring Data!
Oliver Gierke
 
Ad

Similar to Data access 2.0? Please welcome: Spring Data! (20)

Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
 
NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020
Thodoris Bais
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012
Timo Westkämper
 
Requery overview
Requery overviewRequery overview
Requery overview
Sunghyouk Bae
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
Maarten Balliauw
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015
Svetlin Nakov
 
Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS
Nuxeo
 
Spring data
Spring dataSpring data
Spring data
명철 강
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
James Williams
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDb
sliimohara
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
MongoSF
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
Norberto Leite
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
MongoDB
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
Trisha Gee
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
Heiko Behrens
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
 
NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020
Thodoris Bais
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012
Timo Westkämper
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
 
Building a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to SpaceBuilding a friendly .NET SDK to connect to Space
Building a friendly .NET SDK to connect to Space
Maarten Balliauw
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015
Svetlin Nakov
 
Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS
Nuxeo
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
James Williams
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
GaryCoady
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDb
sliimohara
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
MongoSF
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
Norberto Leite
 
Mongo+java (1)
Mongo+java (1)Mongo+java (1)
Mongo+java (1)
MongoDB
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
Trisha Gee
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
Heiko Behrens
 
Ad

Recently uploaded (20)

What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 

Data access 2.0? Please welcome: Spring Data!

  • 1. Data Access 2.0? …please welcome… Spring Data! Oliver Gierke
  • 4. How? Why? What?
  • 12. Hibari Voldemort Membase Riak Cassandra Redis SimpleDB (No)SQL MongoDB OrientDB CouchDB HBase Sones Neo4J
  • 18. Document database JSON documents JSON queries
  • 19. MongoDB Infrastructure API Mongo mongo = new Mongo(…); DB db = mongo.getDB("myDatabase"); Collection collection = db.getCollection("myCollection"); DBObject address = new BasicDBObject(); address.put("city", "London"); DBObject person = new BasicDBObject(); person.put("firstname", "Dave"); person.put("lastname", "Matthews"); person.put("address", address); collection.save(person); 19
  • 20. MongoDB Query API Mongo mongo = new Mongo(…); DB db = mongo.getDB("myDatabase"); Collection collection = db.getCollection("myCollection"); DBObject query = new BasicDBObject(); query.put("address.city", "London"); DBCursor cursor = collection.find(query); for (DBObject element : cursor) { // Map data onto object } 20
  • 21. Graph database Nodes / Relationships Traversals / Cypher / Gremlin
  • 22. Neo4J Infrastructure API GraphDatabaseService database = new EmbeddedGraphDatabase(…); Transaction tx = database.beginTx(); try { Node mrAnderson = database.createNode(); mrAnderson.setProperty("name", "Thomas Anderson"); Node morpheus = database.createNode(); morpheus.setProperty("name", "Morpheus"); Relationship friendship = mrAnderson.createRelationshipTo( morpheus, FriendTypes.KNOWS); tx.success(); } finally { tx.finish(); } 22
  • 23. Neo4J Query API GraphDatabaseService database = new EmbeddedGraphDatabase(…); CypherParser parser = new CypherParser(); Query query = parser.parse("start person = Person(id = *) match " + "person-[:colleagues]->colleague where colleague.firstname = {name}"); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("name", "Dave"); ExecutionEngine engine = new ExecutionEngine(database); ExecutionResult result = engine.execute(query, parameters); for (EntrySet<String, Object> element : result) { // Map data onto object } 23
  • 24. Neo4J entity class Actor { private final Node node; public Actor(Node node) { … } public String getName() { return (String) node.getProperty(„name“); } … } 24
  • 25. Forest for the woods?
  • 26. JPA?
  • 27. " 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.
  • 28. " 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.
  • 29. JPA?
  • 32. " … provide a familiar and consistent Spring-based programming model while retaining store-specific features and capabilities.
  • 33. Spring Data JDBC JPA
  • 34. Spring Data JDBC JPA
  • 35. Spring Data JDBC JPA
  • 36. Spring Data JDBC JPA
  • 40. JPA entity mapping @Entity class Person { @Id @GeneratedValue(strategy=GenerationType.AUTO) private BigInteger id; private String firstname, lastname; @Column(name="email") private String emailAddress; @OneToMany private Set<Person> colleagues; } 40
  • 41. Entity mapping - MongoDB @Document class Person { @Id private BigInteger id; @Indexed private String firstname, lastname; @Field("email") private String emailAddress; @DBRef private Set<Person> colleagues; public Person(String firstname) { … } @PersistenceConstructor public Person(String firstname, String lastname) { … } … } 41
  • 42. Entity mapping - Neo4J @NodeEntity class Person { @GraphId private long id; @Indexed private String firstname, lastname; @RelatedTo(direction = Direction.INCOMING) private Set<Person> colleagues; public Person(String firstname) { … } @PersistenceConstructor public Person(String firstname, String lastname) { … } … } 42
  • 44. MongoOperations / -Template public interface MongoOperations { // Generic callback-accepting methods <T> T execute(DbCallback<T> action); <T> T execute(Class<?> entityClass, CollectionCallback<T> action); <T> T execute(String collectionName, CollectionCallback<T> action); // Higher level access methods <T> List<T> find(Query query, Class<T> entityClass); void save(Object objectToSave, String collectionName); WriteResult updateFirst(Query query, Update update, Class<?> entityClass); // Geo API <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass); } 44
  • 45. MongoTemplate usage // Setup infrastructure Mongo mongo = new Mongo(); MongoDbFactory factory = new SimpleMongoDbFactory(mongo, „foo“); MongoTemplate template = new MongoTemplate(factory); // Create and save entity Person dave = new Person("Dave", "Matthews"); dave.setEmailAddress("[email protected]"); template.save(person); // Query entity Query query = new Query(new Criteria("emailAddress") .is("[email protected]")); assertThat(template.find(query), is(dave)); 45
  • 47. Repositories - JPA <jpa:repositories base-package="com.acme.repositories" /> public interface PersonRepository extends Repository<Person, BigInteger> { // Finder for a single entity Person findByEmailAddress(String emailAddress); // Finder for multiple entities List<Person> findByLastnameLike(String lastname); // Finder with pagination Page<Person> findByFirstnameLike(String firstname, Pageable page); } 47
  • 48. Repositories - MongoDB public interface PersonRepository extends Repository<Person, BigInteger> { // Finder for a single entity Person findByEmailAddress(String emailAddress); // Finder for multiple entities List<Person> findByLastnameLike(String lastname); // Finder with pagination Page<Person> findByFirstnameLike(String firstname, Pageable page); // Geospatial queries List<Person> findByLocationNear(Point location, Distance distance); GeoResults<Person> findByLocationNear(Point location); } 48
  • 49. Repositories - MongoDB <mongo:repositories base-package="com.acme.repositories" /> @Component public class MyClient { @Autowired private PersonRepository repository; public List<Person> doSomething() { Point point = new Point(43.7, 48.8); Distance distance = new Distance(200, Metrics.KILOMETERS); return repository.findByLocationNear(point, distance); } } 49
  • 50. Repositories - Neo4J interface PersonRepository extends GraphRepository<Person, Long> // Finder for a single entity Person findByEmailAddress(String emailAddress); // Finder for multiple entities List<Person> findByLastnameLike(String lastname); // Finder with pagination Page<Person> findByFirstnameLike(String firstname, Pageable page); @Query("start person = Person(id = *) " + "match person-[:colleagues]->colleague where " + "colleague.firstname = {name}") List<Person> getPersonsWithColleaguesName( @Param("name") Movie m); } 50
  • 51. Repositories Querydsl 51
  • 52. Querydsl QPerson $ = QPerson.person; BooleanExpression left = $.lastname.contains("eth"); BooleanExpression right = $.firstname.is("Carter"); public interface QueryDslPredicateExecutor<T> { T findOne(Predicate predicate); List<T> findAll(Predicate predicate); } public interface PersonRepository extends Repository<Person, BigInteger>, QueryDslPredicateExecutor { … } List<Person> result = repository.findAll(left.or(right)); assertThat(result.size(), is(2)); assertThat(result, hasItems(dave, carter)); 52
  • 54. Wrap up Sophisticated mapping support Templates Repositories Querydsl Spring namespace Geospatial support (MongoDB) Cross-store persistence
  • 56. Resources • www.springframework.org/spring-data • github.com/SpringSource/spring-data-mongodb • github.com/SpringSource/spring-data-neo4j • http://www.se-radio.net/2010/07/episode-165-nosql-and- mongodb-with-dwight-merriman • http://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis