SlideShare a Scribd company logo
1 of 19
Download to read offline
Data Access
Data Access
• Data access pattern
• Data Sources / Connection pool
• Data access with JDBC Template
• myBatis
• Object Relational Mapping (ORM) Data Access
Data Access Pattern
• Data Access Object Pattern or DAO pattern is used to separate low level data
accessing API or operations from high level business services. Following are the
participants in Data Access Object Pattern.
• Data Access Object Interface - This interface defines the standard operations to
be performed on a model object(s).
• Data Access Object concrete class - This class implements above interface. This
class is responsible to get data from a data source which can be database / xml or
any other storage mechanism.
• Model Object or Value Object - This object is simple POJO containing get/set
methods to store data retrieved using DAO class
Service Object DAO interface
DAO
implementation
Data Sources
• Use Data Source
• Use Connection Pool
We used the sample application provided in section "Connecting to a Data Source" to open a connection to Oracle9i using
a DataDirect Connect for JDBC 3.2 Oracle driver. We closed the connection at 100, 100, 1000, and 3000 iterations. We
ran this sample application on a single Pentium IV 2 GHz machine with 512 MB RAM connected to an Oracle9i Server
(Pentium IV 2 GHz machine with 512 MB RAM). The total elapsed time for each run was measured when connection
pooling was used and was measured again when connection pooling was not used as shown in the following table:
100 Iterations 100 Iterations 1000 Iterations 3000 Iterations
Pooling 547 ms <10 ms 47 ms 31 ms
Non-Pooling 4859 ms 4453 ms 43625 ms 134375 ms
JDBC CONNECTION POOLING - PERFORMANCE BENCHMARKS
Spring JDBC
Action Spring You
Define connection parameters.   X
Open the connection. X  
Specify the SQL statement.   X
Declare parameters and provide parameter values   X
Prepare and execute the statement. X  
Set up the loop to iterate through the results (if any). X  
Do the work for each iteration.   X
Process any exception. X  
Handle transactions. X  
Close the connection, statement and resultset. X
Spring JDBC - who does what?
Querying (SELECT)
Here is a simple query for getting the number of rows in a relation:
int rowCount = this.jdbcTemplate.queryForObject("select count(*) from t_actor", Integer.class);
A simple query using a bind variable:
int countOfActorsNamedJoe = this.jdbcTemplate.queryForObject(
"select count(*) from t_actor where first_name = ?", Integer.class, "Joe");
Querying for a String:
String lastName = this.jdbcTemplate.queryForObject(
"select last_name from t_actor where id = ?", new Object[]{1212L}, String.class);
Querying and populating a single domain object:
Actor actor = this.jdbcTemplate.queryForObject(
"select first_name, last_name from t_actor where id = ?",
new Object[]{1212L},
new RowMapper<Actor>() {
public Actor mapRow(ResultSet rs, int rowNum) throws SQLException {
Actor actor = new Actor();
actor.setFirstName(rs.getString("first_name"));
actor.setLastName(rs.getString("last_name"));
return actor;
}
});
Updating (INSERT/UPDATE/DELETE) with jdbcTemplate
this.jdbcTemplate.update("insert into t_actor (first_name, last_name) values (?, ?)", "Leonor", "Watling");
this.jdbcTemplate.update( "update t_actor set last_name = ? where id = ?","Banjo", 5276L);
this.jdbcTemplate.update("delete from actor where id = ?",Long.valueOf(actorId));
JdbcTemplate best practices
public class JdbcCorporateEventDao implements CorporateEventDao {
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
// JDBC-backed implementations of the methods on the
CorporateEventDao follow...
}
Using @Repository
@Repository
public class JdbcCorporateEventDao implements CorporateEventDao {
private JdbcTemplate jdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
// JDBC-backed implementations of the methods on the
CorporateEventDao follow...
}
myBatis
• iBATIS is a persistence framework which automates the mapping between SQL databases and objects in
Java, .NET, and Ruby on Rails. In Java, the objects are POJOs (Plain Old Java Objects). The mappings are
decoupled from the application logic by packaging the SQL statements in XML configuration files. The result is a
significant reduction in the amount of code that a developer needs to access a relational database using lower
level APIs like JDBC and ODBC.
• Other persistence frameworks such as Hibernate allow the creation of an object model (in Java, say) by the user,
and create and maintain the relational database automatically. iBATIS takes the reverse approach: the developer
starts with a SQL database and iBATIS automates the creation of the Java objects. Both approaches have
advantages, and iBATIS is a good choice when the developer does not have full control over the SQL database
schema. For example, an application may need to access an existing SQL database used by other software, or
access a new database whose schema is not fully under the application developer's control, such as when a
specialized database design team has created the schema and carefully optimized it for high performance.
• On May 21, 2010 the development team forked the code creating a new project called MyBatis and making new
releases there. As a consequence the Apache iBATIS project became inactive and was moved to the Apache
Attic in June 2010.
Object-relational mapping
• Compared to traditional techniques of exchange between
an object-oriented language and a relational database,
ORM often reduces the amount of code that needs to be
written.
• Disadvantages of ORM tools generally stem from the high
level of abstraction obscuring what is actually happening
in the implementation code. Also, heavy reliance on ORM
software has been cited as a major factor in producing
poorly designed databases.
Comparison of object-relational mapping software
Software Platform Availability License Version Persistence Specification
Doctrine PHP Open source MIT 2.4/April 8, 2014
DataNucleus
Java Virtual
Machine
Open source Apache License 2 4.1.0.RELEASE / May 19, 2015 JDO
RedBeanPHP PHP Open source BSD License 4/April 1, 2014
Dapper .NET 4.0 Open source Apache License 2.0 1.8 NuGet
ECO .NET 4.0 Commercial ECO 6 Final (2011-04-18[1])
EntitySpaces .NET 4.0 Open source Modified BSD License 2012.1.0930.0 / October 4, 2012
EclipseLink
Java Virtual
Machine
Open source
Eclipse Public License Version 1.0 (EPL) and Eclipse Distribution
License Version 1.0 (EDL)
2.4.2 / July 4, 2013 JPA 2.0
Hibernate
Java Virtual
Machine
Open source GNU Lesser General Public License 4.2.5 / August 28, 2013 JPA 2.0
MyBatis/iBATIS Cross-platform Open source Apache License 2.0
jOOQ
Java Virtual
Machine
Open source Apache License 2.0 and Proprietary License 3.2.0 / October 9, 2013
Apache Cayenne
Java Virtual
Machine
Open source Apache License 2.0 3.0.2 / July 21, 2011
Microsoft ADO.NET
Entity Framework
.NET 4.5 Part of .NET 4.5 Apache License 2.0[2] v6.0 (2014)
nHibernate .NET 4.5 Open source GNU Lesser General Public License 4.0 (2014-08-17[3])
ODB
Cross-platform
C++
Dual-licensed GNU General Public License and Proprietary License 2.3.0 / October 30, 2013
SQLAlchemy Python Open source MIT License 1.0.9 / October 20, 2015
SQLObject Python Open source LGPL 2.1.2 / March 15, 2015
Storm Python Open source LGPL 2.1 0.19 / October 5, 2011
SubSonic .NET 2.0 Open source New BSD 3.0 / July 2009
TopLink
Java Virtual
Machine
Commercial Oracle License 10g JPA
Skipper PHP Commercial Proprietary software 3.0
WebORB Integration
Server
.NET, Java,
PHP
Commercial & Open
source
WebORB for .NET and WebORB for Java = Proprietary License,
WebORB for PHP = Mozilla Public License
WebORB for .NET v.4.2 (Oct 2010), WebORB for Java
v.4.0 (Sep 2010), WebORB for PHP (Sep 2008)
DBIx::Class Perl Open source Artistic License 1.0 & GPL 0.082820 / March 20, 2015[4]
Advantage Disadvantage
JDBC template Performance SQL in Code
MyBatis decoupling SQL XML
Hibernate Reduce code Poor Performance
Reference
http://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm
http://www.oracle.com/technetwork/java/dataaccessobject-138824.html
https://en.wikipedia.org/wiki/Data_access_object
https://en.wikipedia.org/wiki/Data_transfer_object
http://javarevisited.blogspot.kr/2012/08/top-10-jdbc-best-practices-for-java.html
https://www.progress.com/jdbc/resources/tutorials/connection-pooling/performance-
benchmarks
http://www.javaranch.com/journal/200601/JDBCConnectionPooling.html
https://en.wikipedia.org/wiki/Comparison_of_object-relational_mapping_software
http://www.jooq.org/doc/2.6/manual/sql-execution/comparison-with-jdbc/
http://stackoverflow.com/questions/7242388/comparing-querydsl-jooq-jequel-activejdbc-
iciql-and-other-query-dsls
http://stackoverflow.com/questions/1353137/hibernate-or-jdbc
https://docs.oracle.com/javase/jndi/tutorial/ldap/connect/pool.html
http://www.yegor256.com/2014/12/01/orm-offensive

