JDO vs Value Object
JDO yog Java persistence thev naus laus zis uas tuaj yeem siv los khaws POJO (Plain Old Java Objects) rau hauv cov ntaub ntawv yam tsis tas yuav nkag siab txog qhov kev siv ntawm cov khw muag khoom sib txawv. Tus Nqi Khoom (tseem hu ua Cov Ntaub Ntawv Hloov Khoom) yog tus qauv tsim qauv tsim qauv uas qhia txog lub tswv yim ntawm cov ntaub ntawv yooj yim rau lub hom phiaj ntawm kev hloov cov ntaub ntawv ntawm ntau txheej thiab tiers.
JDO yog dab tsi?
JDO (Java Data Objects) muab ib lub tswv yim los xa cov persistence rau Java cov khoom thiab nkag mus rau hauv database. JDO yog pob tshab heev vim nws tso cai rau Java daim ntawv thov cov neeg tsim khoom nkag mus rau cov ntaub ntawv hauv qab yam tsis tas yuav sau cov lej tshwj xeeb rau cov ntaub ntawv. JDO tuaj yeem siv thoob plaws ntau qib nrog rau Java Standard Edition, Web-tier thiab daim ntawv thov servers. JDO API yog ib qho kev xaiv rau lwm qhov kev pheej hmoo (khaws cov khoom tom qab rho tawm ntawm qhov kev pab cuam) ntawm Java cov khoom xws li Serialization, JDBC (Java DataBase Connectivity) thiab EJB CMP (Enterprise JavaBeans architecture Container Managed Persistence). JDO siv XML thiab txhim kho bytecode. Qhov txiaj ntsig tseem ceeb ntawm kev siv JDO API yog tias lawv tuaj yeem khaws cov ntaub ntawv yam tsis tas yuav tsum tau kawm cov lus nug tshiab xws li SQL (uas nyob ntawm hom kev khaws ntaub ntawv). JDO yog qhov yooj yim heev rau siv vim tias cov neeg tsim khoom tuaj yeem tsom mus rau lawv cov qauv khoom lag luam. Tsis tsuas yog qhov no, JDO optimizes code los ntawm nws tus kheej raws li cov ntaub ntawv nkag. Vim tias JDO API tsis nruj rau hom ntawm cov ntaub ntawv khaws cia, tib lub interface tuaj yeem siv los ntawm java daim ntawv thov tsim los khaws cov khoom java rau txhua qhov chaw khaws ntaub ntawv suav nrog kev sib raug zoo database, khoom database lossis XML. JDO yog qhov txav tau yooj yim vim tias tsis tas yuav hloov kho lossis rov ua dua tshiab los khiav ntawm kev siv cov neeg muag khoom sib txawv.
Yam khoom muaj nqis yog dab tsi?
Value Object tseem hu ua Cov Ntaub Ntawv Hloov Khoom (DTO) yog ib qho qauv tsim qauv tsim qauv yooj yim uas cuam tshuam nrog lub thawv ntim cov ntaub ntawv los tuav cov ntaub ntawv rau lub hom phiaj ntawm kev hloov cov ntaub ntawv ntawm cov khaubncaws sab nraud povtseg thiab tiers. Txawm hais tias lub ntsiab lus tseeb tshaj plaws rau tus qauv no yog Cov Ntaub Ntawv Hloov Khoom, vim yog qhov yuam kev hauv Core J2EE thawj version nws tau qhia ua Tus Nqi Khoom. Txawm hais tias qhov kev ua yuam kev no tau raug kho nyob rau hauv tsab thib 2, lub npe no tau nrov thiab tseem siv ntau heev los ntawm Kev Hloov Cov Ntaub Ntawv (tab sis nws yuav tsum tau muab sau tseg tias lo lus raug yog Data Transfer Object). DTO tus qauv tsim yog siv nrog qhov chaw taum, JDBC thiab JDO los kho cov teeb meem tshwm sim hais txog kev sib cais thiab kev lag luam hauv kev lag luam. Nws yog ib qho tseem ceeb uas yuav tsum nco ntsoov tias cov no tsuas yog cov ntaub ntawv yooj yim siv los hloov cov ntaub ntawv ntawm tus neeg siv khoom thiab cov ntaub ntawv thiab lawv tsis muab kev ua kom tsis tu ncua. DTO ua hauj lwm rau lub hom phiaj ntawm kev ua yeeb yam raws li Serializable khoom nyob rau hauv ib txwm EJB (raws li qhov chaw taum ua ntej 3.0 tsis serializable). Nyob rau hauv ib qho kev sib sau ua ke uas tau teev tseg los ntawm DTO, tag nrho cov ntaub ntawv siv los ntawm kev saib tau txais thiab marshaled ua ntej tso tawm ntawm kev tswj mus rau txheej nthuav qhia.
Dab tsi yog qhov txawv ntawm JDO thiab Tus Nqi Khoom?
JDO yog qhov ua tau zoo siv thev naus laus zis siv los khaws cov khoom Java rau hauv cov ntaub ntawv uas muab kev yooj yim rau cov neeg tsim khoom los ntawm kev tuav tag nrho cov ntsiab lus ntawm kev ua tiav thiab tso cai rau cov neeg tsim khoom tsom mus rau qhov tsis yog database tshwj xeeb coding. Tab sis, Tus Nqi Khoom Muag sawv cev rau tus qauv tsim qauv (tsis yog thev naus laus zis) uas muab cov ntaub ntawv dav dav hu ua Data Transfer Object uas tuaj yeem tuav cov ntaub ntawv rau lub hom phiaj ntawm kev hloov ntawm cov neeg siv khoom thiab cov ntaub ntawv. JDO muab qhov chaw ntawm cov ntaub ntawv txuas ntxiv mus, thaum Lub Hom Phiaj tsuas yog cuam tshuam nrog kev khaws cov ntaub ntawv ib ntus thaum lub sijhawm hloov cov ntaub ntawv. Hauv lwm lo lus, Tus Nqi Khoom tsis muab kev ruaj khov.