0
MySQL/JVM<br />A Framework for Enabling Java Language Stored Procedures in MySQL<br />Kevin Tankersley<br />
External Language Routines<br /><ul><li>Stored procedure languages typically specialized for data access
The available function libraries typically focus on numeric, date, time, and string functions
How to handle more unusual situations?</li></li></ul><li>Sample Problems<br /><ul><li>XML validation, XPath querying, XSL ...
Network Access and Consuming web services
Encryption and signature algorithms</li></li></ul><li>Vendor Solutions<br /><ul><li>Oracle allows stored procedures to be ...
Microsoft SQL Server allows stored procedures to be written in .NET
PostgreSQL allows procedures to be written in several external languages, including Java
No solution for MySQL, though…</li></li></ul><li>The Project<br /><ul><li>Add support to MySQL for creating Java stored pr...
Use MySQL as the database because it is open source and widely used
Use Java as the language because it is multi-platform and widely known
Design for compliance with ISO standards
ISO 9075-13 Defines the syntax and behavior of Java routines in the DB</li></li></ul><li>Demonstration<br />
Design Overview<br /><ul><li>Four major tasks to accomplish:
Link the project to the Java Virtual Machine
Modify the MySQL language syntax to accommodate Java routines
Modify classes, tables, and support libraries to recognize Java routines
Build a framework for loading classes and invoking methods at runtime</li></li></ul><li>Java Virtual Machine Linkage<br />...
Platform for making native calls between Java runtime and C/C++
Supports callbacks from Java code, or JVM invocation from C/C++
Requires the shared library jvm.dll and the header jni.h at compile time
Requires the full Java Runtime Environment on the path at run time</li></li></ul><li>JVM Linkage Example<br />
JVM Thread Linkage Example<br />
Design Overview<br /><ul><li>Four major tasks to accomplish:
Link the project to the Java Virtual Machine
Modify the MySQL language syntax to accommodate Java routines
Modify classes, tables, and support libraries to recognize Java routines
Upcoming SlideShare
Loading in...5
×

MySQL/JVM

1,195

Published on

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,195
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "MySQL/JVM"

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

    Clipping is a handy way to collect important slides you want to go back to later.

×