More Related Content

What's hot

Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Examplekamal kotecha
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentationJohn Slick
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate TutorialRam132
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOPHitesh-Java
 
Spring (1)
Spring (1)Spring (1)
Spring (1)Aneega
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentationManav Prasad
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An IntroductionNguyen Cao
 
Hibernate
HibernateHibernate
HibernateAjay K
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationKhoa Nguyen
 

What's hot (20)

Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Dao example
Dao exampleDao example
Dao example
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
 
Hibernate
HibernateHibernate
Hibernate
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
 

Viewers also liked

Apresentação final our international healthy restaurant
Apresentação final our international healthy restaurantApresentação final our international healthy restaurant
Apresentação final our international healthy restaurantFERNANDO BAPTISTA
 
Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016Brilo Team
 
Graphics designer
Graphics designerGraphics designer
Graphics designerOliviaBrady
 
Prezentace - základy bezpečnosti
Prezentace - základy bezpečnostiPrezentace - základy bezpečnosti
Prezentace - základy bezpečnostiBrilo Team
 
Manusia dan alam semesta
Manusia dan alam semestaManusia dan alam semesta
Manusia dan alam semestaAoi Sano
 

Viewers also liked (10)

La música en la Edad Media
La música en la Edad MediaLa música en la Edad Media
La música en la Edad Media
 
