Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB Data Access using Spring Data and Sprin...

mongodb
February 16, 2012

MongoDB Data Access using Spring Data and Spring Roo Frameworks - Srini Penchikala, InfoQ

MongoDB Austin 2012

Spring Data provides a POJO based programming model to interact with a MongoDB DBCollection. In this session, I will give an overview of the Spring Data project and how it can be used to develop enterprise Java applications that access the data in MongoDB NoSQL Databases. I will talk about the Cross-store persistence concept and support for JPA Entities. The session will include the demonstration of a sample Java application using the Spring Data and Spring Roo frameworks to retrieve and persist data to a MongoDB database. I will also discuss the like Log4j appender, Map-Reduce integration and JMX administration and monitoring. I will conclude the talk with discussion on best practices MongoDB based application development.

mongodb

February 16, 2012
Tweet

More Decks by mongodb

Other Decks in Technology

Transcript

  1. MONGODB DATA ACCESS USING SPRING DATA, ROO AND CLOUD FOUNDRY

    FRAMEWORKS MongoDB Austin Event (#MongoDBAustin) Srini Penchikala ([email protected] / @srinip) 02.15.12
  2. GOALS AND SCOPE  Goal  How to access MongoDB

    data using Spring Data and Spring Roo frameworks  Scope  Focus on NoSQL application development framework  Other concerns like RAD, Logging, and Monitoring  Target Audience  Application Developers (Java)  Format  ~40 min presentation + 5 min Q&A  Demos  Interactive  “Spring Roo In Action” eBook to 2 winners 3
  3. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 4
  4. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 5
  5. SPRING DATA  POJO based programming model  Spring-powered applications

    to access:  non-relational databases  map-reduce frameworks  cloud based data services  Contains many subprojects that are specific to a given NoSQL database 6
  6. SPRING DATA PROJECTS Category Sub-project Document Stores MongoDB, CouchDB Graph

    Databases Neo4j Key Value Stores Redis, Riak Column Stores HBase, Cassandra Blob-Stores Blob Big Data Hadoop Data-Grid GemFire Relational Databases JPA, JDBC Extensions Common Infrastructure Commons, Grails Mapping 7 Source: http://www.springsource.org/spring-data
  7. SPRING DATA MONGODB  Provides integration with MongoDB  POJO

    centric model for interacting with MongoDB Collection  Repository style data access layer  1.0 GA release 8 Website: http://www.springsource.org/spring-data/mongodb
  8. SPRING DATA MONGO 1.0 GA FEATURES  Spring namespace 

    MongoTemplate  MongoConverter  Spring Data Repositories  Cross-store persistence  QueryDSL and GeoSpatial integration  Map-Reduce integration  MongoDB Log4j appender  JMX administration and monitoring 9 Source: http://www.springsource.org/node/3346
  9. MONGODB FACTORY 11 Java: MongoFactoryBean mongoFactory = new MongoFactoryBean(); mongoFactory.setHost("localhost");

    XML: <mongo:db-factory dbname="database"> XML w/ Options: <mongo:db-factory id="anotherMongoDbFactory" host="localhost” port="27017” dbname="database” username="joe" password="secret"/>
  10. MONGO TEMPLATE 13 Java: new Mongo("localhost"); new MongoTemplate(mongo, "mydatabase"); XML:

    <mongo:mongo host="localhost" port="27017"/> <bean id="mongoTemplate“ class="org.springframework.data. mongodb.core.MongoTemplate"> <constructor-arg ref="mongo"/> <constructor-arg name="databaseName“ value=" mydatabase "/> </bean>
  11. REQUIREMENTS 14 MongoDB 1.6.5 or later JDK 6.0 mongo-java-driver- 2.5.3.jar

    Spring 3.0.x spring-data- mongodb- 1.0.0.RELEASE.jar spring-data- commons- 1.2.0.M1.jar Third party Libraries
  12. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 15
  13. SPRING ROO  Rapid application development tool  100% development

    in Java  Technology integration  Built-in MongoDB support  Roo add-ons  Fast and simple to remove  1.2.1 is the current GA release 16 Website: http://www.springsource.org/spring-roo
  14. ROO COMMANDS // Create a new project. project com.rooinaction.cmsapp //

    Create configuration for MongoDB peristence mongo setup (or) mongo setup --cloudFoundry true // Define domain model. entity mongo --class ~.domain.Course --testAutomatically field string --fieldName name --sizeMin 2 --notNull --class ~.domain.Course // Add layer support. repository mongo --interface ~.repository.CourseRepository --entity ~.domain.Course // Deploy to the cloud cloud foundry deploy --appName rooinaction-cmsapp-demo1 --path /target/cmsapp-0.1.0.BUILD- SNAPSHOT.war --memory 512 cloud foundry create service --serviceName cmsapp-mongo --serviceType mongodb cloud foundry bind service --serviceName cmsapp-mongo --appName rooinaction-cmsapp-demo1 cloud foundry start app --appName rooinaction-cmsapp-demo1 17
  15. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 18
  16. CLOUD FOUNDRY  Platform as a Service (PaaS) offering from

    VMWare  MongoDB support  Spring Roo integration  Micro Cloud Foundry 19 Websites: http://www.cloudfoundry.org/ http://blog.springsource.org/2011/04/12/launching-cloud-foundry/
  17. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 22
  18. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 26
  19. LOG4J CONFIGURATION log4j.appender.stdout=org.springframework.data.document.mongodb.log4j. MongoLog4jAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n

    log4j.appender.stdout.host = localhost log4j.appender.stdout.port = 27017 log4j.appender.stdout.database = logs log4j.appender.stdout.collectionPattern = %X{year}%X{month} log4j.appender.stdout.applicationId = my.application log4j.appender.stdout.warnOrHigherWriteConcern = FSYNC_SAFE log4j.category.org.springframework.data.document.mongodb=DEBUG 27
  20. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 28
  21. SPRING BEAN JMX CONFIGURATION <mongo:mongo host="localhost" port="27017"/> <mongo:jmx/> <context:mbean-export/> <context:annotation-config/>

    <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean" p:port="1099" /> <bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean“ depends-on="registry“ p:objectName="connector:name=rmi" p:serviceUrl="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/ myconnector" /> 29
  22. MBEANS  AssertMetrics  BackgroundFlushingMetrics  BtreeIndexCounters  ConnectionMetrics 

    GlobalLoclMetrics  MemoryMetrics  OperationCounters  ServerInfo  MongoAdmin 30
  23. AGENDA  Spring Data MongoDB  Spring Roo  Cloud

    Foundry  Cross-Store Persistence  MongoDB Logger  JMX Monitoring  Conclusions 33
  24. CONCLUSIONS  Spring Data  POJO based model  Domain

    to data mapping  Cross-store persistence  Rapid MongoDB application:  Development with Spring Roo  Cloud deployment via Cloud Foundry 34
  25. RESOURCES  Spring Data (http://www.springsource.org/spring-data)  Spring Data – MongoDB

    (http://www.springsource.org/spring-data/mongodb)  Documentation (http://static.springsource.org/spring- data/data-document/docs/current/reference/html/)  Spring Roo In Action Book (http://www.manning.com/rimple/)  Chapter 4: Relationships, JPA and Advanced Persistence (http://www.manning.com/rimple/) 35
  26. THANK YOU  Contact Information  http://www.infoq.com/author/Srini-Penchikala  [email protected]

    @srinip  http://srinip2007.blogspot.com  Spring Roo in Action Book  eBook Winners  Questions? 36