Your SlideShare is downloading. ×
0
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
MySQL/JVM
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

MySQL/JVM

1,192

Published on

A presentation I gave to summarize the project work that I did for my Masters

A presentation I gave to summarize the project work that I did for my Masters

Published in: Career
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,192
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. MySQL/JVM<br />A Framework for Enabling Java Language Stored Procedures in MySQL<br />Kevin Tankersley<br />
  • 2. External Language Routines<br /><ul><li>Stored procedure languages typically specialized for data access
  • 3. The available function libraries typically focus on numeric, date, time, and string functions
  • 4. How to handle more unusual situations?</li></li></ul><li>Sample Problems<br /><ul><li>XML validation, XPath querying, XSL transformations
  • 5. Network Access and Consuming web services
  • 6. Encryption and signature algorithms</li></li></ul><li>Vendor Solutions<br /><ul><li>Oracle allows stored procedures to be written in Java
  • 7. Microsoft SQL Server allows stored procedures to be written in .NET
  • 8. PostgreSQL allows procedures to be written in several external languages, including Java
  • 9. No solution for MySQL, though…</li></li></ul><li>The Project<br /><ul><li>Add support to MySQL for creating Java stored procedures
  • 10. Use MySQL as the database because it is open source and widely used
  • 11. Use Java as the language because it is multi-platform and widely known
  • 12. Design for compliance with ISO standards
  • 13. ISO 9075-13 Defines the syntax and behavior of Java routines in the DB</li></li></ul><li>Demonstration<br />
  • 14. Design Overview<br /><ul><li>Four major tasks to accomplish:
  • 15. Link the project to the Java Virtual Machine
  • 16. Modify the MySQL language syntax to accommodate Java routines
  • 17. Modify classes, tables, and support libraries to recognize Java routines
  • 18. Build a framework for loading classes and invoking methods at runtime</li></li></ul><li>Java Virtual Machine Linkage<br /><ul><li>Java Native Interface
  • 19. Platform for making native calls between Java runtime and C/C++
  • 20. Supports callbacks from Java code, or JVM invocation from C/C++
  • 21. Requires the shared library jvm.dll and the header jni.h at compile time
  • 22. Requires the full Java Runtime Environment on the path at run time</li></li></ul><li>JVM Linkage Example<br />
  • 23. JVM Thread Linkage Example<br />
  • 24. Design Overview<br /><ul><li>Four major tasks to accomplish:
  • 25. Link the project to the Java Virtual Machine
  • 26. Modify the MySQL language syntax to accommodate Java routines
  • 27. Modify classes, tables, and support libraries to recognize Java routines
  • 28. Build a framework for loading classes and invoking methods at runtime</li></li></ul><li>Language Changes: Parsing<br /><ul><li>Statement Parsing
  • 29. MySQL uses the GNU Bison parser
  • 30. Parser reads user query and creates a parse tree descriptor of type LEX*
  • 31. Server libraries use the classes and data in LEX* to carry out the request
  • 32. Current stored procedure language compliant with ISO standard</li></li></ul><li>Language Changes: Characteristics<br />
  • 33. Design Overview<br /><ul><li>Four major tasks to accomplish:
  • 34. Link the project to the Java Virtual Machine
  • 35. Modify the MySQL language syntax to accommodate Java routines
  • 36. Modify classes, tables, and support libraries to recognize Java routines
  • 37. Build a framework for loading classes and invoking methods at runtime</li></li></ul><li>Stored Procedure Changes: Lifecycle<br /><ul><li>Lifecycle of a stored procedure</li></ul>User sends definition to server<br />Server parses definition and creates an object of type sp_head in LEX*<br />The sp_head is cached, and the definition is stored in mysql.proc<br />User calls the procedure<br />Server retrieves sp_head from cache, or reconstructs it<br />The execute function of the sp_head is invoked<br />
  • 38. Stored Procedure Changes: Modifications<br /><ul><li>Add columns to mysql.proc
  • 39. Alter procedure definition code
  • 40. Alter class sp_head
  • 41. Change structure st_chistics
  • 42. Change execution functions to recognize Java routines</li></li></ul><li>Design Overview<br /><ul><li>Four major tasks to accomplish:
  • 43. Link the project to the Java Virtual Machine
  • 44. Modify the MySQL language syntax to accommodate Java routines
  • 45. Modify classes, tables, and support libraries to recognize Java routines
  • 46. Build a framework for loading classes and invoking methods at runtime</li></li></ul><li>Method Invocation: Overview<br /><ul><li>Necessary Subsystems:
  • 47. A system for storing compiled Java code
  • 48. A classloading mechanism to locate and define classes at runtime
  • 49. A parameter translation API to convert MySQL data types to JVM data types
  • 50. A method invocation API to call the relevant class method </li></li></ul><li>Method Invocation: Bytecode<br /><ul><li>Best place for the bytecode is in the database itself
  • 51. More secure: No need to give developers file system access
  • 52. More manageable: Easier for developers and DBAs to track installed libraries
  • 53. More portable: Paths, environment variables, file permissions vary between platforms
  • 54. New Tables
  • 55. Mysql.jclass: Class files
  • 56. Mysql.jmethod: Method descriptions
  • 57. Mysql.jresource: Other resources</li></li></ul><li>Method Invocation: Class Loading<br /><ul><li>Standard loaders only know how to find classes on the file system
  • 58. Create a custom class loader that knows how to get classes from DB
  • 59. Need to link custom loader to DB
  • 60. Using JDBC is problematic
  • 61. Solution: Use JNI Callbacks
  • 62. Create a server function get_jclass to access mysql.jclass through native table handlers
  • 63. Use a native method in the class loader
  • 64. Use JNI to link the native method with the get_jclass function at run time</li></li></ul><li>Method Invocation: Parameters<br /><ul><li>MySQL and JVM use different data types
  • 65. Created JParam API to manage conversions between MySQL types and JVM types
  • 66. Numerics:
  • 67. Need to map MySQL types to Java types of equal or greater width (e.g. TINYINT to byte)
  • 68. Runtime checks for unsigned overflow
  • 69. Strings:
  • 70. MySQL: Support for many encodings
  • 71. Java: Uses only UTF-16 Unicode</li></li></ul><li>Method Invocation: Invocation API<br /><ul><li>Created class MyJThread to tie class loading, parameters, and invocation together
  • 72. When Created:
  • 73. Attaches to JVM
  • 74. Locates bytecode for class loader
  • 75. Defines class loader
  • 76. When Called:
  • 77. Parse method signature
  • 78. Locate bytecode for entry class
  • 79. Define entry class with class loader
  • 80. Translate parameters to JVM types
  • 81. Invoke method on entry class
  • 82. Save return value in MySQL context</li></li></ul><li>Project Summary<br /><ul><li>Successfully added all elements necessary to create Java routines in MySQL
  • 83. Framework to link MySQL to JVM
  • 84. Standards-compliant changes to the language
  • 85. Modifications to existing elements of stored procedure execution
  • 86. New classes to support native class loading, parameter translation, and method invocation</li></li></ul><li>Future Work<br /><ul><li>Additional features to add:
  • 87. Role-based security model for JVM resources
  • 88. Fully native JDBC Driver
  • 89. New server configuration variables
  • 90. A bytecode cache
  • 91. User-defined types
  • 92. More data type translations</li></li></ul><li>References<br />
  • 93. References<br />
  • 94. Questions<br />

×