Apresentação final our international healthy restaurant
Apresentação final our international healthy restaurantApresentação final our international healthy restaurant
Apresentação final our international healthy restaurant
 
Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016
 
Deltricia Smith Resume
Deltricia Smith ResumeDeltricia Smith Resume
Deltricia Smith Resume
 
Graphics designer
Graphics designerGraphics designer
Graphics designer
 
E&EProgram
E&EProgramE&EProgram
E&EProgram
 
Recursos literarios
Recursos literariosRecursos literarios
Recursos literarios
 
Prezentace - základy bezpečnosti
Prezentace - základy bezpečnostiPrezentace - základy bezpečnosti
Prezentace - základy bezpečnosti
 
El clasicismo
El clasicismoEl clasicismo
El clasicismo
 
Manusia dan alam semesta
Manusia dan alam semestaManusia dan alam semesta
Manusia dan alam semesta
 

Similar to Data access

EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivityweb360
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET Journal
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionMazenetsolution
 
Session 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaSession 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaPawanMM
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5phanleson
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)suraj pandey
 
Java one 2010
Java one 2010Java one 2010
Java one 2010scdn
 
Dev212 Comparing Net And Java The View From 2006
Dev212 Comparing  Net And Java  The View From 2006Dev212 Comparing  Net And Java  The View From 2006
Dev212 Comparing Net And Java The View From 2006kkorovkin
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaJignesh Aakoliya
 

Similar to Data access (20)

EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Practical OData
Practical ODataPractical OData
Practical OData
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivity
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
JEE5 New Features
JEE5 New FeaturesJEE5 New Features
JEE5 New Features
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database Connectivity
 
JDBC
JDBCJDBC
JDBC
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
 
Session 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise JavaSession 24 - JDBC, Intro to Enterprise Java
Session 24 - JDBC, Intro to Enterprise Java
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc
JdbcJdbc
Jdbc
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
Dev212 Comparing Net And Java The View From 2006
Dev212 Comparing  Net And Java  The View From 2006Dev212 Comparing  Net And Java  The View From 2006
Dev212 Comparing Net And Java The View From 2006
 
Unit 5.pdf
Unit 5.pdfUnit 5.pdf
Unit 5.pdf
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 

More from Joshua Yoon

More from Joshua Yoon (6)

AOP
AOPAOP
AOP
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Database design
Database designDatabase design
Database design
 
HTTP Basic
HTTP BasicHTTP Basic
HTTP Basic
 
Javascript
JavascriptJavascript
Javascript
 
기업문화
기업문화기업문화
기업문화
 

Recently uploaded

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 

