1 / 15

Jakarta - Torque

Jakarta - Torque. CIS 764 Presentation Deepti Gupta. Overview. Object Relational Mapping Torque overview Configuring Torque Invoking Torque Sample application Conclusion References. Object Relational Mapping.

jael
Download Presentation

Jakarta - Torque

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  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

  8. 2. Database Schema <database name="bookstore" defaultIdMethod="idbroker"> <table name="book" description="Book Table"> <column name="book_id" required="true" primaryKey="true" type="INTEGER" description="Book Id"/> <column name="author_id" required="true" type="INTEGER" description="Foreign Key Author"/> <foreign-key foreignTable="author"> <reference local="author_id" foreign="author_id"/> </foreign-key> </table> </database>

  9. 3. Torque.properties • torque.database.default = bookstore • torque.bookstore.connection.driver = oracle.jdbc.driver.OracleDriver • torque.bookstore.connection.url= jdbc:oracle:thin:@oracle.cis.ksu.edu:1521:oracle • torque.bookstore.connection.user = user • torque.bookstore.connection.password = password • log4j.rootCategory = DEBUG • log4j.appender.default = org.apache.log4j.FileAppender • 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/10936_1457081_1 - Using the Torque Object Mapper

More Related