Improve Persistence With Apache Derby And Ibatis Part 1-Books Pdf

Improve persistence with Apache Derby and iBATIS Part 1
27 May 2020 | 31 views | 0 downloads | 23 Pages | 373.07 KB

Share Pdf : Improve Persistence With Apache Derby And Ibatis Part 1

Download and Preview : Improve Persistence With Apache Derby And Ibatis Part 1


Report CopyRight/DMCA Form For : Improve Persistence With Apache Derby And Ibatis Part 1



Transcription

developerWorks ibm com developerWorks, data access and Derby database layers You use the DAO framework with the Data. Mapper framework through the JPetStore application Using the DAO with the Data. Mapper provides you with a clean and consistent way of accessing your application s. underlying data structure, Part 3 uses the Data Mapper to cover transaction handling data caching and. creating dynamic SQL statements It also takes a brief look at and provides an. example of how to use the DAO framework without the Data Mapper framework to. integrate it as a stand alone framework within an application. About this tutorial, As a developer you ve likely had the frequent responsibility of mapping your Java. objects to relational database tables for persistence Persistence is the ability to read. objects from write objects to and delete objects from permanent storage a topic. discussed ad infinitum in the Java community This is where iBATIS comes in It s a. simple and powerful framework that does a great job of OR mapping letting you. solve business problems instead of mucking around with boilerplate code. iBATIS consists of two frameworks one of which the Data Mapper pertains. specifically to OR mapping The Data Mapper is this tutorial s main focus You ll use. the versatile Apache Derby as an embedded database for your persistence layer in. the tutorial s example exercises,Prerequisites, This tutorial assumes that you re comfortable working with basic SQL statements. that you understand basic XML semantics and that you don t have any trouble. reading through Java code You need to know how to run Apache Ant to follow the. tutorial s examples and create the database,System requirements.
To run the example code in this tutorial perform the following steps. 1 Download and install the following applications,Apache Derby 10 1 1 0. Apache Ant 1 6 5,Java 2 Platform Standard Edition J2SE 1 4 2 09. You don t need to download iBATIS separately because the necessary. Initial configuration semantics and a simple test, Page 2 of 23 Copyright IBM Corporation 1994 2008 All rights reserved. ibm com developerWorks developerWorks, jar files are included with the source code for this tutorial which you. download in step 3, 2 Make sure that the environmental variables outlined in Table 1 are.
defined in your shell,Table 1 Setting the environmental variables. Variable name Required setting,DERBY HOME Set to the root folder of your Derby. installation,ANT HOME Set to the root folder of your Ant. installation,JAVA HOME Set to the root folder of your Java. installation,PATH Ensure that ANT HOME bin is in, 3 Extract the supplied zip file see the Download section to your preferred.
location This is the project root The project is laid out in Listing 1. Listing 1 Project layout, lib iBATIS JAR files to be included in the classpath. sql file containing DDL to create your database,src Java source code and iBATIS XML configs. build xml Ant build file, 4 Modify the src properties database properties file to specify where you. would like Derby to create your database I ve set the url property in the. database properties file to be jdbc derby c temp ibatis See the. database properties file shown in Listing 2 and change the path to. include something appropriate for your file system. Listing 2 The database properties file,Database Connectivity Properties. driver org apache derby jdbc EmbeddedDriver,url jdbc derby c temp ibatis.
Make sure that the value you specify is an existing empty directory You. can leave the username and password blank as they are If you re on a. UNIX or Linux system your path looks something like tmp ibatis but. Initial configuration semantics and a simple test, Copyright IBM Corporation 1994 2008 All rights reserved Page 3 of 23. developerWorks ibm com developerWorks,you can create this directory wherever you want. Section 2 What is iBATIS, This section describes the separate APIs within iBATIS and why you might use. them and identifies iBATIS s advantages over other database mapping frameworks. The iBATIS frameworks, Simply put iBATIS consists of two separate frameworks You use the Data Mapper. framework specifically for OR mapping which is the mapping of your Java domain. objects to relational tables in a database The DAO framework gives your application. a clean and consistent way to access underlying data. iBATIS Data Mapper framework Data Mapper, The Data Mapper is the framework that executes your SQL and maps the results.
back to objects saving you from having to do this manually. The Data Mapper framework doesn t require you to make any special version of your. Java objects You don t need to implement any interfaces or generate any code You. don t need to subclass some other base object or perform any strange rituals And. you don t need to learn a secondary query language specific to the framework. You use a simple and straightforward XML format to define the manner in which. iBATIS maps your Java objects to the database You can define the exact query you. need directly in SQL and optionally use any proprietary SQL that is specific to the. database engine you re using This capability lets you map your objects exactly the. way you want and perform joins exactly the way you want. iBATIS Data Access Objects framework DAO framework. The DAO framework s main goal is to abstract the how and where of your. application s data access or persistence layer from the application s business logic. The DAO framework lets you define interfaces in your application that are. responsible for data centric operations, For example if your application uses straight up Java Database Connectivity. JDBC for persistence the DAO framework s goal is to abstract the use of classes. and interfaces such as Connection PreparedStatement and ResultSet. Initial configuration semantics and a simple test, Page 4 of 23 Copyright IBM Corporation 1994 2008 All rights reserved. ibm com developerWorks developerWorks, away from your application and move it down into a persistence layer instead. If your application for some reason uses HTTP GETs and POSTs to get and store. data then the DAO framework s purpose becomes to abstract the use of classes. such as HttpUrlConnection away from your application s business layer Your. application can then use the DAO interfaces to perform operations on your data and. the implementations of these interfaces are abstracted away from your business. logic The implementations can retrieve data from a database a Web service or any. other source, The DAO framework doesn t depend on the use of the Data Mapper framework You. can use both frameworks in a project should you choose and they pair quite nicely. or you can use each one independently This tutorial series shows the advantages of. using the frameworks alone and together,Advantages of iBATIS.
iBATIS has some advantages over other OR mapping tools. iBATIS doesn t use its own proprietary query language it just uses SQL. Some OR mapping tools such as Hibernate use their own query. languages in addition to SQL, All the queries and updates you want to perform are written in SQL and. stored in xml files Some people might consider this a disadvantage. wanting the database abstracted from them completely to avoid needing. to write any SQL code This is one reason a lot of developers like. Hibernate But you might prefer to have fine grained control over exactly. what SQL is being executed when you access your objects rather than. having it unpredictably generated for you in a manner dependent on the. underlying OR mapping framework You can fine tune your queries and. other statements based on recommendations by a database administrator. DBA or by access plans or query optimizers provided by the tools. supplied with your relational database management system RDBMS. Another benefit of having direct access over the SQL that is written for. this layer is that you can take advantage of any proprietary SQL offered. by your database,It s easy to use,The project is well documented. It has no external dependencies Some of the other OR mapping. frameworks ship with 15 to 20 jar files and are dependent on specific. versions of these files just to let the framework run You don t need or. want that kind of a headache when developing applications so the fact. Initial configuration semantics and a simple test, Copyright IBM Corporation 1994 2008 All rights reserved Page 5 of 23. developerWorks ibm com developerWorks, that you can use iBATIS without any external dependencies is a huge. plus Note that some optional configurations let you enable things like an. external connection pool or bytecode enhancement but none of them is. Now it s time to dive into some more specific iBATIS concepts and semantics which. eventually lead to some coding and examples,Section 3 iBATIS Data Mapper semantics.
The remainder of this tutorial examines the Data Mapper framework almost. exclusively Part 2 covers the DAO framework in depth This section covers Data. Mapper semantics,Mapped Statements, The Data Mapper s core functionality revolves around the concept of Mapped. Statements A Mapped Statement can have what are called Parameter Maps. basically data input and Result Maps data output So a Mapped Statement is. essentially an XML element that contains an SQL statement responsible for. performing some action and mapping input output parameters to Java objects. Listing 3 shows a simple SQL Mapped Statement that comes from the JPetStore. demo see Resources for a link to the download,Listing 3 A simple SQL Mapped Statement. select id getUsernameList,resultClass string,parameterClass account. select USERNAME as value from SIGNON, The Mapped Statement in Listing 3 is responsible for querying for all values of the. USERNAME column from the SIGNON table There are several different types of. Mapped Statements As you can see this particular Mapped Statement is a. select In addition to select you can take advantage of statement. insert update delete and procedure Mapped Statement. elements when using the iBATIS framework The iBATIS documentation covers. each of these in more detail see Resources for a link to the iBATIS Web site. Parameter Maps and inline parameters,Initial configuration semantics and a simple test.
Page 6 of 23 Copyright IBM Corporation 1994 2008 All rights reserved. ibm com developerWorks developerWorks, Parameter Maps in the iBATIS framework provide data input parameters to a. Mapped Statement Parameter Maps are not often used in and of themselves. usually inline parameters are used instead but Listing 4 shows an example of how. they work with an example Parameter Map and a Mapped Statement from the. documentation,Listing 4 Parameter Maps in the iBATIS framework. parameterMap id insert product param class com domain Product. parameter property id jdbcType NUMERIC,javaType int nullValue 9999999. parameter property description jdbcType VARCHAR,nullValue NO ENTRY. parameterMap, statement id insertProduct parameterMap insert product param.
insert into PRODUCT PRD ID PRD DESCRIPTION values, You can see that the Mapped Statement in Listing 4 references the Parameter Map. by name and that it contains two placeholder question marks You ll recognize these. as standard placeholders for JDBC PreparedStatements It applies the values it. retrieves from the Parameter Map in the order in which they are defined to these. placeholders, The Parameter Map in Listing 4 defines that the com domain Product class s id. property getId maps to the first placeholder question mark in any Mapped. Statement that uses this Parameter Map It goes on with the next parameter. element to state that the com domain Product class s description. property getDescription maps to the second placeholder question. mark in any Mapped Statement that uses it Within a parameterMap the order in. which parameter elements appear is the same order in which they are applied to. the placeholder question marks within the Mapped Statement that uses the. parameterMap, More commonly input parameters are mapped with inline parameters see Listing. Listing 5 Inline parameters, statement id insertProduct parameterClass com domain Product. insert into PRODUCT PRD ID PRD DESCRIPTION,values id description.
This syntax replaces id with the value returned by getId from the. com domain Product class while description is replaced by the value. returned by getDescription of com domain Product You can take a look. at the iBATIS documentation for how to specify null values. Initial configuration semantics and a simple test, Copyright IBM Corporation 1994 2008 All rights reserved Page 7 of 23. developerWorks ibm com developerWorks,Result Maps, Result Maps are like Parameter Maps but are used for output Result Maps let you. define the manner in which you would like your Mapped Statements typically. queries mapped back into a Java object Listing 6 provides a quick look at an. example from the iBATIS documentation,Listing 6 Result Maps. resultMap id get product result class com domain Product. result property id column PRD ID, result property description column PRD DESCRIPTION. statement id getProduct resultMap get product result. select from PRODUCT, You can see that the Mapped Statement with the id of getProduct.
iBATIS maps your Java objects to the database You can define the exact query you need directly in SQL and optionally use any proprietary SQL that is specific to the database engine you re using This capability lets you map your objects exactly the way you want and perform joins exactly the way you want iBATIS Data Access Objects framework DAO framework The DAO framework s main goal is to

