activerecord-jdbcas400-adapter 1.3.5.3 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/arjdbc/as400/adapter.rb +43 -15
- data/lib/arjdbc/as400/connection_methods.rb +30 -11
- data/test/config.yml +3 -3
- data/test/test_adapter.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb2bfb276ecfc1dee2de1f0439823043a1d5771a
|
4
|
+
data.tar.gz: 89efd8b8716e600fa7e8bc7186049c1b24e7ec57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7ba6ba952a06a01b6826e56d145801881f4abb864c2033bff68bbc94b6b26feace32c84598bcac99790ed1568e9f0717ec14116dd879963b4b6e17e2c5cd3d8
|
7
|
+
data.tar.gz: 2435e51ab693e89482173cbf24db5d14de3f7090c3a0000a006a411c5c346d9c95d01455dd6717f6775824daec1b2d04f6c7dddb6c09bddad9750ea61c1a4512
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# activerecord-jdbcas400-adapter
|
2
2
|
|
3
|
+
[][gem]
|
4
|
+
[][gemnasium]
|
5
|
+
[][codeclimate]
|
6
|
+
|
3
7
|
https://github.com/pierrickrouxel/activerecord-jdbcas400-adapter/
|
4
8
|
|
5
9
|
## Description
|
@@ -48,8 +52,14 @@ If your DB isn't correctly discovered you can specify the dialect:
|
|
48
52
|
dialect: as400
|
49
53
|
```
|
50
54
|
|
51
|
-
|
55
|
+
To use native DB2 connection (directly on IBM i JVM only), you can add this to database.yml:
|
56
|
+
```yml
|
57
|
+
native: true
|
58
|
+
```
|
59
|
+
This connection doesn't require credentials.
|
52
60
|
|
61
|
+
## Experimental features
|
62
|
+
### Current library
|
53
63
|
To allow migrations with system naming, a configuration is added to adapter:
|
54
64
|
|
55
65
|
```yml
|
data/lib/arjdbc/as400/adapter.rb
CHANGED
@@ -45,13 +45,6 @@ module ArJdbc
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# Force migration in current library
|
49
|
-
def create_table(name, options = {})
|
50
|
-
execute("SET SCHEMA #{config[:current_library]}") if config[:current_library]
|
51
|
-
super
|
52
|
-
execute('SET SCHEMA DEFAULT') if config[:current_library]
|
53
|
-
end
|
54
|
-
|
55
48
|
# Prevent migration in QGPL
|
56
49
|
def supports_migrations?
|
57
50
|
!(system_naming? && config[:current_library].nil?)
|
@@ -67,8 +60,8 @@ module ArJdbc
|
|
67
60
|
# @override
|
68
61
|
def rename_column(table_name, column_name, new_column_name)
|
69
62
|
column = columns(table_name, column_name).find { |column| column.name == column_name.to_s}
|
70
|
-
add_column(table_name, new_column_name, column.type)
|
71
|
-
execute("UPDATE #{table_name} SET #{new_column_name} = #{column_name}")
|
63
|
+
add_column(table_name, new_column_name, column.type, column.instance_values)
|
64
|
+
execute("UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(new_column_name)} = #{quote_column_name(column_name)}")
|
72
65
|
remove_column(table_name, column_name)
|
73
66
|
end
|
74
67
|
|
@@ -81,8 +74,8 @@ module ArJdbc
|
|
81
74
|
def execute_and_auto_confirm(sql, name = nil)
|
82
75
|
|
83
76
|
begin
|
84
|
-
|
85
|
-
|
77
|
+
execute_system_command('QSYS/CHGJOB INQMSGRPY(*SYSRPYL)')
|
78
|
+
execute_system_command("ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I')")
|
86
79
|
rescue Exception => e
|
87
80
|
raise "Could not call CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I').\n" +
|
88
81
|
"Do you have authority to do this?\n\n#{e.inspect}"
|
@@ -99,8 +92,8 @@ module ArJdbc
|
|
99
92
|
|
100
93
|
# Ensure default configuration restoration
|
101
94
|
begin
|
102
|
-
|
103
|
-
|
95
|
+
execute_system_command('QSYS/CHGJOB INQMSGRPY(*DFT)')
|
96
|
+
execute_system_command('RMVRPYLE SEQNBR(9876)')
|
104
97
|
rescue Exception => e
|
105
98
|
raise "Could not call CHGJOB INQMSGRPY(*DFT) and RMVRPYLE SEQNBR(9876).\n" +
|
106
99
|
"Do you have authority to do this?\n\n#{e.inspect}"
|
@@ -121,10 +114,12 @@ module ArJdbc
|
|
121
114
|
end
|
122
115
|
|
123
116
|
DRIVER_NAME = 'com.ibm.as400.access.AS400JDBCDriver'.freeze
|
117
|
+
NATIVE_DRIVER_NAME = 'com.ibm.db2.jdbc.app.DB2Driver'.freeze
|
124
118
|
|
125
119
|
# Set schema is it specified
|
126
120
|
def configure_connection
|
127
121
|
set_schema(config[:schema]) if config[:schema]
|
122
|
+
change_current_library(config[:current_library]) if config[:current_library]
|
128
123
|
end
|
129
124
|
|
130
125
|
# Do not return *LIBL as schema
|
@@ -132,6 +127,40 @@ module ArJdbc
|
|
132
127
|
db2_schema
|
133
128
|
end
|
134
129
|
|
130
|
+
# Change current library
|
131
|
+
def change_current_library(current_library)
|
132
|
+
# *CRTDFT is the nil equivalent for current library
|
133
|
+
current_library ||= '*CRTDFT'
|
134
|
+
execute_system_command("CHGCURLIB CURLIB(#{current_library})")
|
135
|
+
end
|
136
|
+
|
137
|
+
def execute_system_command(command)
|
138
|
+
length = command.length
|
139
|
+
command = ::ActiveRecord::Base.sanitize(command)
|
140
|
+
@connection.execute_update("CALL qsys.qcmdexc(#{command}, CAST(#{length} AS DECIMAL(15, 5)))")
|
141
|
+
end
|
142
|
+
|
143
|
+
# Disable transactions when they are not supported
|
144
|
+
def begin_db_transaction
|
145
|
+
super unless config[:transaction_isolation] == 'none'
|
146
|
+
end
|
147
|
+
|
148
|
+
def commit_db_transaction
|
149
|
+
super unless config[:transaction_isolation] == 'none'
|
150
|
+
end
|
151
|
+
|
152
|
+
def rollback_db_transaction
|
153
|
+
super unless config[:transaction_isolation] == 'none'
|
154
|
+
end
|
155
|
+
|
156
|
+
def begin_isolated_db_transaction(isolation)
|
157
|
+
super unless config[:transaction_isolation] == 'none'
|
158
|
+
end
|
159
|
+
|
160
|
+
def create_savepoint(name = current_savepoint_name(true))
|
161
|
+
super unless config[:transaction_isolation] == 'none'
|
162
|
+
end
|
163
|
+
|
135
164
|
private
|
136
165
|
# If naming is really in system mode CURRENT_SCHEMA is *LIBL
|
137
166
|
def system_naming?
|
@@ -151,10 +180,9 @@ module ArJdbc
|
|
151
180
|
config[:schema]
|
152
181
|
else
|
153
182
|
# Only found method to set db2_schema from jndi
|
154
|
-
result = select_one(
|
183
|
+
result = select_one('VALUES CURRENT_SCHEMA')
|
155
184
|
result['00001']
|
156
185
|
end
|
157
186
|
end
|
158
|
-
|
159
187
|
end
|
160
188
|
end
|
@@ -1,25 +1,44 @@
|
|
1
1
|
ArJdbc::ConnectionMethods.module_eval do
|
2
2
|
# @note Assumes AS400 driver (*jt400.jar*) is on class-path.
|
3
3
|
def as400_connection(config)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
|
5
|
+
if config[:native]
|
6
|
+
config[:transaction_isolation] ||= 'none'
|
7
|
+
else
|
8
|
+
begin
|
9
|
+
require 'jdbc/as400'
|
10
|
+
::Jdbc::AS400.load_driver(:require) if defined?(::Jdbc::AS400.load_driver)
|
11
|
+
rescue LoadError # assuming driver.jar is on the class-path
|
12
|
+
end
|
8
13
|
end
|
9
14
|
|
10
15
|
config[:url] ||= begin
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
+
url = 'jdbc:'
|
17
|
+
if config[:native]
|
18
|
+
# jdbc:db2:*local;naming=[naming];libraries=[libraries]
|
19
|
+
url << 'db2:*local'
|
20
|
+
else
|
21
|
+
# jdbc:as400://[host];proxy server=[proxy:port];naming=[naming];libraries=[libraries];prompt=false
|
22
|
+
url << 'as400://'
|
23
|
+
url << config[:host] if config[:host]
|
24
|
+
url << ";database name=#{config[:database]}" if config[:database]
|
25
|
+
url << ";proxy server=#{config[:proxy]}" if config[:proxy]
|
26
|
+
url << ';prompt=false'
|
27
|
+
end
|
16
28
|
url << ";naming=#{config[:naming]}" if config[:naming]
|
17
29
|
url << ";libraries=#{config[:libraries]}" if config[:libraries]
|
18
|
-
url <<
|
30
|
+
url << ";auto commit=#{config[:auto_commit]}" if config[:auto_commit]
|
31
|
+
url << ";transaction isolation=#{config[:transaction_isolation]}" if config[:transaction_isolation]
|
19
32
|
url
|
20
33
|
end
|
21
34
|
require 'arjdbc/as400/adapter'
|
22
|
-
config[:driver] ||= ::
|
35
|
+
config[:driver] ||= if defined?(::Jdbc::AS400.driver_name)
|
36
|
+
::Jdbc::AS400.driver_name
|
37
|
+
elsif config[:native]
|
38
|
+
::ArJdbc::AS400::NATIVE_DRIVER_NAME
|
39
|
+
else
|
40
|
+
::ArJdbc::AS400::DRIVER_NAME
|
41
|
+
end
|
23
42
|
config[:adapter_spec] ||= ::ArJdbc::AS400
|
24
43
|
config[:connection_alive_sql] ||= 'SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY'
|
25
44
|
jdbc_connection(config)
|
data/test/config.yml
CHANGED
data/test/test_adapter.rb
CHANGED
@@ -29,4 +29,17 @@ class TestAdapter < Test::Unit::TestCase
|
|
29
29
|
connection.execute('DROP TABLE test_table')
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_execute_system_command
|
34
|
+
assert_nothing_raised do
|
35
|
+
connection.execute_system_command('DSPJOBLOG')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_change_current_library
|
40
|
+
assert_nothing_raised do
|
41
|
+
connection.change_current_library('QGPL')
|
42
|
+
connection.change_current_library(nil)
|
43
|
+
end
|
44
|
+
end
|
32
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbcas400-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sieger, Ola Bini, Pierrick Rouxel and JRuby contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-jdbc-adapter
|