Developing Java EE 6 MongoDB Applications
By Shekhar Gulati Promo Code J!DC"#$%#
A&out Me ' Shekhar Gulati
OpenShift Evangelist at Red Hat Hands on developer Speaker Writer and Blogger Twitter Handle : shekhargulati
Agenda
NoSQ E!os"ste# Hi$ernate O%& &ongo'B in (!tion 'e#o
) 'eveloping Todo (ppli!ation ) 'eplo"ing to OpenShift
(here are so many choices $$ http)**nos+l,data&ase$org* list -./0 #oS12 data stores
http:**www+#arketresear!h#edia+!o#*,p-./0
3arious #oS12 DBs Jo& (rends
Jo& (rends 4ith MyS12
5hy #oS126
Read S!ala$ilit" Write S!ala$ilit" Tries to solve a parti!ular pro$le# ) are not one si1e fit all S!he#a less Write !onfigura$ilit"
3isual Guide to #oS12
7i&ernate "GM
5hat is 7i&ernate "GM6
2ersisten!e engine providing 32( support for NoSQ datastores+ Reuses #ature pro4e!ts like hi$ernate !ore5 hi$ernate sear!h 6eeps good part of relational #odel Still evolving
7i&ernate "GM Goals
Si#plif" progra##ati! #odel for NoSQ 2rovide full 32( support Help s!ale e7isting appli!ations with a NoSQ front end to a traditional data$ase 2rovide fa#iliar environ#ent to developers whi!h leads to produ!tivit"
Note : 8urrentl" does not #eet all the goals
"GM Current Status
Store data in ke"*value stores 9nfinispan:s datagrid and Eh!a!he Store data in &ongo'B 8reate5 Read5 ;pdate and 'elete operations <8R;'= for entities 2ol"#orphi! entities <support for super!lasses5 su$!lasses et!=+ E#$edda$le o$4e!ts <aka !o#ponents= Support for $asi! t"pes <nu#$ers5 String5 ;R 5 'ate5 enu#s5 et!= Support for asso!iations Support for !olle!tions <Set5 ist5 &ap5 et!= Support for Hi$ernate Sear!h:s full>te7t ?ueries 32( and native Hi$ernate OR& (29 support
&ongo'B in (!tion
5hat is MongoDB6
'o!u#ent $ased NoSQ data$ase
) Ea!h do!u#ent !an $e heterogeneous5 and #a" have !o#pletel" different stru!ture !o#pared to other do!u#ents
Stores data in BSON<Binar" 3SON= @ast S#art S!ala$le
MongoDB (erminology
'ata$ase Ta$le Row 9nde7 A A A A 'ata$ase 8olle!tion 'o!u#ent 9nde7
Getting started 4ith MongoDB
$ wget
http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.2.2.tgz
$ tar -xf mongodb-osx-x86_64-2.2.2.tgz $ mkdir -p /data/db might fa!e permission iss"es# $ mongodb-osx-x86_64-2.2.2/bin/mongod
8unning some commands
show d$s use de#o show !olle!tions d$+todos+help<= d$+todos+insert<Btodo:Clearn openshiftC5!reatedOn : new 'ate<=5tags:DEopenshiftC5C!loudC5CpaasCFG= d$+todos+findOne<=
B HIidH : O$4e!t9d<H.Jf.00KLMKJNf0d0!0K$L!MMH=5 HtodoH : H earning OpenShiftH5 H!reatedOnH : 9SO'ate<HLJKO>JK>K.TK/:NM:KN+K/OPH=5 HtagsH : DHopenshiftH5H!loudH5HpaasHF G
MongoDB Dynamic 1ueries
d$+todos+find<BHtodoH:H earning OpenShiftHG= d$+todos+find<BHtodoH:*openshift*i5HtagsH:HpaasHG= d$+todos+find<Btodo : BQrege7 : *openshift*iGG= d$+todos+find<Btags:BQin : DH!loudH5H4avaHFGG= d$+todos+find<Btags:BQnin : DH!loudH5H4avaHFGG= d$+todos+find<Btags:BQall : DH!loudH5H4avaHFGG= ot of other operators availa$le http:**do!s+#ongod$+org*#anual*referen!e*operator*
MongoDB !pdate 1uery
d$+todos+update<Btodo : H earning OpenShiftHG5BQpush : Btags : H4avaHGG5true=
'e#o : Building Todo (ppli!ation
Getting Started 4ith "penShi9t
https:**openshift+redhat+!o#*app*a!!ount*new
Sign up with 2ro#o 8ode J!DC"#$%#
Creating JBossAS: MongoDB "penShi9t Application using Eclipse K= 'ownload E!lipse L= 9nstall 3Boss Tools 2lugin
Setting up "GM template pro;ect
Q git re#ote add te#plate ># #aster git:**githu$+!o#*shekhargulati*hi$ernate>og#>openshift> te#plate+git Q git pull >s re!ursive >R theirs te#plate #aster
Demo Steps
8reate do#ain #odel 8reate E3B servi!e &ake servi!e REST@ul $" S2ath &ake we$ servi!e !alls
(sso!iation &anage#ent hi$ernate+og#+#ongod$+asso!iations+store % OB( I8O E8T9ON T 9NIENT9TU T 8O E8T9ON
'eplo"ing to OpenShift &aking !hanges in persisten!e+7#l Q git push
Thanks Sour!e !ode is on githu$ https:**githu$+!o#*shekhargulati*todo>og#> rest Sign up 9or an "penShi9t Account
Promo Code
J!DC"#$%#