SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Downloaden Sie, um offline zu lesen
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!
Overview
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
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?
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;
     }




36
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) { … }

         …
     }




37
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) { … }

         …
     }




38
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);
 }



40
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));




41
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);
     }




43
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);
 }




44
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);
         }
     }




45
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);
 }



46
Repositories
        Querydsl




47
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));




48
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

Weitere ähnliche Inhalte

Was ist angesagt?

#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기Arawn Park
 
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 ContextRussell Castagnaro
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDBScott Hernandez
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2Haroon Idrees
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
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. SQLMongoDB
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query OptimizationMongoDB
 
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
 
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 RavenDBOren Eini
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDMichele Capra
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applicationsjeromevdl
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query OptimizationMongoDB
 

Was ist angesagt? (20)

Green dao
Green daoGreen dao
Green dao
 
greenDAO
greenDAOgreenDAO
greenDAO
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
 
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
 
Green dao
Green daoGreen dao
Green dao
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5Simple Jdbc With Spring 2.5
Simple Jdbc With Spring 2.5
 
Ajax chap 5
Ajax chap 5Ajax chap 5
Ajax chap 5
 
Ajax chap 4
Ajax chap 4Ajax chap 4
Ajax chap 4
 
Jndi
JndiJndi
Jndi
 
Jndi (1)
Jndi (1)Jndi (1)
Jndi (1)
 
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
 
Indexing & Query Optimization
Indexing & Query OptimizationIndexing & Query Optimization
Indexing & Query Optimization
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
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
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDD
 
Softshake - Offline applications
Softshake - Offline applicationsSoftshake - Offline applications
Softshake - Offline applications
 
Indexing and Query Optimization
Indexing and Query OptimizationIndexing and Query Optimization
Indexing and Query Optimization
 

Andere mochten auch

Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Igor Anishchenko
 
The Evolution of Java Persistence
The Evolution of Java PersistenceThe Evolution of Java Persistence
The Evolution of Java PersistenceShaun Smith
 
Generic DAOs With Hades
Generic DAOs With HadesGeneric DAOs With Hades
Generic DAOs With HadesOliver Gierke
 
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 DiveBen Alex
 
Sophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & HadesSophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & HadesOliver Gierke
 
Coding & Music Passion And Profession
Coding & Music   Passion And ProfessionCoding & Music   Passion And Profession
Coding & Music Passion And ProfessionOliver 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 MongoDBOliver Gierke
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDBOliver 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
 
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 3Oliver 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 productivityOliver Gierke
 
Spring in action - Hades & Spring Roo
Spring in action - Hades & Spring RooSpring in action - Hades & Spring Roo
Spring in action - Hades & Spring RooOliver Gierke
 
Real world dependency injection - DPC10
Real world dependency injection - DPC10Real world dependency injection - DPC10
Real world dependency injection - DPC10Stephan Hochdörfer
 
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
 

Andere mochten auch (20)

Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)
 
The Evolution of Java Persistence
The Evolution of Java PersistenceThe Evolution of Java Persistence
The Evolution of Java Persistence
 
Generic DAOs With Hades
Generic DAOs With HadesGeneric DAOs With Hades
Generic DAOs With Hades
 
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
 
Sophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & HadesSophisticated JPA with Spring & Hades
Sophisticated JPA with Spring & Hades
 
Coding & Music Passion And Profession
Coding & Music   Passion And ProfessionCoding & Music   Passion And Profession
Coding & Music Passion And Profession
 
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)
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
 
Spring Data and MongoDB
Spring Data and MongoDBSpring Data and MongoDB
Spring Data and MongoDB
 
Whoops! where did my architecture go?
Whoops! where did my architecture go?Whoops! where did my architecture go?
Whoops! where did my architecture go?
 
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
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
 
Mylyn - Increasing developer productivity
Mylyn - Increasing developer productivityMylyn - Increasing developer productivity
Mylyn - Increasing developer productivity
 
Spring Data in 10 minutes
Spring Data in 10 minutesSpring Data in 10 minutes
Spring Data in 10 minutes
 
Spring in action - Hades & Spring Roo
Spring in action - Hades & Spring RooSpring in action - Hades & Spring Roo
Spring in action - Hades & Spring Roo
 
Mylyn
MylynMylyn
Mylyn
 
Real world dependency injection - DPC10
Real world dependency injection - DPC10Real world dependency injection - DPC10
Real world dependency injection - DPC10
 
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!
 
Spring integration
Spring integrationSpring integration
Spring integration
 

Ähnlich wie An introduction into Spring Data

Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennPaintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennJavaDayUA
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring DataEric Bottard
 
NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020Thodoris 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 MongoDBMongoDB
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDBJames Williams
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012Timo Westkämper
 
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
 
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 JavaMongoDB
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Groupkchodorow
 
Real-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL Databases Real-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL Databases MongoDB
 
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 SpaceMaarten Balliauw
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Svetlin Nakov
 
Mongo sf easy java persistence
Mongo sf   easy java persistenceMongo sf   easy java persistence
Mongo sf easy java persistenceScott Hernandez
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaScott Hernandez
 
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
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB AppHenrik Ingo
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDbsliimohara
 
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 EclipseHeiko Behrens
 
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
 

Ähnlich wie An introduction into Spring Data (20)

Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp KrennPaintfree Object-Document Mapping for MongoDB by Philipp Krenn
Paintfree Object-Document Mapping for MongoDB by Philipp Krenn
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020NoSQL Endgame Percona Live Online 2020
NoSQL Endgame Percona Live Online 2020
 
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
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
 
Querydsl fin jug - june 2012
Querydsl   fin jug - june 2012Querydsl   fin jug - june 2012
Querydsl fin jug - june 2012
 
Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS
 
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
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
Real-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL Databases Real-Time Integration Between MongoDB and SQL Databases
Real-Time Integration Between MongoDB and SQL Databases
 
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
 
Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015Entity Framework: Nakov @ BFU Hackhaton 2015
Entity Framework: Nakov @ BFU Hackhaton 2015
 
Mongo sf easy java persistence
Mongo sf   easy java persistenceMongo sf   easy java persistence
Mongo sf easy java persistence
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
Spring data
Spring dataSpring data
Spring data
 
jQuery Datatables With MongDb
jQuery Datatables With MongDbjQuery Datatables With MongDb
jQuery Datatables With MongDb
 
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
 
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
 

Kürzlich hochgeladen

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 

Kürzlich hochgeladen (20)

Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 

An introduction into 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
  • 17.
  • 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?
  • 28. " … provide a familiar and consistent Spring-based programming model while retaining store-specific features and capabilities.
  • 29. Spring Data JDBC JPA
  • 30. Spring Data JDBC JPA
  • 31. Spring Data JDBC JPA
  • 32. Spring Data JDBC JPA
  • 36. 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; } 36
  • 37. 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) { … } … } 37
  • 38. 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) { … } … } 38
  • 40. 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); } 40
  • 41. 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)); 41
  • 43. 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); } 43
  • 44. 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); } 44
  • 45. 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); } } 45
  • 46. 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); } 46
  • 47. Repositories Querydsl 47
  • 48. 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)); 48
  • 50. Wrap up Sophisticated mapping support Templates Repositories Querydsl Spring namespace Geospatial support (MongoDB) Cross-store persistence
  • 52. 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

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. A lot of hands on ses\n
  7. \n
  8. No in-depth choice advice.\n
  9. Traditional approach to data storage\nDeveloper&amp;#x2018;s point of view\n
  10. Well known, solid\nAdmins know how to administer it\nProblems? Challenges?\nTwo main drivers: Cloud and Datastructures\n
  11. New challenges in deployment platforms\nCloudFoundry\n
  12. Consistency requirements -&gt; hard to scale -&gt; CAP\nSQLFire\n\n
  13. Transactions as consistency switch\nOrganize data differently\n
  14. Object-relational-mismatch\nInheritance, Trees (Nested Set?), Networks\n
  15. Huge variety of APIs\n
  16. \n
  17. \n
  18. \n
  19. \n
  20. Starring today&amp;#x2026; MongoDB\n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. Hard to choose\nDifferent APIs all over the place\n
  29. \n
  30. \n
  31. Umbrella projects for Data Access 2.0\n
  32. \n
  33. Variety of stores supported (or planned)\n
  34. Key/Value stores\n
  35. Document stores\n
  36. Other ones (graph)\n
  37. \n
  38. - Spring already provides support for JDBC, JPA, Hibernate etc.\n- add functionality on top of that\n- leverage well known Spring concepts\n - DI, AOP, Spring namespaces, JMX\n
  39. POJO based mapping\nAnnotation based mapping (Morphia and beyond)\n- Persistence constructor\n- (deeply nested) Generics\n- DBRef -&gt; embeds by default\n- Document -&gt; specify collections\n
  40. \n
  41. \n
  42. \n
  43. Template pattern\n- Resource management\n- Exception translation\n- simple Query API\n
  44. \n
  45. \n
  46. Eliminate boilerplate code\n\n- interface-only approach\n- finder methods\n- annotations for query tweaking\n- QueryDsl integration for type safe queries\n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. JMX support\n
  57. \n
  58. Upcoming talks:\n- JUG BB -&gt; Spring Data JPA\n
  59. \n