JATO Tutorial
|
The remainder of the tutorial assumes the presence of a sample database. The use of the sample database is solely a prerequisite to this specific tutorial so that we can introduce you to some additional JATO features. There is no requirement for a JATO application to access an RDBMS. Even if you are designing an application to use a RDBMS, you will not need to "create" the database as we are doing here as an unavoidable tutorial prerequisite. Please follow the instructions and install the sample database before proceeding any further.
hsqldb.jar
)
from one of the following locations. You will need version 1.6.1 or higher:
http://sourceforge.net/projects/hsqldb/
http://prdownloads.sourceforge.net/hsqldb/hsqldb.jar
(direct link)
hsqldb.jar
file into the tutorial application lib
directory./JatoTutorial/WEB-INF/lib/hsqldb.jar
db
directory to hold the sample database data./JatoTutorial/WEB-INF/db
northwind.script
, northwind.properties
,
and northwind.data
) from the /extra/db
directory
to your /JatoTutorial/WEB-INF/db
directory.
/JatoTutorial/WEB-INF/db/northwind.script
/JatoTutorial/WEB-INF/db/northwind.properties
/JatoTutorial/WEB-INF/db/northwind.data
Your directory structure should now appear as follows:
/JatoTutorial |
Main working directory |
/jatotutorial |
Document directory for jatotutorial application |
/module1 |
Document directory for module1 module (jsp files here) |
/WEB-INF |
Web application information |
jato.tld |
JATO tag library descriptor file |
web.xml |
Deployment descriptor |
/classes |
Application classes |
/jatotutorial |
Directory for jatotutorial package classes |
/module1
|
Directory for module1 package classes |
/lib |
Additional application classes (jar files) |
hsqldb.jar |
Hypersonic SQL jar file (for sample database) |
jato-1_2.jar |
JATO jar file |
/db |
Database files |
northwind.script |
Sample database file |
northwind.properties
|
Sample database file |
northwind.data |
Sample database file |
SQLConnectionManagerImpl.java
file. As indicated below,
add the code to load the Hypersonic SQL JDBC driver. Note, some parts of the
template code have been omitted here. Any omitted sections are not pertinent
to this example:
package jatotutorial.module1; ... public class SQLConnectionManagerImpl extends SQLConnectionManagerBase { public SQLConnectionManagerImpl() { super(); } static { try { Class.forName("org.hsqldb.jdbcDriver"); } catch(ClassNotFoundException e) { e.printStackTrace(); } // Turn off JNDI lookup (turn on DriverManager use) setUsingJNDI(false); } } |
JatoTutorialServletBase.java
file as indicated below.
As described by the comment in the source, this step would not be necessary
if we weren't using the embedded Hypersonic SQL database for the tutorial.
Note, some parts of the template code have been omitted here. Any omitted
sections are not pertinent to this example:
package jatotutorial; ... public class JatoTutorialServletBase extends ApplicationServletBase { ... public void init(ServletConfig config) throws ServletException { super.init(config); // These objects are assumed to exist in each application's package MODEL_TYPE_MAP=new ModelTypeMapImpl(); SQL_CONNECTION_MANAGER=new SQLConnectionManagerImpl(); // NOTE: This code is only necessary when using the Hypersonic // SQL embedded database driver; it requires a fully qualified // path name to the database files. Normally, one would specify // the interface-implementation directly within the // SQLConnectionManagerImpl class. String path=config.getServletContext().getRealPath( "/WEB-INF/db"); SQLConnectionManagerImpl.addDataSourceMapping( "jdbc/NorthwindDataSource", "jdbc:hsqldb:" + path+ "/northwind"); } ... } |
|