-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first step to support stored procedures
Support for stored procedures added with tests for MySQL. The tests are taken from http://docs.oracle.com/javase/tutorial/jdbc/basics/storedprocedures.html The out parameters can not be renamed to Elasticsearch field names right now, this will be done as a followup.
- Loading branch information
Showing
16 changed files
with
221 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...elasticsearch/river/jdbc/strategy/simple/storedprocedure/StoredProcedureJavaDBSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.xbib.elasticsearch.river.jdbc.strategy.simple.storedprocedure; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
public class StoredProcedureJavaDBSample { | ||
|
||
public static void showSuppliers(ResultSet[] rs) | ||
throws SQLException { | ||
|
||
Connection con = DriverManager.getConnection("jdbc:default:connection"); | ||
Statement stmt = null; | ||
|
||
String query = | ||
"select SUPPLIERS.SUP_NAME, " + | ||
"COFFEES.COF_NAME " + | ||
"from SUPPLIERS, COFFEES " + | ||
"where SUPPLIERS.SUP_ID = " + | ||
"COFFEES.SUP_ID " + | ||
"order by SUP_NAME"; | ||
|
||
stmt = con.createStatement(); | ||
rs[0] = stmt.executeQuery(query); | ||
} | ||
|
||
public static void getSupplierOfCoffee(String coffeeName, String[] supplierName) | ||
throws SQLException { | ||
|
||
Connection con = DriverManager.getConnection("jdbc:default:connection"); | ||
PreparedStatement pstmt = null; | ||
ResultSet rs = null; | ||
|
||
String query = | ||
"select SUPPLIERS.SUP_NAME " + | ||
"from SUPPLIERS, COFFEES " + | ||
"where " + | ||
"SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + | ||
"and ? = COFFEES.COF_NAME"; | ||
|
||
pstmt = con.prepareStatement(query); | ||
pstmt.setString(1, coffeeName); | ||
rs = pstmt.executeQuery(); | ||
|
||
if (rs.next()) { | ||
supplierName[0] = rs.getString(1); | ||
} else { | ||
supplierName[0] = null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...sources/org/xbib/elasticsearch/river/jdbc/strategy/simple/mysql/create-suppliertables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
drop table IF EXISTS SUPPLIERS | ||
drop table IF EXISTS COFFEES | ||
drop procedure IF EXISTS SHOW_SUPPLIERS | ||
create table SUPPLIERS (SUP_ID integer NOT NULL, SUP_NAME varchar(40) NOT NULL, STREET varchar(40) NOT NULL, CITY varchar(20) NOT NULL, STATE char(2) NOT NULL, ZIP char(5), PRIMARY KEY (SUP_ID)); | ||
create table COFFEES (COF_NAME varchar(32) NOT NULL, SUP_ID int NOT NULL, PRICE numeric(10,2) NOT NULL, SALES integer NOT NULL, TOTAL integer NOT NULL, PRIMARY KEY (COF_NAME), FOREIGN KEY (SUP_ID) REFERENCES SUPPLIERS (SUP_ID)); | ||
insert into SUPPLIERS values(49, 'Superior Coffee', '1 Party Place', 'Mendocino', 'CA', '95460') | ||
insert into SUPPLIERS values(101, 'Acme, Inc.', '99 Market Street', 'Groundsville', 'CA', '95199') | ||
insert into SUPPLIERS values(150, 'The High Ground', '100 Coffee Lane', 'Meadows', 'CA', '93966') | ||
insert into COFFEES values('Colombian', 00101, 7.99, 0, 0) | ||
insert into COFFEES values('French_Roast', 00049, 8.99, 0, 0) | ||
insert into COFFEES values('Espresso', 00150, 9.99, 0, 0) | ||
insert into COFFEES values('Colombian_Decaf', 00101, 8.99, 0, 0) | ||
insert into COFFEES values('French_Roast_Decaf', 00049, 9.99, 0, 0) | ||
create procedure SHOW_SUPPLIERS() begin select SUPPLIERS.SUP_NAME, COFFEES.COF_NAME from SUPPLIERS, COFFEES where SUPPLIERS.SUP_ID = COFFEES.SUP_ID order by SUP_NAME; end | ||
create procedure GET_SUPPLIER_OF_COFFEE(IN coffeeName varchar(32), OUT supplierName varchar(40)) begin select SUPPLIERS.SUP_NAME into supplierName from SUPPLIERS, COFFEES where SUPPLIERS.SUP_ID = COFFEES.SUP_ID and coffeeName = COFFEES.COF_NAME; select supplierName; end |
3 changes: 3 additions & 0 deletions
3
...sources/org/xbib/elasticsearch/river/jdbc/strategy/simple/mysql/delete-suppliertables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
drop table COFFEES | ||
drop table SUPPLIERS | ||
drop procedure SHOW_SUPPLIERS |
12 changes: 12 additions & 0 deletions
12
src/test/resources/org/xbib/elasticsearch/river/jdbc/strategy/simple/mysql/river-6.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"jdbc" : { | ||
"url" : "jdbc:mysql://localhost:3306/test", | ||
"user" : "", | ||
"password" : "", | ||
"sql" : "select * from products", | ||
"schedule" : "0/5 0-59 0-23 ? * *", | ||
"bulk_flush_interval" : "1s", | ||
"index" : "my_jdbc_river_index", | ||
"type" : "my_jdbc_river_type" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/resources/org/xbib/elasticsearch/river/jdbc/strategy/simple/mysql/river-7.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"jdbc" : { | ||
"url" : "jdbc:mysql://localhost:3306/test", | ||
"user" : "", | ||
"password" : "", | ||
|
||
"sql" : [ | ||
{ | ||
"statement" : "select message from logs where {fn timestampdiff(SQL_TSI_HOUR, modified ,?)} > 0", | ||
"parameter" : [ "$now" ] | ||
} | ||
], | ||
"schedule" : "0/5 0-59 0-23 ? * *", | ||
"index" : "my_jdbc_river_index", | ||
"type" : "my_jdbc_river_type", | ||
"timezone" : "Asia/Jerusalem", | ||
"locale" : "iw_IL" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/resources/org/xbib/elasticsearch/river/jdbc/strategy/simple/mysql/river-8.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"jdbc" : { | ||
"url" : "jdbc:mysql://localhost:3306/test", | ||
"user" : "", | ||
"password" : "", | ||
"sql" : [ | ||
{ | ||
"callable" : true, | ||
"statement" : "{call SHOW_SUPPLIERS()}" | ||
} | ||
], | ||
"index" : "my_jdbc_river_index", | ||
"type" : "my_jdbc_river_type" | ||
} | ||
} |
Oops, something went wrong.