activerecord-jdbcas400-adapter 1.3.4 → 1.3.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1e2fed6165b5884b66e6b376a11fad559a66d3c
4
- data.tar.gz: 5c871953b8c322d88ecb46957298b357165d5a62
3
+ metadata.gz: 17117e85ff715297a6f0eae81bc6396bf42e37f0
4
+ data.tar.gz: 7ec82609586834ec4a759e751a1c9da610b601fa
5
5
  SHA512:
6
- metadata.gz: ebab63a04a39b6d6e5374a279c3ff83d2e331b27f48a0d7689386c48ec26da983009f06d0212651ed07e61c15c947b558c200f31a32e07559c972a7eba1e2aae
7
- data.tar.gz: b58433253e0d40024d9e6b699494e5a5f9c4e84aa3ed6572642cb7e9b9624871f872025f0ec4a6edf206a2ffdca2c372088ffe2826e0561aa1b6379362625f33
6
+ metadata.gz: 10cddd83ee5fc0ce0e5dc03465259726be5d619278c46decd8fd3522d53ea45d419acb55f4355aea01091ccc300e5481a819e875b57bdb7fba9405b58f50acce
7
+ data.tar.gz: 02982ff31b1d1a7ebe2cc6ce37be72fa72c8a34f26718fad50b63cfe45ed5cc2c54d821eb18ea052f5a877bc7794fd8b71dc66f2152344c2575b49298377697e
data/README.md CHANGED
@@ -5,3 +5,30 @@ https://github.com/pierrickrouxel/activerecord-jdbcas400-adapter/
5
5
  ## Description
6
6
 
7
7
  This is an ActiveRecord driver for AS/400 using JDBC running under JRuby.
8
+
9
+ ## Usage
10
+
11
+ Configure your database.yml in the normal Rails style:
12
+ ```yml
13
+ development:
14
+ adapter: as400
15
+ database: development
16
+ username: user
17
+ password: 1234
18
+ ```
19
+
20
+ You cas also use JNDI in production mode:
21
+ ```yml
22
+ production:
23
+ adapter: jndi # jdbc
24
+ jndi: jdbc/DataSource
25
+ ```
26
+
27
+ If your DB isn't correctly discovered you can specify the dialect:
28
+ ```yml
29
+ dialect: as400
30
+ ```
31
+
32
+ ## Dependency
33
+
34
+ You can embed the JTOpen driver in your application. It is distributed in a separate gem : 'as400-jdbc'
@@ -0,0 +1 @@
1
+ require 'arjdbc/as400'
@@ -1,3 +1,2 @@
1
1
  # NOTE: here for Bundler to auto-load the gem unless :require => false
