MySQL/JVM
Upcoming SlideShare
Loading in...5
×
 

MySQL/JVM

on

  • 1,532 views

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

Statistics

Views

Total Views
1,532
Views on SlideShare
1,528
Embed Views
4

Actions

Likes
0
Downloads
11
Comments
0

2 Embeds 4

http://www.slideshare.net 2
http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MySQL/JVM MySQL/JVM Presentation Transcript

    • MySQL/JVM
      A Framework for Enabling Java Language Stored Procedures in MySQL
      Kevin Tankersley
    • External Language Routines
      • 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?
    • Sample Problems
      • XML validation, XPath querying, XSL transformations
      • Network Access and Consuming web services
      • Encryption and signature algorithms
    • Vendor Solutions
      • Oracle allows stored procedures to be written in Java
      • 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…
    • The Project
      • Add support to MySQL for creating Java stored procedures
      • 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
    • Demonstration
    • Design Overview
      • 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
    • Java Virtual Machine Linkage
      • Java Native Interface
      • 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
    • JVM Linkage Example
    • JVM Thread Linkage Example
    • Design Overview
      • 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
    • Language Changes: Parsing
      • Statement Parsing
      • MySQL uses the GNU Bison parser
      • Parser reads user query and creates a parse tree descriptor of type LEX*
      • Server libraries use the classes and data in LEX* to carry out the request
      • Current stored procedure language compliant with ISO standard
    • Language Changes: Characteristics
    • Design Overview
      • 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
    • 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
    • Stored Procedure Changes: Modifications
      • Add columns to mysql.proc
      • Alter procedure definition code
      • Alter class sp_head
      • Change structure st_chistics
      • Change execution functions to recognize Java routines
    • Design Overview
      • 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
    • Method Invocation: Overview
      • Necessary Subsystems:
      • A system for storing compiled Java code
      • A classloading mechanism to locate and define classes at runtime
      • A parameter translation API to convert MySQL data types to JVM data types
      • A method invocation API to call the relevant class method
    • Method Invocation: Bytecode
      • Best place for the bytecode is in the database itself
      • More secure: No need to give developers file system access
      • More manageable: Easier for developers and DBAs to track installed libraries
      • More portable: Paths, environment variables, file permissions vary between platforms
      • New Tables
      • Mysql.jclass: Class files
      • Mysql.jmethod: Method descriptions
      • Mysql.jresource: Other resources
    • Method Invocation: Class Loading
      • Standard loaders only know how to find classes on the file system
      • Create a custom class loader that knows how to get classes from DB
      • Need to link custom loader to DB
      • Using JDBC is problematic
      • Solution: Use JNI Callbacks
      • Create a server function get_jclass to access mysql.jclass through native table handlers
      • Use a native method in the class loader
      • 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
      • Created JParam API to manage conversions between MySQL types and JVM types
      • Numerics:
      • Need to map MySQL types to Java types of equal or greater width (e.g. TINYINT to byte)
      • Runtime checks for unsigned overflow
      • Strings:
      • MySQL: Support for many encodings
      • Java: Uses only UTF-16 Unicode
    • Method Invocation: Invocation API
      • Created class MyJThread to tie class loading, parameters, and invocation together
      • When Created:
      • Attaches to JVM
      • Locates bytecode for class loader
      • Defines class loader
      • When Called:
      • Parse method signature
      • Locate bytecode for entry class
      • Define entry class with class loader
      • Translate parameters to JVM types
      • Invoke method on entry class
      • Save return value in MySQL context
    • Project Summary
      • Successfully added all elements necessary to create Java routines in MySQL
      • Framework to link MySQL to JVM
      • Standards-compliant changes to the language
      • Modifications to existing elements of stored procedure execution
      • New classes to support native class loading, parameter translation, and method invocation
    • Future Work
      • Additional features to add:
      • Role-based security model for JVM resources
      • Fully native JDBC Driver
      • New server configuration variables
      • A bytecode cache
      • User-defined types
      • More data type translations
    • References
    • References
    • Questions