Recently uploaded (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 

Data access

  • 2. Data Access • Data access pattern • Data Sources / Connection pool • Data access with JDBC Template • myBatis • Object Relational Mapping (ORM) Data Access
  • 4. • Data Access Object Pattern or DAO pattern is used to separate low level data accessing API or operations from high level business services. Following are the participants in Data Access Object Pattern. • Data Access Object Interface - This interface defines the standard operations to be performed on a model object(s). • Data Access Object concrete class - This class implements above interface. This class is responsible to get data from a data source which can be database / xml or any other storage mechanism. • Model Object or Value Object - This object is simple POJO containing get/set methods to store data retrieved using DAO class
  • 5.
  • 6. Service Object DAO interface DAO implementation
  • 7. Data Sources • Use Data Source • Use Connection Pool
  • 8. We used the sample application provided in section "Connecting to a Data Source" to open a connection to Oracle9i using a DataDirect Connect for JDBC 3.2 Oracle driver. We closed the connection at 100, 100, 1000, and 3000 iterations. We ran this sample application on a single Pentium IV 2 GHz machine with 512 MB RAM connected to an Oracle9i Server (Pentium IV 2 GHz machine with 512 MB RAM). The total elapsed time for each run was measured when connection pooling was used and was measured again when connection pooling was not used as shown in the following table: 100 Iterations 100 Iterations 1000 Iterations 3000 Iterations Pooling 547 ms <10 ms 47 ms 31 ms Non-Pooling 4859 ms 4453 ms 43625 ms 134375 ms JDBC CONNECTION POOLING - PERFORMANCE BENCHMARKS
  • 10. Action Spring You Define connection parameters.   X Open the connection. X   Specify the SQL statement.   X Declare parameters and provide parameter values   X Prepare and execute the statement. X   Set up the loop to iterate through the results (if any). X   Do the work for each iteration.   X Process any exception. X   Handle transactions. X   Close the connection, statement and resultset. X Spring JDBC - who does what?
  • 11. Querying (SELECT) Here is a simple query for getting the number of rows in a relation: int rowCount = this.jdbcTemplate.queryForObject("select count(*) from t_actor", Integer.class); A simple query using a bind variable: int countOfActorsNamedJoe = this.jdbcTemplate.queryForObject( "select count(*) from t_actor where first_name = ?", Integer.class, "Joe"); Querying for a String: String lastName = this.jdbcTemplate.queryForObject( "select last_name from t_actor where id = ?", new Object[]{1212L}, String.class); Querying and populating a single domain object: Actor actor = this.jdbcTemplate.queryForObject( "select first_name, last_name from t_actor where id = ?", new Object[]{1212L}, new RowMapper<Actor>() { public Actor mapRow(ResultSet rs, int rowNum) throws SQLException { Actor actor = new Actor(); actor.setFirstName(rs.getString("first_name")); actor.setLastName(rs.getString("last_name")); return actor; } });
  • 12. Updating (INSERT/UPDATE/DELETE) with jdbcTemplate this.jdbcTemplate.update("insert into t_actor (first_name, last_name) values (?, ?)", "Leonor", "Watling"); this.jdbcTemplate.update( "update t_actor set last_name = ? where id = ?","Banjo", 5276L); this.jdbcTemplate.update("delete from actor where id = ?",Long.valueOf(actorId));
  • 13. JdbcTemplate best practices public class JdbcCorporateEventDao implements CorporateEventDao { private JdbcTemplate jdbcTemplate; public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } // JDBC-backed implementations of the methods on the CorporateEventDao follow... }
  • 14. Using @Repository @Repository public class JdbcCorporateEventDao implements CorporateEventDao { private JdbcTemplate jdbcTemplate; @Autowired public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } // JDBC-backed implementations of the methods on the CorporateEventDao follow... }
  • 15. myBatis • iBATIS is a persistence framework which automates the mapping between SQL databases and objects in Java, .NET, and Ruby on Rails. In Java, the objects are POJOs (Plain Old Java Objects). The mappings are decoupled from the application logic by packaging the SQL statements in XML configuration files. The result is a significant reduction in the amount of code that a developer needs to access a relational database using lower level APIs like JDBC and ODBC. • Other persistence frameworks such as Hibernate allow the creation of an object model (in Java, say) by the user, and create and maintain the relational database automatically. iBATIS takes the reverse approach: the developer starts with a SQL database and iBATIS automates the creation of the Java objects. Both approaches have advantages, and iBATIS is a good choice when the developer does not have full control over the SQL database schema. For example, an application may need to access an existing SQL database used by other software, or access a new database whose schema is not fully under the application developer's control, such as when a specialized database design team has created the schema and carefully optimized it for high performance. • On May 21, 2010 the development team forked the code creating a new project called MyBatis and making new releases there. As a consequence the Apache iBATIS project became inactive and was moved to the Apache Attic in June 2010.
  • 16. Object-relational mapping • Compared to traditional techniques of exchange between an object-oriented language and a relational database, ORM often reduces the amount of code that needs to be written. • Disadvantages of ORM tools generally stem from the high level of abstraction obscuring what is actually happening in the implementation code. Also, heavy reliance on ORM software has been cited as a major factor in producing poorly designed databases.
  • 17. Comparison of object-relational mapping software Software Platform Availability License Version Persistence Specification Doctrine PHP Open source MIT 2.4/April 8, 2014 DataNucleus Java Virtual Machine Open source Apache License 2 4.1.0.RELEASE / May 19, 2015 JDO RedBeanPHP PHP Open source BSD License 4/April 1, 2014 Dapper .NET 4.0 Open source Apache License 2.0 1.8 NuGet ECO .NET 4.0 Commercial ECO 6 Final (2011-04-18[1]) EntitySpaces .NET 4.0 Open source Modified BSD License 2012.1.0930.0 / October 4, 2012 EclipseLink Java Virtual Machine Open source Eclipse Public License Version 1.0 (EPL) and Eclipse Distribution License Version 1.0 (EDL) 2.4.2 / July 4, 2013 JPA 2.0 Hibernate Java Virtual Machine Open source GNU Lesser General Public License 4.2.5 / August 28, 2013 JPA 2.0 MyBatis/iBATIS Cross-platform Open source Apache License 2.0 jOOQ Java Virtual Machine Open source Apache License 2.0 and Proprietary License 3.2.0 / October 9, 2013 Apache Cayenne Java Virtual Machine Open source Apache License 2.0 3.0.2 / July 21, 2011 Microsoft ADO.NET Entity Framework .NET 4.5 Part of .NET 4.5 Apache License 2.0[2] v6.0 (2014) nHibernate .NET 4.5 Open source GNU Lesser General Public License 4.0 (2014-08-17[3]) ODB Cross-platform C++ Dual-licensed GNU General Public License and Proprietary License 2.3.0 / October 30, 2013 SQLAlchemy Python Open source MIT License 1.0.9 / October 20, 2015 SQLObject Python Open source LGPL 2.1.2 / March 15, 2015 Storm Python Open source LGPL 2.1 0.19 / October 5, 2011 SubSonic .NET 2.0 Open source New BSD 3.0 / July 2009 TopLink Java Virtual Machine Commercial Oracle License 10g JPA Skipper PHP Commercial Proprietary software 3.0 WebORB Integration Server .NET, Java, PHP Commercial & Open source WebORB for .NET and WebORB for Java = Proprietary License, WebORB for PHP = Mozilla Public License WebORB for .NET v.4.2 (Oct 2010), WebORB for Java v.4.0 (Sep 2010), WebORB for PHP (Sep 2008) DBIx::Class Perl Open source Artistic License 1.0 & GPL 0.082820 / March 20, 2015[4]
  • 18. Advantage Disadvantage JDBC template Performance SQL in Code MyBatis decoupling SQL XML Hibernate Reduce code Poor Performance
  • 19. Reference http://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm http://www.oracle.com/technetwork/java/dataaccessobject-138824.html https://en.wikipedia.org/wiki/Data_access_object https://en.wikipedia.org/wiki/Data_transfer_object http://javarevisited.blogspot.kr/2012/08/top-10-jdbc-best-practices-for-java.html https://www.progress.com/jdbc/resources/tutorials/connection-pooling/performance- benchmarks http://www.javaranch.com/journal/200601/JDBCConnectionPooling.html https://en.wikipedia.org/wiki/Comparison_of_object-relational_mapping_software http://www.jooq.org/doc/2.6/manual/sql-execution/comparison-with-jdbc/ http://stackoverflow.com/questions/7242388/comparing-querydsl-jooq-jequel-activejdbc- iciql-and-other-query-dsls http://stackoverflow.com/questions/1353137/hibernate-or-jdbc https://docs.oracle.com/javase/jndi/tutorial/ldap/connect/pool.html http://www.yegor256.com/2014/12/01/orm-offensive