How to Use NoSQLin Enterprise Java ApplicationsPatrick BaumgartnerNoSQL Roadshow | Basel | 30.08.2012
Agenda•   Speaker Profile•   New Demands on Data Access•   New Types of Data Stores•   Integrating NoSQL Data Stores•   Sp...
Speaker ProfilePatrick Baumgartner•   Senior Software Consultant | Partner•   VMware/SpringSource Certified Instructor (Sp...
New Demands on Data Access                  • Structured and                    unstructured data                  • Massi...
New Types of Data Stores                           5
Integrating NoSQL Data Stores #1We are not architects!                            http://www.flickr.com/photos/sakeeb/4087...
Integrating NoSQL Data Stores #2Don’t re-invent the wheel!                             http://www.flickr.com/photos/dmott9...
Integrating NoSQL Data Stores #3Let’s use Spring!                              http://www.springsource.org/spring-data    ...
Spring Data• Same goals as the Spring Framework   – Productivity improvement   – Programming model consistency   – Portabi...
Spring Data – Overview #1  Relational Databases  • JPA  • JDBC Extensions  Big Data  • Apache Hadoop  Data Grid  • GemFire...
Spring Data – Overview #2  Key Value Stores  • Redis  Document Stores  • Mongo DB  Graph Databases  • Neo4J  Column Stores...
Spring Data – Key Features• Low level data access API abstraction   – MongoTemplate, RiakTemplate, Neo4jTemplate   – Excep...
Spring Data MongoDB – Example                                13
Documents            Stored JSON:            { "_id" : ObjectId("4f9886290364b533b3acd4ce"),              "_class" : "com....
Spring Data MongoDB – Document@Documentpublic class Person {  @Id                         Stored JSON:  private int id;   ...
Spring Data MongoDB – Configuration                                      16
Spring Data MongoDB – Repository@Repositorypublic class MongoPersonRepository implements BaseRepository<Person> {    @Auto...
Spring Data Neo4j – Example                              18
Graph        19
Spring Data Neo4j (SDN)•   POJOs mapped as nodes or relationships – type safe•   Works directly Database, typically embedd...
Spring Data Neo4j – Entity@NodeEntity                                 Nodepublic class Person {  private String name;  pri...
Spring Data Neo4j – NodeEntity@NodeEntitypublic class Person {  private String name;  private int yearOfBirth;  @RelatedTo...
Spring Data Neo4j – Relationship@RelationshipEntitypublic class Knows {  private int sinceYear;  public Knows since(int ye...
Spring Data Neo4j – Repositorypublic interface PersonRepository extendsGraphRepository<Person> {    @Query("start person =...
Spring Data Neo4j – Querying• Several possibilities implemented to query the graph   – Neo4j API   – Traversal description...
Give it a try!Use a data model which really matches to your data …                                           http://www.fl...
05.09.2012 /ch/open Workshop-TageNoSQL für Java Enterprise Anwendungen mit Spring Data                                    ...
Q&APatrick Baumgartnerpatrick.baumgartner [at] swiftmind [dot] comhttp://www.swiftmind.com http://www.twitter.com/patbaumg...
Upcoming SlideShare
Loading in...5
×

How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel

566

Published on

Once you begin developing with NoSQL technologies you will quickly realize that accessing data stores or services often requires in-depth knowledge of proprietary APIs that are typically not designed for use in enterprise Java applications. Sooner or later you might find yourself wanting to write an abstraction layer to encapsulate those APIs and simplify your application code. Luckily such an abstraction layer already exits: Spring Data.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
566
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Spring Data repositories can be composed with interfacesThe implementation is magically provided by Spring Data
  • How to use NoSQL in Enterprise Java Applications - NoSQL Roadshow Basel

    1. 1. How to Use NoSQLin Enterprise Java ApplicationsPatrick BaumgartnerNoSQL Roadshow | Basel | 30.08.2012
    2. 2. Agenda• Speaker Profile• New Demands on Data Access• New Types of Data Stores• Integrating NoSQL Data Stores• Spring Data Overview• Example with MongoDB• Example with Neo4j• Q&A 2
    3. 3. Speaker ProfilePatrick Baumgartner• Senior Software Consultant | Partner• VMware/SpringSource Certified Instructor (Spring Trainer)• Spring Framework, OSGi & agile engineering practices• Co-author of „OSGi für Praktiker“ (Hanser)Swiftmind GmbH http://www.swiftmind.com• Enterprise Java, Spring & OSGi consulting• Spring & OSGi workshops & trainings• Agile engineering practices workshops 3
    4. 4. New Demands on Data Access • Structured and unstructured data • Massive amounts of data • Inexpensive horizontal scaling • Apps and data in the cloud • Social network features • … 4
    5. 5. New Types of Data Stores 5
    6. 6. Integrating NoSQL Data Stores #1We are not architects! http://www.flickr.com/photos/sakeeb/4087246274 6
    7. 7. Integrating NoSQL Data Stores #2Don’t re-invent the wheel! http://www.flickr.com/photos/dmott9/5921728819 7
    8. 8. Integrating NoSQL Data Stores #3Let’s use Spring! http://www.springsource.org/spring-data 8
    9. 9. Spring Data• Same goals as the Spring Framework – Productivity improvement – Programming model consistency – Portability• Umbrella for subprojects, specific to a given database• Mapping support for Java domain objects• http://www.springsource.org/spring-data• http://github.com/SpringSource/spring-data-XXX 9
    10. 10. Spring Data – Overview #1 Relational Databases • JPA • JDBC Extensions Big Data • Apache Hadoop Data Grid • GemFire HTTP • REST 10
    11. 11. Spring Data – Overview #2 Key Value Stores • Redis Document Stores • Mongo DB Graph Databases • Neo4J Column Stores • HBase Common Infrastructure • Commons 11
    12. 12. Spring Data – Key Features• Low level data access API abstraction – MongoTemplate, RiakTemplate, Neo4jTemplate – Exception translation – Transaction management• Object Mapping (Java to data store)• Generic Repository Support – Basic CRUD, dynamic finders, pagination and sorting• Spring namespaces• Cross Store Persistence Programming Model – @Entity, @Document, @NodeEntity 12
    13. 13. Spring Data MongoDB – Example 13
    14. 14. Documents Stored JSON: { "_id" : ObjectId("4f9886290364b533b3acd4ce"), "_class" : "com.acme.hello.domain.Person", "name" : "Bob", "age" : 33 } 14
    15. 15. Spring Data MongoDB – Document@Documentpublic class Person { @Id Stored JSON: private int id; { "_id" : ObjectId("4f9886290364b533b3acd4ce"), "_class" : "com.example.Person", private String name; "name" : "Bob", private int age; "age" : 33 } // getters/setters…} 15
    16. 16. Spring Data MongoDB – Configuration 16
    17. 17. Spring Data MongoDB – Repository@Repositorypublic class MongoPersonRepository implements BaseRepository<Person> { @Autowired MongoOperations mongoTemplate; Person createPerson(String name, int age){ if(!mongoTemplate.collectionExists(Person.class)){ mongoTemplate.createCollection(Person.class); } Person p = new Person(name, age); mongoTemplate.insert(p) return p; } ...} 17
    18. 18. Spring Data Neo4j – Example 18
    19. 19. Graph 19
    20. 20. Spring Data Neo4j (SDN)• POJOs mapped as nodes or relationships – type safe• Works directly Database, typically embedded mode• Data is fetched very fast and lazy• Stores everything within a @Transaction• Uses heavily AspectJ magic to enhance the POJOs• … 20
    21. 21. Spring Data Neo4j – Entity@NodeEntity Nodepublic class Person { private String name; private int age; _type_: com.example.Person name: "Alice" // getters/setters… age: 42}Person alice = new Person();alice.setName("Alice");alice.setAge(42);alice.persist(); 21
    22. 22. Spring Data Neo4j – NodeEntity@NodeEntitypublic class Person { private String name; private int yearOfBirth; @RelatedTo(type = "KNOWS", direction = Direction.OUTGOING) private Set<Person> knownPersons; public void knows(Person p) { knownPersons.add(p); } public Set<Person> getFriends() { KNOWS return knownPersons; Alice Bob }}Person alice = ...;alice.knows(bob);alice.knows(carol); KNOWS Carol 22
    23. 23. Spring Data Neo4j – Relationship@RelationshipEntitypublic class Knows { private int sinceYear; public Knows since(int year) { this.sinceYear = year; return this; }}@NodeEntitypublic class Person { public Known knows(Person p) { return this.relateTo(p, Knows.class, "KNOWS"); }}Person alice = ...;Person bob ...; KNOWSalice.knows(bob).since(2012); Alice Bob since: 2012 23
    24. 24. Spring Data Neo4j – Repositorypublic interface PersonRepository extendsGraphRepository<Person> { @Query("start person = {0} match ... return ...") Iterable<Product> getOwnedServices(Person person); Iterable<Person> findByName(String name); Iterable<Person> findByNameLike(String name);}@AutowiredPersonRepository personRepository;Person alice = personRepository.findByName("Alice"); 24
    25. 25. Spring Data Neo4j – Querying• Several possibilities implemented to query the graph – Neo4j API – Traversal descriptions – Graph algorithms – Index queries – Cypher queries 25
    26. 26. Give it a try!Use a data model which really matches to your data … http://www.flickr.com/photos/juniorvelo/3267647833 26
    27. 27. 05.09.2012 /ch/open Workshop-TageNoSQL für Java Enterprise Anwendungen mit Spring Data 4th – 6th September http://www.flickr.com/photos/4nitsirk/5211251578 27
    28. 28. Q&APatrick Baumgartnerpatrick.baumgartner [at] swiftmind [dot] comhttp://www.swiftmind.com http://www.twitter.com/patbaumgartner 28
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×