Skip to content

Commit 556cd30

Browse files
authored
Merge pull request #259 from yahonda/add-test-11g-ojdbc11-workflow
Add ojdbc17, ojdbc11, and ojdbc8 to JDBC driver search list
2 parents 5ea974a + 1a13513 commit 556cd30

9 files changed

Lines changed: 181 additions & 35 deletions

File tree

.github/workflows/jruby_head.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99

1010
runs-on: ubuntu-latest
11-
continue-on-error: true
11+
continue-on-error: false
1212
strategy:
1313
matrix:
1414
ruby: [
@@ -39,6 +39,11 @@ jobs:
3939
4040
steps:
4141
- uses: actions/checkout@v6
42+
- name: Set up Java
43+
uses: actions/setup-java@v4
44+
with:
45+
distribution: oracle
46+
java-version: '21'
4247
- name: Set up Ruby
4348
uses: ruby/setup-ruby@v1
4449
with:
@@ -57,7 +62,7 @@ jobs:
5762
echo "/opt/oracle/instantclient_23_26" >> $GITHUB_PATH
5863
- name: Install JDBC Driver
5964
run: |
60-
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/233/ojdbc11.jar -O ./lib/ojdbc11.jar
65+
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/23261/ojdbc17.jar -O ./lib/ojdbc17.jar
6166
- name: Create database user
6267
run: |
6368
./ci/setup_accounts.sh

.github/workflows/test.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ jobs:
88
build:
99

1010
runs-on: ubuntu-latest
11-
continue-on-error: true
11+
continue-on-error: false
1212
strategy:
1313
matrix:
1414
ruby: [
1515
'4.0',
1616
'3.4',
1717
'3.3',
18-
'3.2'
18+
'3.2',
19+
'jruby-10.0.5.0',
1920
]
2021
env:
2122
ORACLE_HOME: /opt/oracle/instantclient_23_26
@@ -42,6 +43,12 @@ jobs:
4243
4344
steps:
4445
- uses: actions/checkout@v6
46+
- name: Set up Java
47+
if: startsWith(matrix.ruby, 'jruby')
48+
uses: actions/setup-java@v4
49+
with:
50+
distribution: oracle
51+
java-version: '21'
4552
- name: Set up Ruby
4653
uses: ruby/setup-ruby@v1
4754
with:
@@ -61,8 +68,9 @@ jobs:
6168
sudo unzip -qo instantclient-sqlplus-linux.x64-23.26.1.0.0.zip -d /opt/oracle/
6269
echo "/opt/oracle/instantclient_23_26" >> $GITHUB_PATH
6370
- name: Install JDBC Driver
71+
if: startsWith(matrix.ruby, 'jruby')
6472
run: |
65-
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/233/ojdbc11.jar -O ./lib/ojdbc11.jar
73+
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/23261/ojdbc17.jar -O ./lib/ojdbc17.jar
6674
- name: Create database user
6775
run: |
6876
./ci/setup_accounts.sh

.github/workflows/test_11g.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ jobs:
1212
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
1313

1414
runs-on: ubuntu-latest
15-
continue-on-error: true
15+
continue-on-error: false
1616
strategy:
1717
matrix:
1818
ruby: [
1919
'4.0',
2020
'3.4',
2121
'3.3',
22-
'3.2'
22+
'3.2',
23+
'jruby-10.0.5.0',
2324
]
2425
env:
2526
ORACLE_HOME: /opt/oracle/instantclient_21_15
@@ -46,6 +47,12 @@ jobs:
4647
4748
steps:
4849
- uses: actions/checkout@v6
50+
- name: Set up Java
51+
if: startsWith(matrix.ruby, 'jruby')
52+
uses: actions/setup-java@v4
53+
with:
54+
distribution: oracle
55+
java-version: '21'
4956
- name: Set up Ruby
5057
uses: ruby/setup-ruby@v1
5158
with:
@@ -66,20 +73,21 @@ jobs:
6673
sudo unzip -qo instantclient-sdk-linux.x64-21.15.0.0.0dbru.zip -d /opt/oracle
6774
echo "/opt/oracle/instantclient_21_15" >> $GITHUB_PATH
6875
- name: Install JDBC Driver
76+
if: startsWith(matrix.ruby, 'jruby')
6977
run: |
70-
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/233/ojdbc11.jar -O ./lib/ojdbc11.jar
78+
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/23261/ojdbc17.jar -O ./lib/ojdbc17.jar
7179
- name: Configure ORA_TZFILE to match Oracle 11g server
7280
run: |
73-
# Oracle 11g XE uses timezone file v14; Instant Client 21.15 embeds v35.
74-
# This mismatch causes ORA-01805 when ruby-oci8 fetches DATE/TIMESTAMP
81+
# Oracle 11g XE uses timezone file v14; Instant Client 21.15 embeds
82+
# v35. This mismatch causes ORA-01805 when fetching DATE/TIMESTAMP
7583
# values. Copy the v14 files from the 11g container and point the
7684
# Instant Client at them via ORA_TZFILE.
77-
ORACLE_CONTAINER=$(docker ps --filter "ancestor=gvenzl/oracle-xe:11" -q)
78-
sudo mkdir -p /opt/oracle/instantclient_21_15/oracore/zoneinfo
85+
ORACLE_CONTAINER="${{ job.services.oracle.id }}"
86+
sudo mkdir -p "$ORACLE_HOME/oracore/zoneinfo"
7987
docker cp "$ORACLE_CONTAINER":/u01/app/oracle/product/11.2.0/xe/oracore/zoneinfo/timezlrg_14.dat /tmp/timezlrg_14.dat
8088
docker cp "$ORACLE_CONTAINER":/u01/app/oracle/product/11.2.0/xe/oracore/zoneinfo/timezone_14.dat /tmp/timezone_14.dat
81-
sudo mv /tmp/timezlrg_14.dat /opt/oracle/instantclient_21_15/oracore/zoneinfo/
82-
sudo mv /tmp/timezone_14.dat /opt/oracle/instantclient_21_15/oracore/zoneinfo/
89+
sudo mv /tmp/timezlrg_14.dat "$ORACLE_HOME/oracore/zoneinfo/"
90+
sudo mv /tmp/timezone_14.dat "$ORACLE_HOME/oracore/zoneinfo/"
8391
echo "ORA_TZFILE=timezlrg_14.dat" >> $GITHUB_ENV
8492
- name: Create database user
8593
run: |
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: test_11g_ojdbc11
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types: [opened, synchronize, reopened, ready_for_review]
9+
10+
jobs:
11+
build:
12+
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
13+
14+
runs-on: ubuntu-latest
15+
continue-on-error: false
16+
strategy:
17+
matrix:
18+
ruby: [
19+
'jruby-10.0.5.0'
20+
]
21+
env:
22+
ORACLE_HOME: /opt/oracle/instantclient_21_15
23+
LD_LIBRARY_PATH: /opt/oracle/instantclient_21_15
24+
NLS_LANG: AMERICAN_AMERICA.AL32UTF8
25+
TNS_ADMIN: ./ci/network/admin
26+
DATABASE_NAME: XE
27+
TZ: Europe/Riga
28+
DATABASE_SYS_PASSWORD: Oracle18
29+
30+
services:
31+
oracle:
32+
image: gvenzl/oracle-xe:11
33+
ports:
34+
- 1521:1521
35+
env:
36+
TZ: Europe/Riga
37+
ORACLE_PASSWORD: Oracle18
38+
options: >-
39+
--health-cmd healthcheck.sh
40+
--health-interval 10s
41+
--health-timeout 5s
42+
--health-retries 10
43+
44+
steps:
45+
- uses: actions/checkout@v6
46+
- name: Set up Java
47+
uses: actions/setup-java@v4
48+
with:
49+
distribution: oracle
50+
java-version: '21'
51+
- name: Set up Ruby
52+
uses: ruby/setup-ruby@v1
53+
with:
54+
ruby-version: ${{ matrix.ruby }}
55+
- name: Create symbolic link for libaio library compatibility
56+
run: |
57+
sudo ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64 /usr/lib/x86_64-linux-gnu/libaio.so.1
58+
- name: Download Oracle instant client
59+
run: |
60+
wget -q https://download.oracle.com/otn_software/linux/instantclient/2115000/instantclient-basic-linux.x64-21.15.0.0.0dbru.zip
61+
wget -q https://download.oracle.com/otn_software/linux/instantclient/2115000/instantclient-sqlplus-linux.x64-21.15.0.0.0dbru.zip
62+
wget -q https://download.oracle.com/otn_software/linux/instantclient/2115000/instantclient-sdk-linux.x64-21.15.0.0.0dbru.zip
63+
- name: Install Oracle instant client
64+
run: |
65+
sudo mkdir -p /opt/oracle/
66+
sudo unzip -q instantclient-basic-linux.x64-21.15.0.0.0dbru.zip -d /opt/oracle
67+
sudo unzip -qo instantclient-sqlplus-linux.x64-21.15.0.0.0dbru.zip -d /opt/oracle
68+
sudo unzip -qo instantclient-sdk-linux.x64-21.15.0.0.0dbru.zip -d /opt/oracle
69+
echo "/opt/oracle/instantclient_21_15" >> $GITHUB_PATH
70+
- name: Install JDBC Driver
71+
run: |
72+
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/23261/ojdbc11.jar -O ./lib/ojdbc11.jar
73+
- name: Configure ORA_TZFILE to match Oracle 11g server
74+
run: |
75+
# Oracle 11g XE uses timezone file v14; Instant Client 21.15 embeds
76+
# v35. This mismatch causes ORA-01805 when fetching DATE/TIMESTAMP
77+
# values. Copy the v14 files from the 11g container and point the
78+
# Instant Client at them via ORA_TZFILE.
79+
ORACLE_CONTAINER="${{ job.services.oracle.id }}"
80+
sudo mkdir -p "$ORACLE_HOME/oracore/zoneinfo"
81+
docker cp "$ORACLE_CONTAINER":/u01/app/oracle/product/11.2.0/xe/oracore/zoneinfo/timezlrg_14.dat /tmp/timezlrg_14.dat
82+
docker cp "$ORACLE_CONTAINER":/u01/app/oracle/product/11.2.0/xe/oracore/zoneinfo/timezone_14.dat /tmp/timezone_14.dat
83+
sudo mv /tmp/timezlrg_14.dat "$ORACLE_HOME/oracore/zoneinfo/"
84+
sudo mv /tmp/timezone_14.dat "$ORACLE_HOME/oracore/zoneinfo/"
85+
echo "ORA_TZFILE=timezlrg_14.dat" >> $GITHUB_ENV
86+
- name: Create database user
87+
run: |
88+
./ci/setup_accounts.sh
89+
- name: Bundle install
90+
run: |
91+
bundle install --jobs 4 --retry 3
92+
- name: Run RSpec
93+
run: |
94+
RUBYOPT=-w bundle exec rspec

.github/workflows/test_gemfiles.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ jobs:
8282
sudo unzip -qo instantclient-sdk-linux.x64-23.26.1.0.0.zip -d /opt/oracle/
8383
sudo unzip -qo instantclient-sqlplus-linux.x64-23.26.1.0.0.zip -d /opt/oracle/
8484
echo "/opt/oracle/instantclient_23_26" >> $GITHUB_PATH
85-
- name: Install JDBC Driver
86-
run: |
87-
wget -q https://download.oracle.com/otn-pub/otn_software/jdbc/233/ojdbc11.jar -O ./lib/ojdbc11.jar
8885
- name: Create database user
8986
run: |
9087
./ci/setup_accounts.sh

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ In addition install either ruby-oci8 (for MRI/YARV) or copy Oracle JDBC driver t
154154
If you are using MRI Ruby implementation then you need to install ruby-oci8 gem (version 2.1 or higher)
155155
as well as Oracle client, e.g. [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html).
156156

157-
If you are using JRuby then you need to download latest [Oracle JDBC driver](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html) - either ojdbc7.jar for Java 8 and 7, ojdbc6.jar for Java 6, 7, 8 or ojdbc5.jar for Java 5. You can refer [the support matrix](http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#01_03) for details.
157+
If you are using JRuby then you need to download the appropriate [Oracle JDBC driver](https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html) for your Java version - ojdbc17.jar for Java 17+, ojdbc11.jar for Java 11+, ojdbc8.jar for Java 8+, ojdbc7.jar for Java 7, ojdbc6.jar for Java 6, or ojdbc5.jar for Java 5.
158158

159159
And copy this file to one of these locations. JDBC driver will be searched in this order:
160160

lib/plsql/jdbc_connection.rb

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1+
ojdbc_jars = []
2+
13
begin
24
require "java"
35
require "jruby"
46

5-
# ojdbc6.jar or ojdbc5.jar file should be in JRUBY_HOME/lib or should be in ENV['PATH'] or load path
7+
# Oracle JDBC driver jar should be in JRUBY_HOME/lib or should be in ENV['PATH'] or load path
68

79
java_version = java.lang.System.getProperty("java.version")
8-
ojdbc_jars = if java_version =~ /^1.5/
9-
%w(ojdbc5.jar)
10-
elsif java_version =~ /^1.6/
11-
%w(ojdbc6.jar)
12-
elsif java_version >= "1.7"
13-
# Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
14-
# Oracle 12c client provides new ojdbc7.jar
15-
%w(ojdbc7.jar ojdbc6.jar)
10+
java_major = if java_version =~ /^1\.(\d+)/
11+
$1.to_i
1612
else
17-
[]
13+
java_version.to_i
1814
end
1915

20-
if ENV_JAVA["java.class.path"] !~ Regexp.new(ojdbc_jars.join("|"))
16+
ojdbc_jars << "ojdbc17.jar" if java_major >= 17
17+
ojdbc_jars << "ojdbc11.jar" if java_major >= 11
18+
ojdbc_jars << "ojdbc8.jar" if java_major >= 8
19+
ojdbc_jars << "ojdbc7.jar" if java_major >= 7
20+
ojdbc_jars << "ojdbc6.jar" if java_major >= 6
21+
ojdbc_jars << "ojdbc5.jar" if java_major == 5
22+
23+
if ENV_JAVA["java.class.path"] !~ Regexp.union(ojdbc_jars)
2124
# On Unix environment variable should be PATH, on Windows it is sometimes Path
2225
env_path = (ENV["PATH"] || ENV["Path"] || "").split(File::PATH_SEPARATOR)
2326
# Look for JDBC driver at first in lib subdirectory (application specific JDBC file version)
@@ -33,23 +36,43 @@
3336
end
3437
end
3538

36-
java.sql.DriverManager.registerDriver Java::oracle.jdbc.OracleDriver.new
37-
3839
# set tns_admin property from TNS_ADMIN environment variable
3940
if !java.lang.System.get_property("oracle.net.tns_admin") && ENV["TNS_ADMIN"]
4041
java.lang.System.set_property("oracle.net.tns_admin", ENV["TNS_ADMIN"])
4142
end
4243

43-
rescue LoadError, NameError
44+
rescue LoadError
4445
# JDBC driver is unavailable.
4546
raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver. Please install #{ojdbc_jars.empty? ? "Oracle JDBC" : ojdbc_jars.join(' or ') } library."
4647
end
4748

4849
module PLSQL
4950
class JDBCConnection < Connection # :nodoc:
51+
begin
52+
ORACLE_DRIVER = Java::oracle.jdbc.OracleDriver.new
53+
java.sql.DriverManager.registerDriver ORACLE_DRIVER
54+
rescue NameError
55+
raise LoadError, "ERROR: ruby-plsql could not load Oracle JDBC driver. " \
56+
"Please install the appropriate Oracle JDBC driver. " \
57+
"See https://www.oracle.com/database/technologies/appdev/jdbc-downloads.html"
58+
end
59+
5060
def self.create_raw(params)
5161
url = jdbc_connection_url(params)
52-
new(java.sql.DriverManager.getConnection(url, params[:username], params[:password]))
62+
conn = begin
63+
java.sql.DriverManager.getConnection(url, params[:username], params[:password])
64+
rescue Java::JavaSql::SQLException => e
65+
raise unless e.message =~ /no suitable driver/i
66+
# bypass DriverManager to work in cases where ojdbc*.jar
67+
# is added to the load path at runtime and not on the
68+
# system classpath
69+
ORACLE_DRIVER.connect(url, java.util.Properties.new.tap do |props|
70+
props.setProperty("user", params[:username])
71+
props.setProperty("password", params[:password])
72+
end)
73+
end
74+
conn.setAutoCommit(false)
75+
new(conn)
5376
end
5477

5578
def self.jdbc_connection_url(params)

spec/plsql/procedure_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ def new_candidate(status)
18751875
expect(plsql.test_cursor do |cursor|
18761876
cursor2 = cursor
18771877
end).to be_nil
1878-
expect { cursor2.fetch }.to raise_error(/Cursor was already closed|Closed Statement/)
1878+
expect { cursor2.fetch }.to raise_error(/Cursor was already closed|Closed Statement|Closed ResultSet/)
18791879
end
18801880

18811881
it "should not raise error if cursor is closed inside block" do

spec/spec_helper.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,18 @@ def get_connection(user_number = 0)
8888
end
8989
else
9090
try_to_connect(Java::JavaSql::SQLException) do
91-
java.sql.DriverManager.getConnection(get_connection_url, database_user, database_password)
91+
begin
92+
java.sql.DriverManager.getConnection(get_connection_url, database_user, database_password)
93+
rescue Java::JavaSql::SQLException => e
94+
raise unless e.message =~ /no suitable driver/i
95+
# bypass DriverManager to work in cases where ojdbc*.jar
96+
# is added to the load path at runtime and not on the
97+
# system classpath
98+
PLSQL::JDBCConnection::ORACLE_DRIVER.connect(get_connection_url, java.util.Properties.new.tap do |props|
99+
props.setProperty("user", database_user)
100+
props.setProperty("password", database_password)
101+
end)
102+
end.tap { |c| c.setAutoCommit(false) }
92103
end
93104
end
94105
end

0 commit comments

Comments
 (0)