spring DAO

Posted on 2011-05-06
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.
Question by:gudii9
    LVL 47

    Accepted Solution

    This statement is very understandable and applies not only to Spring - the easiest way to illustrate it is too look at
    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.
    LVL 7

    Author Comment

    >>> 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
    LVL 47

    Expert Comment


    In Object Oriented Design (see, e.g.
     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.
    LVL 92

    Assisted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Video by: Michael
    Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now