activerecord-jdbcas400-adapter 1.3.6.1 → 1.3.7
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/lib/arjdbc/as400.rb +1 -0
- data/lib/arjdbc/as400/adapter.rb +47 -69
- data/lib/arjdbc/as400/system.rb +38 -0
- data/test/test_adapter.rb +21 -19
- data/test/test_helper.rb +7 -2
- data/test/test_system.rb +36 -0
- metadata +7 -8
- data/test/config.yml +0 -5
- data/test/test_connection.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6199e97dfd1e313557b52d4e660110f7700fa4b4
|
4
|
+
data.tar.gz: 886e6efe31d46508b42218613f0635233138a27e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b703180d160b4b3672010cd040befe3853d2812c6cc9d0af9e135a8b5a84480e0e275171efc6025fafcdda951bb0a5d86c990c41d72f91aaef891b2fd226ca8
|
7
|
+
data.tar.gz: 74ba90d96b88d3b7a421ecb0dc4dc3ab4debdc9dc33a84bc0fcd3954870068c13023e55d3a0e11925c7edc228f829e9acf40f3f01e8d18bbeb32771dafd791d6
|
data/lib/arjdbc/as400.rb
CHANGED
data/lib/arjdbc/as400/adapter.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require 'arjdbc/db2/adapter'
|
2
|
-
|
3
1
|
module ArJdbc
|
4
2
|
module AS400
|
5
3
|
include DB2
|
4
|
+
include System
|
6
5
|
|
7
6
|
# @private
|
8
7
|
def self.extended(adapter); DB2.extended(adapter); end
|
@@ -31,15 +30,28 @@ module ArJdbc
|
|
31
30
|
def self.emulate_booleans=(emulate); DB2.emulate_booleans = emulate; end
|
32
31
|
|
33
32
|
ADAPTER_NAME = 'AS400'.freeze
|
33
|
+
DRIVER_NAME = 'com.ibm.as400.access.AS400JDBCDriver'.freeze
|
34
|
+
NATIVE_DRIVER_NAME = 'com.ibm.db2.jdbc.app.DB2Driver'.freeze
|
34
35
|
|
35
36
|
def adapter_name
|
36
37
|
ADAPTER_NAME
|
37
38
|
end
|
38
39
|
|
40
|
+
# Set schema is it specified
|
41
|
+
def configure_connection
|
42
|
+
set_schema(config[:schema]) if config[:schema]
|
43
|
+
change_current_library(config[:current_library]) if config[:current_library]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Do not return *LIBL as schema
|
47
|
+
def schema
|
48
|
+
db2_schema
|
49
|
+
end
|
50
|
+
|
39
51
|
# Return only migrated tables
|
40
52
|
def tables
|
41
|
-
if
|
42
|
-
@connection.tables(nil,
|
53
|
+
if current_library
|
54
|
+
@connection.tables(nil, current_library)
|
43
55
|
else
|
44
56
|
@connection.tables(nil, schema)
|
45
57
|
end
|
@@ -47,7 +59,7 @@ module ArJdbc
|
|
47
59
|
|
48
60
|
# Prevent migration in QGPL
|
49
61
|
def supports_migrations?
|
50
|
-
!(system_naming? &&
|
62
|
+
!(system_naming? && !current_library?)
|
51
63
|
end
|
52
64
|
|
53
65
|
# @override
|
@@ -70,37 +82,6 @@ module ArJdbc
|
|
70
82
|
execute_and_auto_confirm(sql, name)
|
71
83
|
end
|
72
84
|
|
73
|
-
# holy moly batman! all this to tell AS400 "yes i am sure"
|
74
|
-
def execute_and_auto_confirm(sql, name = nil)
|
75
|
-
|
76
|
-
begin
|
77
|
-
execute_system_command('CHGJOB INQMSGRPY(*SYSRPYL)')
|
78
|
-
execute_system_command("ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I')")
|
79
|
-
rescue Exception => e
|
80
|
-
raise unauthorized_error_message("CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I')", e)
|
81
|
-
end
|
82
|
-
|
83
|
-
begin
|
84
|
-
result = execute(sql, name)
|
85
|
-
rescue Exception
|
86
|
-
raise
|
87
|
-
else
|
88
|
-
# Return if all work fine
|
89
|
-
result
|
90
|
-
ensure
|
91
|
-
|
92
|
-
# Ensure default configuration restoration
|
93
|
-
begin
|
94
|
-
execute_system_command('CHGJOB INQMSGRPY(*DFT)')
|
95
|
-
execute_system_command('RMVRPYLE SEQNBR(9876)')
|
96
|
-
rescue Exception => e
|
97
|
-
raise unauthorized_error_message('CHGJOB INQMSGRPY(*DFT) and RMVRPYLE SEQNBR(9876)', e)
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
102
|
-
private :execute_and_auto_confirm
|
103
|
-
|
104
85
|
# Disable all schemas browsing
|
105
86
|
def table_exists?(name)
|
106
87
|
return false unless name
|
@@ -111,39 +92,6 @@ module ArJdbc
|
|
111
92
|
@connection.indexes(table_name, name, schema)
|
112
93
|
end
|
113
94
|
|
114
|
-
DRIVER_NAME = 'com.ibm.as400.access.AS400JDBCDriver'.freeze
|
115
|
-
NATIVE_DRIVER_NAME = 'com.ibm.db2.jdbc.app.DB2Driver'.freeze
|
116
|
-
|
117
|
-
# Set schema is it specified
|
118
|
-
def configure_connection
|
119
|
-
set_schema(config[:schema]) if config[:schema]
|
120
|
-
change_current_library(config[:current_library]) if config[:current_library]
|
121
|
-
end
|
122
|
-
|
123
|
-
# Do not return *LIBL as schema
|
124
|
-
def schema
|
125
|
-
db2_schema
|
126
|
-
end
|
127
|
-
|
128
|
-
# Change current library
|
129
|
-
def change_current_library(current_library)
|
130
|
-
# *CRTDFT is the nil equivalent for current library
|
131
|
-
current_library ||= '*CRTDFT'
|
132
|
-
execute_system_command("CHGCURLIB CURLIB(#{current_library})")
|
133
|
-
end
|
134
|
-
|
135
|
-
# Change libraries
|
136
|
-
def change_libraries(libraries)
|
137
|
-
libraries = libraries.nil? || libraries.size < 1 ? '*NONE' :libraries.join(' ')
|
138
|
-
execute_system_command("CHGLIBL LIBL(#{libraries})")
|
139
|
-
end
|
140
|
-
|
141
|
-
def execute_system_command(command)
|
142
|
-
length = command.length
|
143
|
-
command = quote(command)
|
144
|
-
execute("CALL qsys.qcmdexc(#{command}, CAST(#{length} AS DECIMAL(15, 5)))")
|
145
|
-
end
|
146
|
-
|
147
95
|
# Disable transactions when they are not supported
|
148
96
|
def begin_db_transaction
|
149
97
|
super unless config[:transaction_isolation] == 'none'
|
@@ -189,6 +137,36 @@ module ArJdbc
|
|
189
137
|
end
|
190
138
|
end
|
191
139
|
|
140
|
+
# Holy moly batman! all this to tell AS400 "yes i am sure"
|
141
|
+
def execute_and_auto_confirm(sql, name = nil)
|
142
|
+
|
143
|
+
begin
|
144
|
+
execute_system_command('CHGJOB INQMSGRPY(*SYSRPYL)')
|
145
|
+
execute_system_command("ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I')")
|
146
|
+
rescue Exception => e
|
147
|
+
raise unauthorized_error_message("CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I')", e)
|
148
|
+
end
|
149
|
+
|
150
|
+
begin
|
151
|
+
result = execute(sql, name)
|
152
|
+
rescue Exception
|
153
|
+
raise
|
154
|
+
else
|
155
|
+
# Return if all work fine
|
156
|
+
result
|
157
|
+
ensure
|
158
|
+
|
159
|
+
# Ensure default configuration restoration
|
160
|
+
begin
|
161
|
+
execute_system_command('CHGJOB INQMSGRPY(*DFT)')
|
162
|
+
execute_system_command('RMVRPYLE SEQNBR(9876)')
|
163
|
+
rescue Exception => e
|
164
|
+
raise unauthorized_error_message('CHGJOB INQMSGRPY(*DFT) and RMVRPYLE SEQNBR(9876)', e)
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
192
170
|
def unauthorized_error_message(command, exception)
|
193
171
|
"Could not call #{command}.\nDo you have authority to do this?\n\n#{exception.inspect}"
|
194
172
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module AS400
|
3
|
+
module System
|
4
|
+
|
5
|
+
# Execute system command with QSYS.QCMDEXC
|
6
|
+
def execute_system_command(command)
|
7
|
+
length = command.length
|
8
|
+
command = quote(command)
|
9
|
+
execute("CALL QSYS.QCMDEXC(#{command}, CAST(#{length} AS DECIMAL(15, 5)))")
|
10
|
+
end
|
11
|
+
|
12
|
+
# Change current library
|
13
|
+
def change_current_library(current_library)
|
14
|
+
@current_library = current_library
|
15
|
+
# *CRTDFT is the nil equivalent for current library
|
16
|
+
current_library ||= '*CRTDFT'
|
17
|
+
execute_system_command("CHGCURLIB CURLIB(#{current_library})")
|
18
|
+
end
|
19
|
+
|
20
|
+
# Change libraries
|
21
|
+
def change_libraries(libraries)
|
22
|
+
libraries = libraries.nil? || libraries.size < 1 ? '*NONE' :libraries.join(' ')
|
23
|
+
execute_system_command("CHGLIBL LIBL(#{libraries})")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns true if current library is configured
|
27
|
+
def current_library?
|
28
|
+
!current_library.nil?
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the name current library
|
32
|
+
def current_library
|
33
|
+
@current_library
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/test_adapter.rb
CHANGED
@@ -1,6 +1,27 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class TestAdapter < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_schema
|
6
|
+
assert_equal(connection.schema, config[:schema])
|
7
|
+
assert_equal(system_connection.schema, '*LIBL')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_system_naming?
|
11
|
+
assert_false(connection.instance_eval {system_naming?})
|
12
|
+
assert_true(system_connection.instance_eval {system_naming?})
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_supports_migrations?
|
16
|
+
assert_true(connection.supports_migrations?)
|
17
|
+
|
18
|
+
system_connection.change_current_library('QGPL')
|
19
|
+
assert_true(system_connection.supports_migrations?)
|
20
|
+
|
21
|
+
system_connection.change_current_library(nil)
|
22
|
+
assert_false(system_connection.supports_migrations?)
|
23
|
+
end
|
24
|
+
|
4
25
|
def test_prefetch_primary_key?
|
5
26
|
begin
|
6
27
|
connection.execute('CREATE TABLE test_table (test_column INTEGER)')
|
@@ -30,23 +51,4 @@ class TestAdapter < Test::Unit::TestCase
|
|
30
51
|
end
|
31
52
|
end
|
32
53
|
|
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
|
45
|
-
|
46
|
-
def test_change_libraries
|
47
|
-
assert_nothing_raised do
|
48
|
-
connection.change_libraries(%w(QGPL QTEMP))
|
49
|
-
connection.change_libraries(nil)
|
50
|
-
end
|
51
|
-
end
|
52
54
|
end
|
data/test/test_helper.rb
CHANGED
@@ -5,8 +5,13 @@ require 'activerecord-jdbc-adapter'
|
|
5
5
|
|
6
6
|
class Test::Unit::TestCase
|
7
7
|
def config
|
8
|
-
@config ||=
|
9
|
-
|
8
|
+
@config ||= {
|
9
|
+
host: ENV['AS400_HOST'],
|
10
|
+
username: ENV['AS400_USERNAME'],
|
11
|
+
password: ENV['AS400_PASSWORD'],
|
12
|
+
schema: ENV['AS400_SCHEMA'],
|
13
|
+
libraries: ENV['AS400_LIBRARIES']
|
14
|
+
}
|
10
15
|
end
|
11
16
|
|
12
17
|
def data_source_connection
|
data/test/test_system.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestAdapter < Test::Unit::TestCase
|
4
|
+
def test_execute_system_command
|
5
|
+
assert_nothing_raised do
|
6
|
+
connection.execute_system_command('DSPJOBLOG')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_change_current_library
|
11
|
+
connection = system_connection
|
12
|
+
assert_nothing_raised do
|
13
|
+
connection.change_current_library('QGPL')
|
14
|
+
connection.change_current_library(nil)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_current_library
|
19
|
+
connection = system_connection
|
20
|
+
connection.change_current_library('QSYS')
|
21
|
+
assert_equal(connection.current_library, 'QSYS')
|
22
|
+
assert_true(connection.current_library?)
|
23
|
+
|
24
|
+
connection.change_current_library(nil)
|
25
|
+
assert_nil(connection.current_library)
|
26
|
+
assert_false(connection.current_library?)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_change_libraries
|
30
|
+
connection = system_connection
|
31
|
+
assert_nothing_raised do
|
32
|
+
connection.change_libraries(%w(QGPL QTEMP))
|
33
|
+
connection.change_libraries(nil)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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.7
|
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-04-
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-jdbc-adapter
|
@@ -16,12 +16,12 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.3.
|
19
|
+
version: 1.3.7
|
20
20
|
requirement: !ruby/object:Gem::Requirement
|
21
21
|
requirements:
|
22
22
|
- - '>='
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 1.3.
|
24
|
+
version: 1.3.7
|
25
25
|
prerelease: false
|
26
26
|
type: :runtime
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -95,11 +95,11 @@ files:
|
|
95
95
|
- lib/arjdbc/discover.rb
|
96
96
|
- lib/arjdbc/as400/adapter.rb
|
97
97
|
- lib/arjdbc/as400/connection_methods.rb
|
98
|
-
-
|
98
|
+
- lib/arjdbc/as400/system.rb
|
99
99
|
- test/test_adapter.rb
|
100
|
-
- test/test_connection.rb
|
101
100
|
- test/test_database_tasks.rb
|
102
101
|
- test/test_helper.rb
|
102
|
+
- test/test_system.rb
|
103
103
|
homepage: https://github.com/pierrickrouxel/activerecord-jdbcas400-adapter
|
104
104
|
licenses:
|
105
105
|
- ''
|
@@ -125,8 +125,7 @@ signing_key:
|
|
125
125
|
specification_version: 4
|
126
126
|
summary: AS/400 JDBC adapter for JRuby on Rails.
|
127
127
|
test_files:
|
128
|
-
- test/config.yml
|
129
128
|
- test/test_adapter.rb
|
130
|
-
- test/test_connection.rb
|
131
129
|
- test/test_database_tasks.rb
|
132
130
|
- test/test_helper.rb
|
131
|
+
- test/test_system.rb
|
data/test/config.yml
DELETED
data/test/test_connection.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TestConnection < Test::Unit::TestCase
|
4
|
-
def test_system_naming
|
5
|
-
assert_false(connection.instance_eval {system_naming?})
|
6
|
-
assert_true(system_connection.instance_eval {system_naming?})
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_schema
|
10
|
-
assert_equal(connection.schema, config[:schema])
|
11
|
-
|
12
|
-
assert_equal(system_connection.schema, '*LIBL')
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_migration_support
|
16
|
-
assert_true(connection.supports_migrations?)
|
17
|
-
|
18
|
-
connection = system_connection
|
19
|
-
connection.config[:current_library] = 'QTEMP'
|
20
|
-
assert_true(connection.supports_migrations?)
|
21
|
-
|
22
|
-
connection.config[:current_library] = nil
|
23
|
-
assert_false(connection.supports_migrations?)
|
24
|
-
end
|
25
|
-
end
|