?
Solved

spring DAO

Posted on 2011-05-06
4
Medium Priority
?
428 Views
Last Modified: 2012-05-11
I was reading folowing lines and I did not understand clearly.
>>
But at certain points, the process delegates to other collaborators to fill in
some implementation-specific details. This is the part of the process that is variable.
For example, the handling of luggage starts with a passenger checking in
the luggage at the counter. This part of the process always has to happen at the
beginning, so its sequence in the process is fixed. But each passenger’s luggage
check-in is different. The implementation of this process is determined by the
passenger. In software terms, a template method delegates the implementationspecific
portions of the process to an interface. Different implementations of this
interface define specific implementations of this portion of the process.
Spring applies this pattern to data access. No matter what technology we are
using, certain data access steps are required. For example, we always need to
obtain a connection to our data store and clean up resources when we are done.
These are the fixed steps in a data access process. But each data access implementation
we write is slightly different. We query for different objects and update the
data in different ways. These are the variable steps in a data access process.
Spring separates the fixed and variant parts of the data access process into


Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
0
Comment
Question by:gudii9
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 1000 total points
ID: 35710113
This statement is very understandable and applies not only to Spring - the easiest way to illustrate it is too look at
JDBC.
JDBC is a set of interfaces which define how Java code can interact with
data in the database. It makes only very basic assumptions about what is a relational database - it is usualy a set
of tables sitting on some server from which you can select and which you can modify - delete rows, insert rows, update.
The definition of JDBC does not care how and where this data is physically stored -you can just
have text table is the file in yiur home directory which will serve as implenetation of database,
or you can have this huge and complicated system on computer cluster in the other part
of the world. You still need to connect to this source, you need to find among many tables there the one
you need and say select some specified row. The actual physical processes would be very different,
but the methods which you will use could have the same signatures, i.e. require
the same input paraemeters, output data to java program in the same formats.
Definition of such interface allows to java programmers to know only format
of these interface methods and to people who know the best their database (usually vendor of databse)
structure and the way data are stored in disks aand files to write mthods which would be consistent
with the certain signatures  and these real implementastions of these methods are  collected in the driver classes
which would be different for Oracle, Sybase, MySQL, etc, even though their
signatures wil be the same. Java programmer    who is using them, as I mentioned, needs to know only the way
the intercfaces look and he  does not need to care how physically the
methods are implemeneted. One thing, it saves a lot of time to the programmer otherwise a programmer
would have to study the internal structure of one or
perhaps several databases. Anaother advantage - you can easily move form one database
to another effectively by just changing the driver - as it is  the driver which incorporates all differences
between databses (in parctice some connection strings will also change, but this is certainly minor
in comparison with all that knowledge of the databse structure, which would have been
necessary if there would not be jdbc interface).
Well, it is all very understandabl issues - in fact application of general idea of iterface/implementation
separation to intercation of java program with databases.
0
 
LVL 7

Author Comment

by:gudii9
ID: 35710266
>>> In software terms, a template method delegates the implementationspecific
portions of the process to an interface.

template means jdbc template right.  Which method delegates it. please advise
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35710338

In Object Oriented Design (see, e.g. http://www.oodesign.com/template-method-pattern.html)
 we speak
of template as say some general higher level plan of a procedure where each individual
step may be implemeneted sperarately in different way.
In JDBC, well , we can also on certain level think of the template - say to get some piece
of data - you have to first make a connection, then locate adequate table, locate adequate row,
find value of necessary field, return data - these are indeed steps defined by jdbc pattern, assumption of how it should
proceed which underlies jdbc
- this may be called as template and implementation of each step is delegated to
driver and each driver will implemnet each step in its own  way, though they will all
follow the same template imposed by jdbc.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 1000 total points
ID: 35714212
yes its talking about the jdbc template (which is specific to Spring)
It makes jdbc coding a lot simpler be handling the creation and release of resources, and also removing the potential for error. It will execute the query, and handle mapping the exceptions to hide you from the underlying jdbc code.
The implementation specific code can be provided through callbacks, for example if you need to make changes how the PreparedStatement is setup you provide your own PreparedStatementCreator and the template will call it whenever it creates a PreparedStatement
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
A solution for Fortify Path Manipulation.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question