Wednesday, April 16, 2014

MongoDB NoSQL Database/Document Database

Introduction:

MongoDB is open source document database and its NoSQL database. MongoDB implemented in C++.

Now a day’s NoSQL database become popular in the market.

We have two types of Databases
  1. SQL database
  2. NoSQL Database

SQL database

We already know about SQL databases in the market these are RDMS databases. We have many popular RDMS databases in the market such as Oracel, MySQL, DB2, PostgreSQL and SQL Server. RDMS databases are managed the data by using Tables. We store the data in tables.

To communicate with these RDMS databases we have common language called SQL. We will use SQL to access and insert data into tables. We have different relations and its mappings between tables to simplify the complex data storage.

Each database vendor have to provide different clients to connect to different applications and which are developed by different languages. Database vendor is responsible to provide language depended database drivers to connect to other applications with database.

We are talking here about java technology so all database vendors have to provide the java JDBC Driver library with these libraries we can connect to RDBMS databases.

NoSQL Database

NoSQL is one of the concepts to access database without any specific database dependent queries instead of that we will use simple programming based object accessing over the databases.

A NoSQL database provides a mechanism for storage and retrieval of data that employs less constrained consistency models than traditional relational databases. Motivations for this approach include simplicity of design, horizontal scaling and finer control over availability

We have many flavors in NoSQL databases

The following are some of the important types

Document databases

Document databases pair each key with a complex data structure known as a document. Documents can contain many different key-value pairs, or key-array pairs, or even nested documents.

Graph stores

Graph stores are used to store information about networks, such as social connections. Graph stores include Neo4J and HyperGraphDB.

Key-value stores

Key-value stores are the simplest NoSQL databases. Every single item in the database is stored as an attribute name (or "key"), together with its value. Examples of key-value stores are Riak and Voldemort. Some key-value stores, such as Redis, allow each value to have a type, such as "integer", which adds functionality.

Wide-column stores

Wide-column stores such as Cassandra and HBase are optimized for queries over large datasets, and store columns of data together, instead of rows.

More Information



MongoDB

MongoDB is one of the NoSQL database and it is document database.


Working with MongoDB

MongoDB database we can install in any Operating System and we can connect to database server and manage the data.

Install and Using MongoDB

The following are steps
  1. Download MongoDB Database
  2. Create MongoDB data Store Directory
  3. Create MongoDB log file
  4. Create MongoDB configuration file
  5. Start MongoDB server
  6. Connect and use MongoDB

Download MongoDB Database

MongoDB server available for all major operating system bases on our operating system we need to download MongoDB database server

The following is MongoDB server Download location


Windows 7


We have installation files and binary distribution, we can use any thing.

Note:

In this article we will install and using MongoDB for Windows 7 and 64 bit OS
Once we download the MongoDB binary distribution ZIP file we will place any one of the directory and need to extract the zip file.

Once you extract we can see bin directory there we can see many .exe file to perform different actions.

Assume we have extracted MongoDB Zip file in D:\MongoDB

The following is screen to show bin directory and exe files of MongoDB



Create MongoDB data Store Directory

We need create one directory there MongoDB will store data.

Assume we have created data directory in D:\MongoDB\data\db

Create MongoDB log file

We also need to create log file for MongoDB to store log information. We need create mongo.log file in any of the directory

Assume we have created mongo.log in D:\MongoDB\log directory.

Create MongoDB configuration file

MongoDB need one configuration file when server starts so we need to create mongo.config file in any location in your machine.
In the configuration file we need to mention data storage path for MongoDB and need to specify the log file location.

We already created data store directory and log file in previous steps.

Create mongo.config file and add following configuration in the file


##store data here
dbpath= D:\MongoDB\data\db

##all output go here
logpath=D:\MongoDB\log\mongo.log

##log read and write operations
diaglog=3


The following is sample mongo.config fine one of the directory




The following is screen shot which show required directories for MongoDB server



Important Direcory and files paths as for above assumptions


MongoDB Server Path

D:\MongoDB\mongodb-win32-x86_64-2008plus-2.6.0

MongoDB Server Bin directory Path

D:\MongoDB\mongodb-win32-x86_64-2008plus-2.6.0\bin

