SlideShare a Scribd company logo
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
Data access
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
Ad

More Related Content

What's hot (20)

Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
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
kamal kotecha
 
Hibernate tutorial
Hibernate tutorialHibernate tutorial
Hibernate tutorial
Mumbai Academisc
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
John Slick
 
Hibernate
HibernateHibernate
Hibernate
Prashant Kalkar
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ram132
 
Dao example
Dao exampleDao example
Dao example
myrajendra
 
Introduction to JPA Framework
Introduction to JPA FrameworkIntroduction to JPA Framework
Introduction to JPA Framework
Collaboration Technologies
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
Hitesh-Java
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Manav Prasad
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
Nguyen Cao
 
Hibernate
HibernateHibernate
Hibernate
Ajay K
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
Jeevesh Pandey
 
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
Guo Albert
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
elliando dias
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
Khoa Nguyen
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
Hitesh-Java
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
Lushanthan Sivaneasharajah
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
Aneega
 
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
kamal kotecha
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
John Slick
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ram132
 
Spring - Part 3 - AOP
Spring - Part 3 - AOPSpring - Part 3 - AOP
Spring - Part 3 - AOP
Hitesh-Java
 
Spring (1)
Spring (1)Spring (1)
Spring (1)
Aneega
 
Hibernate presentation
Hibernate presentationHibernate presentation
Hibernate presentation
Manav Prasad
 
Hibernate An Introduction
Hibernate An IntroductionHibernate An Introduction
Hibernate An Introduction
Nguyen Cao
 
Hibernate
HibernateHibernate
Hibernate
Ajay 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 Step
Guo Albert
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
guest11106b
 
Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
Khoa Nguyen
 

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
Secundaria Digital
 
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
FERNANDO BAPTISTA
 
Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016
Brilo Team
 
Deltricia Smith Resume
Deltricia Smith ResumeDeltricia Smith Resume
Deltricia Smith Resume
Deltricia Smith
 
Graphics designer
Graphics designerGraphics designer
Graphics designer
OliviaBrady
 
E&EProgram
E&EProgramE&EProgram
E&EProgram
Robert Freudenberg
 
Recursos literarios
Recursos literariosRecursos literarios
Recursos literarios
Secundaria Digital
 
Prezentace - základy bezpečnosti
Prezentace - základy bezpečnostiPrezentace - základy bezpečnosti
Prezentace - základy bezpečnosti
Brilo Team
 
El clasicismo
El clasicismoEl clasicismo
El clasicismo
pablosimon222
 
Manusia dan alam semesta
Manusia dan alam semestaManusia dan alam semesta
Manusia dan alam semesta
Aoi Sano
 
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
FERNANDO BAPTISTA
 
Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016Ranni kava-jhk.4.2.2016
Ranni kava-jhk.4.2.2016
Brilo Team
 
Graphics designer
Graphics designerGraphics designer
Graphics designer
OliviaBrady
 
Prezentace - základy bezpečnosti
Prezentace - základy bezpečnostiPrezentace - základy bezpečnosti
Prezentace - základy bezpečnosti
Brilo Team
 
Manusia dan alam semesta
Manusia dan alam semestaManusia dan alam semesta
Manusia dan alam semesta
Aoi Sano
 
Ad

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
Bill Lyons
 
Practical OData
Practical ODataPractical OData
Practical OData
Vagif Abilov
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivity
web360
 
Jdbc
JdbcJdbc
Jdbc
Jaydeep Viradiya
 
Jdbc
JdbcJdbc
Jdbc
mishaRani1
 
JEE5 New Features
JEE5 New FeaturesJEE5 New Features
JEE5 New Features
Haitham Raik
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database Connectivity
IRJET Journal
 
JDBC
JDBCJDBC
JDBC
Ankit Desai
 
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
VENKATESHBHAT25
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
Mazenetsolution
 
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
PawanMM
 
Jdbc
JdbcJdbc
Jdbc
DeepikaT13
 
Jdbc
JdbcJdbc
Jdbc
Yamuna Devi
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5
phanleson
 
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 2010
scdn
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
ChagantiSahith
 
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
kkorovkin
 
Java Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptxJava Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptx
ash909077
 
Unit 5.pdf
Unit 5.pdfUnit 5.pdf
Unit 5.pdf
saturo3011
 
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
Bill Lyons
 
3.java database connectivity
3.java database connectivity3.java database connectivity
3.java database connectivity
web360
 
IRJET- Review on Java Database Connectivity
IRJET- Review on Java Database ConnectivityIRJET- Review on Java Database Connectivity
IRJET- Review on Java Database Connectivity
IRJET Journal
 
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
21CS642 Module 5 JDBC PPT.pptx VI SEM CSE Students
VENKATESHBHAT25
 
Java- JDBC- Mazenet Solution
Java- JDBC- Mazenet SolutionJava- JDBC- Mazenet Solution
Java- JDBC- Mazenet Solution
Mazenetsolution
 
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
PawanMM
 
Jdbc Lecture5
Jdbc Lecture5Jdbc Lecture5
Jdbc Lecture5
phanleson
 
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 2010
scdn
 
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
kkorovkin
 
Java Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptxJava Database Connectivity by shreyash simu dbce.pptx
Java Database Connectivity by shreyash simu dbce.pptx
ash909077
 
Ad

More from Joshua Yoon (6)

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

Recently uploaded (20)

Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 

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
  • 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