Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MongoDB Munich 2012: Spring Data MongoDB

2,892 views

Published on

Einführung in Spring Data MongoDB auf der Konferenz MongoDB Munich 2012

Published in: Technology
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

MongoDB Munich 2012: Spring Data MongoDB

  1. 1. MongoDB Munich 2012:Einführung in Spring Data MongoDBtobias.trelle@codecentric.de / @tobiastrellecodecentric AG
  2. 2. Agenda Spring Framework Spring Data Spring Data MongoDB MongoDB-Template Object Mapping Repository Support Beispielecodecentric AG
  3. 3. Spring FrameworkWhat is Spring? Spring is the most popular application development framework for enterprise Java™. Millions of developers use Spring to create high performing, easily testable, reusable code without any lock-in.Quelle: http://www.springsource.orgcodecentric AG
  4. 4. Spring Framework Leichgewichtes Framework für Java Enterprise Anwendungen Kern: IoC-Container für Depedency Injection Läuft ohne JEE-Server Unterstützt viele Technologie-Stackscodecentric AG
  5. 5. Spring FrameworkProjekte• Spring AMQP • Spring Mobile• Spring for Android • Spring .NET• Spring Batch • Spring Roo• Spring Data • Spring Security• Spring Framework • Spring Social• Spring Gemfire • Spring Web Flow• Spring Integration • Spring Web ServicesGithub: https://github.com/SpringSourcecodecentric AG
  6. 6. Spring DataEinheitliches Programmiermodell für RDBMS und NoSQL-Datastores Spring Data CrudRepository PagingAndSortingRepository Spring Data Spring Data Spring Data Spring Data JPA MongoDB Neo4j … JpaRepository MongoRepository GraphRepository MongoTemplate Neo4jTemplate Embedded REST JPA Mongo Java Driver JDBC RDBMS MongoDB Neo4j …Quelle: http://www.infoq.com/articles/spring-data-introcodecentric AG
  7. 7. Spring Data AllgemeinTemplate Konfiguration von Ressourcen Einheitliches Exception-HandlingObject Mapping Annotationsbasiertes Mapping von Java-Objekten auf DB-Strukturen (Tabellen, Collections, Nodes) Convention over Configuration, viele sinnvolle Default MappingsRepository Support DAOs werden als Interfaces implementiert Query-Implementierungen werden über Namenskonventionen abgeleitet CRUD-Operation und Paging/Sortieren out-of-the-boxcodecentric AG
  8. 8. Spring Data MongoDBTemplate Abstraktion vom MongoDB Java Driver Konfiguration von mongod / mongos-Instanzen und Collections Verwaltung von Collections Map/Reduce-AufrufeObject Mapping Annotationen @Document, @Field, @Index etc. Klassen werden auf Collections abgebildet, Java-Objekte auf DokumenteRepository Support Schlüsselwörter werden auf Query-Operator abgebildet Geospatial Queriescodecentric AG
  9. 9. MongoDB TemplateKonfiguration <!-- Connection to MongoDB server --> <mongo:db-factory host="localhost" port="27017" dbname="test" /> <!-- MongoDB Template --> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/> </bean>Verwendung @Autowired MongoTemplate template; template.indexOps(Location.class).ensureIndex( new GeospatialIndex("position") );codecentric AG
  10. 10. MongoDB TemplateAusführliche Konfiguration der Mongo Connection:<mongo:mongo host="${mongo.host}" port="${mongo.port}"> <mongo:options connections-per-host="${mongo.connectionsPerHost}„ threads-allowed-to-block-for-connection multiplier="${mongo.threadsAllowedToBlockForConnectionMultiplier}„ connect-timeout="${mongo.connectTimeout}„ max-wait-time="${mongo.maxWaitTime}„ auto-connect-retry="${mongo.autoConnectRetry}„ socket-keep-alive="${mongo.socketKeepAlive}„ socket-timeout="${mongo.socketTimeout}„ slave-ok="${mongo.slaveOk}„ write-number="1„ write-timeout="0„ write-fsync="true"/></mongo:mongo><mongo:db-factory dbname= "test" mongo-ref="mongo"/>codecentric AG
  11. 11. MongoDB TemplateKonfiguration für Replica Set:<mongo:mongo id="replicaSetMongo" replica-set="127.0.0.1:27017,localhost:27018"/>codecentric AG
  12. 12. MongoDB Object MappingCode Beispiel: Persistenze Domainklasse „User“:@Document(collection = "usr")public class User { @Id private String id; @Indexed private String fullName; private Date lastLogin; ...}codecentric AG
  13. 13. MongoDB Repository Support Grundidee: für Definition von Queries reicht die Signatur einer Methode, die Implementierung wird zur Laufzeit daraus abgeleitet Basis-Implementierungen vorhanden für CRUD-Operationen Blättern Sortierencodecentric AG
  14. 14. MongoDB Repository SupportKonfiguration <!-- Package w/ automagic repositories --> <mongo:repositories base-package="mongodb" />Implementierung public interface UserRepository extends MongoRepository<User, String> { List<User> findByFullNameLike(String fullName, Sort sort); @Query("{ fullName: ?0 }") List<User> findByTheUsersFullName(String fullName); }codecentric AG
  15. 15. MongoDB Repository SupportVerwendung@Autowired UserRepository repo;...List<User> users;// custom finderusers = repo.findByFullNameLike("^User", null);// paging & general finderPage<User> page = repo.findAll( new PageRequest(2, 2 ) );users = page.getContent();codecentric AG
  16. 16. Alles auf einen Blickcodecentric AG
  17. 17. Live Democodecentric AG
  18. 18. Was gibt‘s sonst noch? Viele Konfigurationsmöglichkeiten @CompoundIndex – zusammengesetzte Indexe auf Klassenebene @Version – optimistisches Locking auf Anwendungsebene (neu in 1.1.0) Template für GridFS-Unterstützung (neu in 1.1.0) Geodaten-Unterstützung Map/Reducecodecentric AG
  19. 19. MongoDB User-Gruppen in Düsseldorf / Frankfurt MongoDB User-Gruppe Düsseldorf https://www.xing.com/net/mongodb-dus @MongoDUS Contact: Tobias Trelle MongoDB User-Gruppe Frankfurt/Main https://www.xing.com/net/mongodb-ffm @MongoFFM Contact: Uwe Seilercodecentric AG
  20. 20. Quellennachweise Spring Zitat: http://www.springsource.org Spring Logo: https://twitter.com/springsource Source Code Beispiele: https://github.com/ttrelle/spring-data-examples/codecentric AG
  21. 21. QUESTION?Tobias Trellecodecentric AGMerscheider Str. 142699 Solingentel +49 (0) 212.233628.47fax +49 (0) 212.233628.79mail Tobias.Trelle@codecentric.detwitter @tobiastrellewww.codecentric.deblog.codecentric.de/author/tobias-trellewww.xing.com/net/mongodb-duscodecentric AG 08.10.2012 21

×