Java Runtime Hosting
HO-S-1 Integrating Java Objects with Virtuoso
Using Java Objects to extend Virtuoso via User Defined Types.
Overview
The following tutorial demonstrates how Virtuoso can be extended through the use of Java to create User Defined Types (UDTs), Stored Procedures, and Functions. This is an enhancement of its Object-Relational Database functionality.
The demonstrations in this section highlight transparent integration (hosting) between Virtuoso and the Java Runtime Environment.
Prerequisites
The following prerequisites ensure the usability of these tutorial demos on any platform with a Java Runtime environment:
- Java Runtime (J2EE 1.2 and Higher)
- Java SDK (if you seek to write your own Objects for integration with Virtuoso)
- Virtuoso Universal Server with Java Runtime Hosting
Tutorial Example
The following tutorial shows how Java Classes are used to create User Defined Types (UDTs), Stored Procedures, and Functions in Virtuoso.
Please follow the steps below to maximize the value of this tutorial:
- Click on the "Set Initial State" link which registers the Java classes used in this demo with Virtuoso. Click on the "ho_s_1.sql" link to see the code behind this step
- Click on the "Run" links to actually experience the demo
Demo Breakdown
- "ho_s_1.sql" performs the following steps
- Registers the "MyFinances" and "Point" Classes with Virtuoso as UDTs. Click on the "MyFinances.java" and "Point.java" links to see the JAVA source code
- Creates the conventional SQL table "Employee"
- Creates the Object-Relational table "Supplier" that includes a column named "Location" that is of Type "Point" (which is a UDT)
- Populates each of the newly created tables with data
- Creates the "distance" stored procedure which uses UDT methods to calculate the distance between points.
- "vsp1.vsp" uses the static method "tax" of the "MyFinances" class to compute the payroll tax values for each employee via the "salary" column (like a SQL function would).
- "vsp2.vsp" uses the "distance" method of the UDT based column "location" to test for distance values less than "3". The distance values are return values from the "Point" UDT. Note that "Point" class is computing the distance between two arbitrary points
- "vsp3.vsp" is a variation of the previous demo, with the UDT based column "location" being used to access and conditionally test the values of data member "x" (shown in "Point.java" as 0)
- "vsp4.vsp" is another variation of a query on the "Supplier" table, in this particular case the query uses a Stored Procedure (see definition in "ho_s_2.sql") to filter its result set. It achieves this by using data member values "x" and "y" from column "location", and the arbitrary values 1 & 2 as input parameters for the Stored Procedure "distance". It then tests the return values for those less than 3.
In order to run this example you need start tomcat.
In order to run this example you need Java Runtime Hosting Enabled.
| View the source | Action |
|---|---|
| 1. ho_s_1.sql | Set the initial state |
| 2. Point.java | |
| 3. my_finances.java | |
| 4. vsp1.vsp | Run |
| 5. vsp2.vsp | Run |
| 6. vsp3.vsp | Run |
| 7. vsp4.vsp | Run |
OpenLink Home
Technical Support