Related Books

spine 8739 The quick way to learn Windows 10

spine 8739 The quick way to learn Windows 10

Windows 10 Step by Step is designed for use as a learning and reference resource by home and business users of desktop and portable computers and devices run ning Windows 10 Home or Windows 10 Pro The content of the book is designed to be useful for people who have previously used earlier versions of Windows and for people who are discovering Windows for the first time What this book is and

computer basics VFU

computer basics VFU

DVD or on a diskette floppy disk and is loaded i e copied from the disk into the computers RAM Random Access Memory as and when required Types of Computers Mini and Mainframe Computers Very powerful used by large organisations such an banks to control the entire business operation Very expensive Personal Computers Cheap and easy to use Often used as stand alone computers or in a

Model Volvo TAD1640GE TAD1641GE TAD1642GE TWD1643GE

Model Volvo TAD1640GE TAD1641GE TAD1642GE TWD1643GE

Engine Model Volvo TAD1640GE TAD1641GE TAD1642GE TWD1643GE Generator Model 450REOZVB 500REOZVB C 550 600REOZV B TP 6348 12 14g Service Parts

VOLVO 850 1996

VOLVO 850 1996

VOLVO 850 1996 1998 RH DRIVE MODEL POWER STEERING GEAR SERVICE INSTRUCTION 1 1 INTRODUCTION Power assisted rack amp pinion steering system is standard equipment on all models covered within the production year above including earlier and later production Typically the system used in my 855T5 is built by TRW with markings 34 010 752 RH ISSUE on the right hand side of the rack housing

