Title: Jakarta%20-%20Torque
1Jakarta - Torque
- CIS 764 Presentation
- Deepti Gupta
-
2Overview
- Object Relational Mapping
- Torque overview
- Configuring Torque
- Invoking Torque
- Sample application
- Conclusion
- References
3Object Relational Mapping
- The process of transforming between object and
relational modeling approaches. - Technique of mapping relational rows from a
relational database to objects in memory where
they can be manipulated by an object-oriented
program.
4Jakarta - Torque
- Torque is a persistence layer.
- Torque consists of two main components
- Generator - The Torque generator uses a single
XML database schema file to generate the SQL for
the target database and Torque's Peer-based
object relational model. - Runtime - The Torque runtime is required in order
to compile and use the classes produced by the
generator.
5Supported RDBMS
RDBMS Driver
MS Access sun.jdbc.odbc.JdbcOdbcDriver
MS SQL com.microsoft.jdbc.sqlserver.SQLServerDriver
MySQL org.gjt.mm.mysql.Driver
Oracle oracle.jdbc.driver.OracleDriver
6Configuring Torque
- 3 configuration files
- Torque Generator properties build.properties
- Torque database schema torque-schema.xml
- Torque runtime properties torque.properties
71. Build.properties
Property Description
Basic Properties Basic Properties
torque.project The name of the project Torque will generate code for.
torque.database The target database.
Database Settings Database Settings
torque.database.createUrl The JDBC URL that Torque can use to create and drop databases if instructed to do so.
torque.database.driver The JDBC database driver to use when connecting to your database.
torque.database.user The administrative username that has sufficient privileges to create and drop databases and tables that Torque executes at build time.
torque.database.password The administrative password for the supplied username.
82. Database Schema
ltdatabase name"bookstore" defaultIdMethod"id
broker"gt lttable name"book" description"Book
Table"gt ltcolumn name"book_id"
required"true" primaryKey"true"
type"INTEGER" description"Book Id"/gt
ltcolumn name"author_id"
required"true" type"INTEGER"
description"Foreign Key Author"/gt
ltforeign-key foreignTable"author"gt
ltreference local"author_id"
foreign"author_id"/gt lt/foreign-keygt
lt/tablegt lt/databasegt
93. Torque.properties
- torque.database.default bookstore
- torque.bookstore.connection.driver
oracle.jdbc.driver.OracleDriver - torque.bookstore.connection.url
jdbcoraclethin_at_oracle.cis.ksu.edu1521oracle - torque.bookstore.connection.user user
- torque.bookstore.connection.password password
- log4j.rootCategory DEBUG
- log4j.appender.default org.apache.log4j.FileAppe
nder - log4j.appender.default.file ./torque.log
10Invoking Torque
- Generating the object model
- Use Ant along with the build.xml file to
generate the object model - Creating the SQL databases and tables
- The command ant create-db can be used for this
purpose - Generating HTML docs
- The command ant doc can be used for this purpose
11Docs generated by Torque
12Torque Object Map
- Torque generates four classes for each table
defined in the database schema. - E.g. Book
- BaseBook.java Torque-generated logic
- BaseBookPeer.java Torque-generated logic
- Book.java Empty sub classes
- BookPeer.java Empty sub classes
- Adding Functionality to the Object Model
- The sub classes are used to extend the object
model. - E.g. Add toString() functions to the model
13Torque Application
- Inserting rows
- Book effective new Book()
- effective.setTitle( Effective Java ")
- effective.save()
- Selecting rows
- Criteria crit new Criteria()
- crit.add(BookPeer.title, "Effective Java")
- List books BookPeer.doSelect(crit)
- Deleting rows
- Criteria crit new Criteria()
- crit.add(BookPeer.title, "Effective Java")
- BookPeer.doDelete(crit)
-
14Conclusion
- Learning curve
- No SQL statements
- Relational database access in object oriented way
15References
- http//db.apache.org/torque/index.html
- User Guide
- Torque tutorial
- Downloads
- Miscellaneous Information
- http//www.developer.com/java/other/article.php/10
936_1457081_1 - Using the Torque Object Mapper