Jakarta%20-%20Torque - PowerPoint PPT Presentation

View by Category
About This Presentation
Title:

Jakarta%20-%20Torque

Description:

Torque runtime properties torque.properties. 1. Build.properties ... effective.setTitle(' Effective Java '); effective.save(); Selecting rows ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 16
Provided by: people5
Category:

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Jakarta%20-%20Torque


1
Jakarta - Torque
  • CIS 764 Presentation
  • Deepti Gupta

2
Overview
  • Object Relational Mapping
  • Torque overview
  • Configuring Torque
  • Invoking Torque
  • Sample application
  • Conclusion
  • References

3
Object 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.

4
Jakarta - 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.

5
Supported 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
6
Configuring Torque
  • 3 configuration files
  • Torque Generator properties build.properties
  • Torque database schema torque-schema.xml
  • Torque runtime properties torque.properties

7
1. 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.
8
2. 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

9
3. 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

10
Invoking 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

11
Docs generated by Torque

12
Torque 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

13
Torque 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)

14
Conclusion
  • Learning curve
  • No SQL statements
  • Relational database access in object oriented way

15
References
  • 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
About PowerShow.com