Spring Tutorial

Topics: Return statement, Java, Source code Pages: 27 (6001 words) Published: April 4, 2013
Spring Framework Tutorial
Isabelle Muszynski 15 April 2003

Chapter 1

This tutorial covers the main packages in the Spring Framework. For full details, we refer you to Rod Johnson’s book, Expert One-on-One J2EE Design and Development, published by Wrox Press in 2002. The book’s ISBN number is 1-86100-784-1. The code for the Spring Framework is contained in package com.interface21. We provide UML diagrams for the subpackages, as well as code samples.


Setting up for the samples

The samples have been written using the MySQL database (www.mysql.com), Tomcat (jakarta.apache.org/tomcat) and JBoss(www.jboss.org). We refer you to these web sites for setting up the environment correctly. In MySQL, create a database named test, a user test with password test, and grant user test all rights: grant all on test.* to test@localhost identified by ’test’; If you use a different database, read the comments at the top of the samples files, they will direct you to the spots in the code you will have to change for your database.


Building the tutorials

The tutorials can be built using the provided Ant script (you can get ant at http://jakarta.apache.org/ant). You may need to edit the build.properties file to set paths correctly for your system.


Running the tutorials

We provide a shell script, runtest.sh, and a batch file, runtest.bat, for running a single tutorial. You may need to edit these files to set the paths correctly.


Chapter 2

The JDBC Package
Data access is taken care of in the com.interface21.jdbc package and its subpackages. These packages are non-intrusive, and so you can use them separately from the rest of the framework to implement persistence in your application. There are two main packages, com.interface21.jdbc.core, which implements low-level persistence, and the high-level com.interface21.jdbc.object, which presents an object-oriented view of the low-level package.


Exception Handling

Clients of the package - i.e. you, as the developer - should not have to concern themselves with SQLExceptions, as these will not be very informative to your users. Also, because SQLExceptions are checked exceptions, they have to be caught. The Spring Framework takes a different approach : checked SQLExceptions are converted to unchecked DataAccessException and its subclasses. A number of pathological conditions are recognized, through the SQLExceptionTranslater interface and its implementing classes, and will result in subclasses of DataAccessException being thrown. For example, a unique key integrity violation will cause a DataIntegrityViolationException to be thrown. It is up to you, as the developer, to catch this exception – if your code can recover from it – or not, thereby letting it percolate upwards.



The com.interface21.jdbc.object Package

The com.interface21.jdbc.object package provides a hig-level, JDO-like environment for persistence. Queries, updates and stored procedures are modeled as reusable, threadsafe objects. The abstract RdbmsOperation class is the root of the hierarchy. It holds a javax.sql.DataSource and a SQL string as instance variables, and allows bind parameters to be declared. Before being used, a RdbmsOperation must be compiled. The exact meaning of the compilation operation varies between subclasses. After compilation, no more parameters can be added, but the operation can be performed repeatedly. Parameters are declared using the declareParameter() method. The abstract SqlOperation class extends RdbmsOperation and is used as a base class for queries and updates. The compilation process checks that the number of parameters matches the number of parameter placeholders in the SQL string. The SqlQuery class is used for queries; it requires the user to implement method newResultReader, which should return a ResultReader for the returned ResultSet. The MappingSqlQuery class is a subclass of SqlQuery which provides a default...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Tutorial Centers Essay
  • ACCG399 Tutorial 1 Essay
  • spring awakening Essay
  • Spring and Help Essay
  • Essay about Spring Day
  • Springs- Hookes Law Lab Essay
  • Blue Mountain Spring Water Essay
  • Final Paper Spring and Summer

Become a StudyMode Member

Sign Up - It's Free