ZK With MongoDB Part 1 - Using MongoDB Java Driver

From Documentation
Revision as of 07:00, 12 January 2012 by Southerncrossie (talk | contribs)
DocumentationSmall Talks2012JanuaryZK With MongoDB Part 1 - Using MongoDB Java Driver
ZK With MongoDB Part 1 - Using MongoDB Java Driver

Author
Ashish Dasnurkar
Date
Jan 18, 2012
Version
ZK 5

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

Introduction

ZK is primarily an UI framework and it doesn't make any assumptions about application's persistence layer or database. Application developers are free to use any database (relational or non-relational) and any data access layer solutions that work with those databases. Typically, for relational databases developers either use plain JDBC or some sophisticated object-relational mapping library like Hibernate. In this small talk series I will show how developers can develop non-relational database driven ZK application.

I will describe a simple TODO list application that uses mongoDB which is a popular non-relational database. In this series I will show three approaches to work with mongoDB. In Part 1 I will use mongoDB Java driver APIs for TODO tasks CRUD operations which is similar to using JDBC driver for relational databases. In Part 2, I will use morphia , a lightweight type-safe library for mapping Java objects to/from mongoDB, which is similar to using Hibernate for relational databases. Finally for developers who are familiar with Spring framework, in Part 3 I will show how to leverage Spring Data mongoDB support to work with mongoDB database.

mongoDB Overview

mongoDB is a document oriented database that manages collections of BSON documents. Each BSON document is a set of fields. Each field is a key-value pair where key is a string and value can be other basic types, a BSON document or array of values. Below is a sample of tasks collection

{ "_id" : ObjectId("4e97d8b7dfa2925b0844a3c9"), "id" : "c011a1df-22ab-4607-a358-ea2f2873b51e", "name" : "Write article", "priority" : 1, "date" : ISODate("2011-10-06T16:00:00Z") }
{ "_id" : ObjectId("4e97d8e5dfa2925b0844a3ca"), "id" : "ce4a059f-1825-4410-bf95-4c30e11aca14", "name" : "Conference call", "priority" : 2, "date" : ISODate("2011-10-13T16:00:00Z") }
{ "_id" : ObjectId("4e97d8f0dfa2925b0844a3cb"), "id" : "0b0db7ac-b5db-40a6-9c8e-2c86581a3e89", "name" : "Release 5", "priority" : 1, "date" : ISODate("2011-10-27T16:00:00Z")}

In this example, each Task document has 5 fields. _id is auto-generated by mongoDB whenever a document is added to the collection. Remaining four fields - id,name,prority and date contains Task data. Note that mongoDB is schema free so you do not have to pre-define this Task document structure. It will be automatically created when first Task document is saved in the database. For this article all you need is an installed instance of mongoDB. You can follow mongoDB quick-start guide to setup and get the mongoDB running.

TODO application Overview