java in the database
play

Java In the Database Rick Hillegas Apache Derby August 28, 2006 - PowerPoint PPT Presentation

Java In the Database Rick Hillegas Apache Derby August 28, 2006 General Overview Derby Overview User Code in the Database SQL Support Demo Overview Demo SQL Derby Overview Lightweight, 0-admin, pure Java database


  1. Java In the Database Rick Hillegas Apache Derby August 28, 2006

  2. General Overview ● Derby Overview ● User Code in the Database ● SQL Support ● Demo Overview ● Demo SQL

  3. Derby Overview ● Lightweight, 0-admin, pure Java database ● Follows ANSI-SQL and JDBC standards ● Usage: embedded or client/server

  4. User Code in the Database ● Integrity ● Performance ● Integration

  5. User Code in the Database: Integrity ● Push business logic close to data ● Enforce business rules in one place

  6. User Code in the Database: Performance ● Filter out noise early on ● Reduce query execution time ● Reduce network traffic

  7. User Code in the Database: Integration ● Re-use existing freeware libraries ● Join with external data

  8. SQL Support: ANSI SQL Support ● User-written functions ● User-written procedures ● [User-written aggregates] ● [User-written function tables] ● Various languages, including SQL/PSM

  9. SQL Support: SQL/PSM ● Procedural language ● Vendor-specific dialects and extensions

  10. SQL Support: Java vs. SQL/PSM ● More expressive ● Better exception handling ● Portable datatypes ● Large body of available freeware ● Better tool support, including debuggers ● Same code can run in client, middle tier, and server

  11. SQL Support: Some Databases that Run User-written Java Code ● Oracle ● DB2 ● Sybase ● Postgres ● Derby

  12. SQL Support: Derby vs. Other Databases ● User code runs on same VM as SQL byte code ● No process/thread switching

  13. Demo Overview: Concepts ● Educational testing application ● Students, Schools, Tests, Questions, Takings

  14. Demo Overview: Classpath ● You can just put the user-written, server-side code on the server classpath ● But this demo loads a user-written, server- side jar file into the database ● The demo also loads Jakarta commons- math-1.1.jar freeware into the database

  15. Demo Overview: Functions ● weighQuestion ● scoreQuestion ● computeAge ● getMedianTestScore

  16. Demo Overview: Procedures ● ScoreTestTaking

  17. Demo Overview: Triggers ● Compute score when Student finishes taking Test

  18. Demo Overview: Actions ● Create schema objects ● Load user-written code into database ● Populate tables ● Make Students take tests ● Pose queries

  19. Demo SQL: Load Jar File ● From com.scores.data.Database.createSchema() call sqlj.install_jar ( '/sw/demo/scores/jars/scores-server.jar', 'APP.SCORES_SERVER', 0 )

  20. Demo SQL: Wire-up a Classpath ● From com.scores.data.Database.createSchema() call syscs_util.syscs_set_database_property ( 'derby.database.classpath', 'APP.SCORES_SERVER:APP.APACHE_COMMONS_MATH' )

  21. Demo SQL: Create Simple Function ● From com.scores.data.Database.createSchema() create function computeAge ( birthday date) returns int language java parameter style java no sql external name 'com.scores.proc.Functions.computeAge'

  22. Demo SQL: Create Function that Reads Data ● From com.scores.data.Database.createSchema() create function getMedianTestScore ( testID int ) returns double language java parameter style java reads sql data external name 'com.scores.proc.Functions.getMedianTestScore'

  23. Demo SQL: Create Procedure ● From com.scores.data.Database.createSchema() create procedure ScoreTestTaking ( in takingID int ) language java parameter style java modifies sql data external name 'com.scores.proc.Procedures.ScoreTestTaking'

  24. Demo SQL: Create a Procedure-invoking Trigger ● From com.scores.data.Database.createSchema() create trigger ScoreTestWhenDone after update of takingDate on TestTaking referencing new as testTakingRow for each row mode db2sql call ScoreTestTaking( testTakingRow.takingID )

  25. Demo SQL: Firing a User-written Procedure from a Trigger ● From com.scores.data.Data.finishTest() update TestTaking set takingDate = ? where takingID = ?

  26. Demo SQL: Faking a User-written Aggregate ● Invokes freeware from Jakarta commons jarball ● See com.scores.proc.Functions.getMedianTestScore()

  27. Demo SQL: Pushing Work into the Database ● From com.scores.proc.Procedures.ScoreTestTaking() select st.lastName, st.firstName from School sc, Student st, LastTaking lt, QuestionTaking qt, Question q where q.questionName = ? and sc.schoolID = ? and q.questionID = qt.questionID and sc.schoolID = st.schoolID and lt.testID = q.testID and lt.studentID = st.studentID and lt.takingID = qt.takingID and scoreQuestion( q.difficulty, q.numberOfChoices, q.correctChoice, qt.actualChoice ) < weighQuestion( q.difficulty ) order by st.lastName, st.firstName

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend