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

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply
Published

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
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,161
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
11
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
    A Framework for Enabling Java Language Stored Procedures in MySQL
    Kevin Tankersley
  • 2. External Language Routines
    • 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?
  • Sample Problems
    • XML validation, XPath querying, XSL transformations
    • 5. Network Access and Consuming web services
    • 6. Encryption and signature algorithms
  • Vendor Solutions
    • 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…
  • The Project
    • 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
  • Demonstration
  • 14. Design Overview
    • 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
  • Java Virtual Machine Linkage
    • 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
  • JVM Linkage Example
  • 23. JVM Thread Linkage Example
  • 24. Design Overview
    • 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
  • Language Changes: Parsing
    • 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
  • Language Changes: Characteristics
  • 33. Design Overview
    • 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
  • Stored Procedure Changes: Lifecycle
    • Lifecycle of a stored procedure
    User sends definition to server
    Server parses definition and creates an object of type sp_head in LEX*
    The sp_head is cached, and the definition is stored in mysql.proc
    User calls the procedure
    Server retrieves sp_head from cache, or reconstructs it
    The execute function of the sp_head is invoked
  • 38. Stored Procedure Changes: Modifications
    • 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
  • Design Overview
    • 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
  • Method Invocation: Overview
    • 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
  • Method Invocation: Bytecode
    • 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
  • Method Invocation: Class Loading
    • 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
  • Method Invocation: Parameters
    • 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
  • Method Invocation: Invocation API
    • 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
  • Project Summary
    • 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
  • Future Work
    • 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
  • References
  • 93. References
  • 94. Questions