Nueva web www etrasa

Nueva web www etrasa

r Facturaci n manual y autom tica de alumnos clientes y proveedores Control de cajas ingresos salidas y gastos por secci n y por usuario r Creaci n de carpetas de tr fico y presentaci n de alumnos por pruebas te rica maniobra y circulaci n Organizaci n del parte del profesor del centro y sincronizado con el programa Qlases G e s t i n A d m i n i s t a t

SISTEMA DE INFORMACI N PARA LA GESTI N DE CURSOS

SISTEMA DE INFORMACI N PARA LA GESTI N DE CURSOS

Gestiones sobre la Tarjeta CAP Solicitud de Certificados CAP C Representante Centro permite acceder a la aplicaci n como representante de una empresa o centro CAP Aparecer un listado de las empresas a las que puede representar en cualquier caso se permitir la comunicaci n de una Nueva autorizaci n de empresa CAP

EDICI N de Capacitaci n Profesional de Transporte 2012

EDICI N de Capacitaci n Profesional de Transporte 2012

Manual para la obtenci n del Certificado de Capacitaci n Profesional de Transporte de M erc an s por C t Colecci n Temarios Generales GES0237 2012 EDICI N 2012 EDICI NEDICI N MANUAL PARA LA OBTENCI N DEL CERTIFICADO DE CAPACITACI N PROFESIONAL DE TRANSPORTE DE MERCANC AS POR CARRETERA Sevilla febrero 2012 ONLINE Consulta los cursos disponibles en Tienes en tus manos un texto

TEMARIO CAP INICIAL

TEMARIO CAP INICIAL

TEMARIO CAP INICIAL MERCANC AS BLOQUE FORMATIVO 1 Formaci n avanzada sobre conducci n racional basada en las normas de seguridad 1 1 Caracter sticas de la cadena cinem tica para optimizar su utilizaci n Conocimiento del veh culo curvas de par potencia y consumo espec fico de un motor zona de utilizaci n ptima del cuentarrevoluciones diagramas de cobertura de las relaciones de

Tailings

Tailings

Volume 8Volume 9Volume 1 12 1 Spring 2013 Fall 2010Fall 2011 Tailings evada s Abandoned ine Lands Program sought new wealth from the mineral treasures just waiting to be discovered Some towns like Tonopah and Virginia City have survived to this day Many however were short lived leaving behind ruins mine workings and waste rock dumps as reminders of days gone by Many of the

Lut ce Cr ations 2012

Lut ce Cr ations 2012

117 jingle bell rock 118 falling in love 119 whos afraid of the big bad wolf 120 sorcerers apprentice the 121 blue bird of happiness 122 id like to teach the world to sing 123 ill be home for christmas 126 mary had a little lamb 127 das sandmannchen lied 128 im late 129 guter mond du gehst so stille 130 sound of music the 134 invitation to the dance 136 go on love

Princeton Terrace Club

Princeton Terrace Club

2006 2007 and 2008 The waiting list grew to as many as thirty sophomores in some of these years Often the Club was able to welcome these students as new Terrans in the fall of their junior year In the winter of 2009 sign ins dipped slightly for the first TFC Era 2005 2010 time in more than five years But as Andrew Kinaci 10 recalls