MongoDB data store path

D:\MongoDB\data\db

MongoDB configuration file path

D:\MongoDB\config\mongo.config

MongoDB log file path

D:\MongoDB\log\mongo.log



Start MongoDB server

We have done all the steps and now we will start the MongoDB server

The flowing is command to start server


mongod --config d:\MongoDB\config\mongo.config --dbpath D:\MongoDB\data\db


--config  is MongoDB configuration path

--dbpath  is data store path for MongoDB


Now open windows command prompt and go to MongoDB server bin directory (D:\MongoDB\mongodb-win32-x86_64-2008plus-2.6.0\bin) then run above command in command prompt.

The following screen shot to start MongoDB server




Connect and use MongoDB

Now we already started MongoDB server now we will connect to server.

Following command to connect to MongoDB server


Mongo


Now open another command prompt and go to bin directory of MongoDB server then enter above command now you can see MongoDB shell to interact with server

The following is screen to show connecting to MongoDB server


Note:

When we connect to server it will show connecting to test database.

Interacting with MongoDB server

The following are important commands to interact with MongoDB


show dbs                   : List all databases.
use db_name            : Switches to the database.
show collections    : List all tables in the current selected database.


The following screen to show databases in MongoDB server



Switch to other database



Note:

When we switch to database if database already existed it will switch to that database if not then it will be create new database with that name.

So MongoDB wont throws error even database not existed simply it will create same thing we can apply for table.

Display All Tables for Selected Database


Create Table and Store Data

In MongoDB when we store data, if the table not existed then it will create and insert data.
If available then it will store in existed table that we specifies.

The following is command insert data in table


db.users.insert({username:"meera",gender:"male"})

or

db.users.save({username:"meera",gender:"male"})



We will use key value pair to represent Colum and its value
In the above users is table and username and gender its columns and values meera , male respectively.

The following screen to insert data in user table



Update Record
db.users.update ({username:"meeraprince",gender:"male"})

List all records from table “users”
db.users.find()

Find records where username is “meera”
db.users.find({username:"meera"})

Find records where username’s length is less than or equal to 4
db.users.find({$where:"this.username.length<=4"})

Delete Record
db.users.remove({username:"meera"})


Reference Links




Author

Monday, April 14, 2014

Liferay Plugin Portlet Development Choices

Introduction:

Liferay is very good portal technology and its completely open source. Liferay have very good support to run other framework applications in portal with the help of little work.

Liferay already have inbuilt portlet framework to develop portlets and some are available for Plugin portlet development and some are not available for Plugin portlet environment.

In liferay we have two choices to create portlet one is  Plugin Portlet environment and other one is Plugins Ext.

We never use EXT for create new portlet and we use only Plugin portlet environment to create new portlet.

Liferay have few inbuilt portlet frameworks to create portlet and run into liferay portal.

The following are the Portlet frameworks which are inbuilt for Liferay Portal.
  1. Generic Portlet
  2. Liferay MVC Portlet
  3. Liferay Struts Portlet

Generic Portlet

This is very basic portlet and comes with javax.Portlet API. This is very default portlet in any portal and all portals have support to run Generic Portlet because Generic Portlet follows JSR Standards. We will implement javax.Portlet Interface for Generic Portlet.

 Liferay IDE have direct support to create Generic Portlet and we can deploy into Liferay Portal. We can use Generic Portlet in Plugin Portlet Development.

Liferay MVC Portlet

 It is inbuilt Liferay frame work and it is very simple to develop and use. Liferay IDE has support to create this portlet skeleton and we can deploy into liferay portal.

This is very easy to create and deploy into liferay portal apart form that we will use JSP for view technology and Liferay Service Builder for Service layer.

Liferay Struts Portlet

We cannot create this portlet in Plugin Portlet Environment we can create using EXT only but it’s not recommended. Liferay Struts Frame work  built it on top of Struts 1.x framework. All liferay portal portlet was developed in Liferay Struts Framework

Out of Box Portlets:

Liferay also support for other web application frame works and those will work in liferay portal. We have many popular frame works in web applications development and we can also use those frame works to create liferay Plugin portlets.