2
- require 'arjdbc/db2'
3
- require 'arjdbc/db2/as400'
2
+ require 'arjdbc/as400'
@@ -0,0 +1,4 @@
1
+ require 'arjdbc'
2
+ require 'arjdbc/db2/adapter'
3
+ require 'arjdbc/as400/connection_methods'
4
+ require 'arjdbc/as400/adapter'
@@ -0,0 +1,136 @@
1
+ require 'arjdbc/db2/adapter'
2
+
3
+ module ArJdbc
4
+ module AS400
5
+ include DB2
6
+
7
+ # @private
8
+ def self.extended(adapter); DB2.extended(adapter); end
9
+
10
+ # @private
11
+ def self.initialize!; DB2.initialize!; end
12
+
13
+ # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
14
+ def self.jdbc_connection_class; DB2.jdbc_connection_class; end
15
+
16
+ # @see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
17
+ def self.arel_visitor_type(config = nil); DB2.arel_visitor_type(config); end
18
+
19
+ def self.column_selector
20
+ [ /as400/i, lambda { |config, column| column.extend(Column) } ]
21
+ end
22
+
23
+ # @private
24
+ Column = DB2::Column
25
+
26
+ # Boolean emulation can be disabled using :
27
+ #
28
+ # ArJdbc::AS400.emulate_booleans = false
29
+ #
30
+ def self.emulate_booleans; DB2.emulate_booleans; end
31
+ def self.emulate_booleans=(emulate); DB2.emulate_booleans = emulate; end
32
+
33
+ ADAPTER_NAME = 'AS400'.freeze
34
+
35
+ def adapter_name
36
+ ADAPTER_NAME
37
+ end
38
+
39
+ # @override
40
+ def prefetch_primary_key?(table_name = nil)
41
+ # TRUE if the table has no identity column
42
+ names = table_name.upcase.split(".")
43
+ sql = "SELECT 1 FROM SYSIBM.SQLPRIMARYKEYS WHERE "
44
+ sql << "TABLE_SCHEM = '#{names.first}' AND " if names.size == 2
45
+ sql << "TABLE_NAME = '#{names.last}'"
46
+ select_one(sql).nil?
47
+ end
48
+
49
+ # @override
50
+ def rename_column(table_name, column_name, new_column_name)
51
+ raise NotImplementedError, "rename_column is not supported on IBM iSeries"
52
+ end
53
+
54
+ # @override
55
+ def execute_table_change(sql, table_name, name = nil)
56
+ execute_and_auto_confirm(sql, name)
57
+ end
58
+
59
+ # holy moly batman! all this to tell AS400 "yes i am sure"
60
+ def execute_and_auto_confirm(sql, name = nil)
61
+
62
+ begin
63
+ @connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*SYSRPYL)',0000000031.00000)"
64
+ @connection.execute_update "call qsys.qcmdexc('ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY(''I'')',0000000045.00000)"
65
+ rescue Exception => e
66
+ raise "Could not call CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I').\n" +
67
+ "Do you have authority to do this?\n\n#{e.inspect}"
68
+ end
69
+
70
+ begin
71
+ result = execute(sql, name)
72
+ rescue Exception
73
+ raise
74
+ else
75
+ # Return if all work fine
76
+ result
77
+ ensure
78
+
79
+ # Ensure default configuration restoration
80
+ begin
81
+ @connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*DFT)',0000000027.00000)"
82
+ @connection.execute_update "call qsys.qcmdexc('RMVRPYLE SEQNBR(9876)',0000000021.00000)"
83
+ rescue Exception => e
84
+ raise "Could not call CHGJOB INQMSGRPY(*DFT) and RMVRPYLE SEQNBR(9876).\n" +
85
+ "Do you have authority to do this?\n\n#{e.inspect}"
86
+ end
87
+
88
+ end
89
+ end
90
+ private :execute_and_auto_confirm
91
+
92
+ # disable all schemas browsing when default schema is specified
93
+ def table_exists?(name)
94
+ return false unless name
95
+ schema ? @connection.table_exists?(name, schema) : @connection.table_exists?(name)
96
+ end
97
+
98
+ DRIVER_NAME = 'com.ibm.as400.access.AS400JDBCDriver'.freeze
99
+
100
+ # @private
101
+ # @deprecated no longer used
102
+ def as400?
103
+ true
104
+ end
105
+
106
+ private
107
+
108
+ # @override
109
+ def db2_schema
110
+ @db2_schema = false unless defined? @db2_schema
111
+ return @db2_schema if @db2_schema != false
112
+ @db2_schema =
113
+ if config[:schema].present?
114
+ config[:schema]
115
+ elsif config[:jndi].present?
116
+ # Only found method to set db2_schema from jndi
117
+ result = select_one("SELECT CURRENT_SCHEMA FROM SYSIBM.SYSDUMMY1")
118
+ schema = result['00001']
119
+ # If the connection uses the library list schema name will be nil
120
+ if schema == '*LIBL'
121
+ schema = nil
122
+ end
123
+ schema
124
+ else
125
+ # AS400 implementation takes schema from library name (last part of URL)
126
+ # jdbc:as400://localhost/schema;naming=system;libraries=lib1,lib2
127
+ schema = nil
128
+ split = config[:url].split('/')
129
+ # Return nil if schema isn't defined
130
+ schema = split.last.split(';').first.strip if split.size == 4
131
+ schema
132
+ end
133
+ end
134
+
135
+ end
136
+ end
@@ -0,0 +1,26 @@
1
+ ArJdbc::ConnectionMethods.module_eval do
2
+ # @note Assumes AS400 driver (*jt400.jar*) is on class-path.
3
+ def as400_connection(config)
4
+ begin
5
+ require 'jdbc/as400'
6
+ ::Jdbc::AS400.load_driver(:require) if defined?(::Jdbc::AS400.load_driver)
7
+ rescue LoadError # assuming driver.jar is on the class-path
8
+ end
9
+
10
+ config[:url] ||= begin
11
+ # jdbc:as400://[host]
12
+ url = 'jdbc:as400://'
13
+ url << config[:host] if config[:host]
14
+ # jdbc:as400://myiSeries;database name=IASP1
15
+ url << ";database name=#{config[:database]}" if config[:database]
16
+ # jdbc:as400://[host];proxy server=HODServerName:proxyServerPort
17
+ url << ";proxy server=#{config[:proxy]}" if config[:proxy]
18
+ url
19
+ end
20
+ require 'arjdbc/as400/adapter'
21
+ config[:driver] ||= ::ArJdbc::AS400::DRIVER_NAME
22
+ config[:adapter_spec] ||= ::ArJdbc::AS400
23
+ config[:connection_alive_sql] ||= 'SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY'
24
+ jdbc_connection(config)
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module ::ArJdbc
2
+ extension :AS400 do |name, config|
3
+ # The native JDBC driver always returns "DB2 UDB for AS/400"
4
+ if name =~ /as\/?400/i
5
+ require 'arjdbc/as400'
6
+ true
7
+ end
8
+ end
9
+ 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
4
+ version: 1.3.4.1
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: 2013-12-11 00:00:00.000000000 Z
11
+ date: 2013-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-jdbc-adapter
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.3.4
27
- - !ruby/object:Gem::Dependency
28
- name: jdbc-as400
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '7.10'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '7.10'
41
27
  description: Install this gem to use AS/400 with JRuby on Rails.
42
28
  email: nick@nicksieger.com, ola.bini@gmail.com
43
29
  executables: []
@@ -47,8 +33,12 @@ files:
47
33
  - Rakefile
48
34
  - README.md
49
35
  - LICENSE.txt
50
- - lib/active_record/connection_adapters/jdbcas400_adapter.rb
36
+ - lib/active_record/connection_adapters/as400_adapter.rb
51
37
  - lib/activerecord-jdbcas400-adapter.rb
38
+ - lib/arjdbc/as400/adapter.rb
39
+ - lib/arjdbc/as400/connection_methods.rb
40
+ - lib/arjdbc/as400.rb
41
+ - lib/arjdbc/discover.rb
52
42
  homepage: https://github.com/pierrickrouxel/activerecord-jdbcas400-adapter
53
43
  licenses: []
54
44
  metadata: {}
@@ -1,6 +0,0 @@
1
- # NOTE: required by AR resolver with 'jdbcas400' adapter configuration :
2
- # we should make sure a jdbcas400db2_connection is setup on ActiveRecord::Base
3
- require 'arjdbc/db2'
4
- require 'arjdbc/db2/as400'
5
- # all setup should be performed in arjdbc/db2 to avoid circular requires
6
- # this should not be required from any loads perormed by arjdbc/db2 code