But these frame work won’t work directly in portals because general web application frame work flow is different from portlet flow.

Web application framework use servlets and servlet container to make the components and run the components. So here servlet life cycle is different from portlet lifecycle

To use other web application frame works such as struts, spring, jsf and vaadin in portals, the frame work vendor is responsible for create some bridges which will make web application frame work run in portals or which can run in portlet container.

These bridges are responsible to convert web application flow into portlet flow i.e. servlet lifecycle will be converted into portlet life cycle.

Example:
  • Struts have given Struts Bridges
  • Spring have Spring Portlet MVC library
  • JSF has JSF bridges.

The following is screen shot i.e. what kind of frame works supported by liferay portal


The following are popular frame portlets which supported by Liferay Portal.
  1. Struts 2.x Portlet
  2. Spring Portlet MVC Portlet
  3. JSF 2.x Portlet
  4. Vaadin Portlet
  5. PHP Portlet
  6. Perl and Groovy Portlet

Struts 2.x Portlet:

Struts 2.x portlet will use strut frame work and development is similar to normal struts web application development but we need to add some other configuration files such  as portlet.xml, liferay-portlet.xml and need to add frame work supported portal bridges.

View Technology:
  • We will use JSP for view technology.
  • JSP,JSTL, Struts Tag Library additional benefit to make RIA development and Struts already proven in the market as best web application framework. Struts will use tiles concept to aggregate page and we can also use free marker templates.

Strengths:
  • Struts frame work have very good front end controller to navigate and render views.
  • Rich Built in Struts Tags.

Limitations:
  • Struts have support and full fill only JSR 168 feature and not all JSR 286 standards (You can explore more on this).
  • Liferay have not direct support for struts 2.0. If any environmental problems then our self need to solve or need to approach struts fame work community.
  • Liferay IDE has not direct support to create Struts 2.x portlet we need to manually add configuration files and Libraries.

When it recommends?

If anybody who good at struts frame work and vast experience then we can choose this one.

Development Options:
  1. Struts 2.0+Liferay Service Builder+ JSP (Tiles,JSTL, Struts Tags)
  2. Strust 2.0+ Spring+Hibernate+ JSP (Tiles,JSTL, Struts Tags)

Reference Links:



Note:

Entire Liferay Portal Portlet has built it upon struts 1.x frame work and they have designed Liferay Struts Frame Work on top struts 1.x.

Unfortunately Liferay Struts Frame Work was not available to Plugin Portlet Environment.

Spring Portlet MVC Portlet

Spring Portlet MVC Portlet is another choice in liferay and its very good framework. Spring Portlet MVC Portlet API is a Portlet Bridge to make spring works in Portals and it also follows JSR standards.

Strengths:
  • It very good frame work and Very big Community for spring so definitely we have good support.
  • If we choose spring we have rich flexibility use other technologies because spring frame work already has many Plugins for integration.
  • We can use JSP, JSTL and Spring Tags for UI development.
  • We can use JQuery or Legacy JS for Java Script.
  • We can also use Struts 2.x or JSF 2.x as front Controller

Limitations:
  • It’s Also full filled JSR 168 stands still it need to full fill JSR 286 standards.
  • Liferay with spring have some environmental integration issues especially in Context loading problems. Liferay already used spring and hibernate for Service Layer.
  • Spring Portlet MVC with Liferay Service Builder has some context loading issues.
  • We can go with Spring DAO Implementation with Hibernate but we are missing sharing of services between portlets. So we need to handle differently when we want share portlet services with other portlet.
  • No Direct Liferay Community support but spring community and liferay forum people can support well.
  • Liferay IDE not have support to create Spring Portlet we need create simple MVC portlet and need to add configuration files and libraries manually.

Reference Links:



JSF 2.x Portlet:

JSF is also very popular frame work in web application development and its from Java Community.

JSF 2.x have very good new features and they have used XHTML as view technology it very good choice rather than JSP.

JSF 2.x frame work has very good component libraries for Rich Internet Application development.

We have very popular JSF component libraries such as Prime Faces, Rich Faces and ICE Faces.

JSF 2.x Specification has two different implementations JSF Mojarra and Apache Myfaces.

JSF Mojarra have jsf-api.jar and jsf-impl.jar is two libraries which implemented JSF frame work.

If we use JSF Mojarra we can use Prime faces, Rich Faces and ICE Faces as component libraries.

Apache Myfaces already have their own component libraries such as Trinidad, Tobago and Tomahawk.

We already know to make it work other frame works in liferay portal we need frame work support bridges so that we can use in portlet development.

Liferay have started special community to support JSF framework to run in liferay portals. The project name is Liferay Faces.

Before we have JSF portlet faces have separate community and they started to implemented libraries so that it was used to run JSF frame work in Liferay. Now Liferay Faces is part of Liferay now have rich support for JSF in Liferay.

Liferay Faces have chosen JSF Mojarra implementation, based on this they have implemented JSF portlet bridges that will make JSF works in Liferay Portal. Once we use JSF bridges we can develop portlet and run in liferay portal.

We can use any component libraries which will support by JSF frame work in JSF portlet development such as Prime Faces, ICE faces and Rich Faces. Apart from this Liferay Also stared develop their own component library i.e. Liferay Faces Alloy.

Alloy Faces is JSF component library which  used to Liferay JSF Portlet development as UI complements for RIA (Rich Internet Application) development.

It used Alloy UI Java Script to implement and we already know Alloy UI is one of the projects from Liferay and Entire Liferay Portal have used AUI java script.

So Liferay started developing JSF components with help of AUI i.e. Liferay Faces Alloy.

Liferay Faces have given 3 Libraries As Follows
  1. Liferay Bridge Faces
  2. Liferay Faces Portal
  3. Liferay Faces Alloy

Liferay Faces Bridge

Liferay Faces Bridge is core library which will make JSF work in Liferay Portal and its responsible for convert JSF life cycle into portlet lifecycle and it based on JSF Mojarra implementation.

Liferay Faces Portal

Liferay Portal Faces is library responsible for to use Liferay Portal API in JSF portlet development and have set of classes and interface which interact with Liferay Portal API.

Liferay Faces Alloy

Liferay Faces Alloy is Liferay component Library for JSF portlet development and it has many UI components for rapid application development.

Strengths:
  • Its part Liferay Project so more support when we start JSF portlet development.
  • JSF frame work has many choices for UI component libraries so we can develop portlet applications very fast.
  • JSF have Prime faces, Rich Faces and ICE faces these are very popular component libraries apart from these liferay also have Alloy Faces for JSF portlet development as UI components.
  • JSF Portlet uses XHTML as view technology so it is one of the good advantages.
  • Liferay Faces is already part of Liferay so defiantly they will improve a lot in future and also have very good support.
  • Liferay IDE has direct support to create JSF portlets and deploy into liferay portal.

Limitations:
  • Still its growing project so we may get few challenges.
  • Liferay Faces Alloy still it’s improving and has limited UI components when we compare with other component libraries such as Prime Faces, Rich Faces and ICE Faces.

Development Options:

Liferay Faces = (Liferay Faces Bridge + Liferay Faces Portal + Liferay Faces Alloy)

Any JSF Component Library = (ICE Faces/ Prime Faces/ Rich Faces/ Liferay Faces Alloy)


  1. Liferay Faces + ICE Faces
  2. Liferay Faces+ Prime Faces
  3. Liferay Faces+ Rich Faces
  4. Liferay Faces+ Liferay Faces Alloy
  5. Liferay Faces + (Any JSF Component Library) + Liferay Service Builder
  6. Liferay Faces + (Any JSF Component Library) + Spring DAO Implementation with Hibernate.

Reference Links



My Suggestion and Opinion Choosing Plugin Portlet for Development
  1. Liferay Portlet MVC Portlet with Liferay Service Builder
  2. Liferay JSF Portlet using Liferay Faces+ Liferay Faces Alloy
  3. Spring Portlet MVC with Spring DAO Implementation with Hibernate
  4. Struts 2.x Portlet with Liferay Service Builder

Note:

It’s my rank and it may be differed from other opinions.
Apart from above we have options like vaadin, php , perl, python and groovy portlet.

Author

Recent Posts

Recent Posts Widget

Popular Posts