activerecord-jdbc-plsql 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: !binary |-
4
+ MmIyMjYwZjIzMzg5N2Q1OTZlMzViZTM1N2U1NGQzNzM2YTFhODYzZA==
5
+ data.tar.gz: !binary |-
6
+ ZWVjMWQzYmQwZWQ0NmU3NDVlYjFjZTU2NGIwMTZmN2I0OGJkMzFhYg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDlkNGJjZDg2OTcwN2IxNDkxNmU0ZGI5MmRmMGJiNzkyZGEwNjBmNTk1MTU5
10
+ ODRiNzMyNTg4N2Q5NDEzMjcwYmM5Yjg4NjBiZTdhZTI0MWM5YTM3MDQ2ZTQ3
11
+ YTcwZDU0ZWEzODk0NmJiYjVmNWZlYzY0MDA4Yjc2ZDVhZGIxNGI=
12
+ data.tar.gz: !binary |-
13
+ ZTk2YmZiOTM2OWU3NGM0YWJiNjA3M2E0NTJhNjBjMmZiMTljMGQ3MjFlYzU4
14
+ NzMwZjdhNDBlZGYyOWQ3YmM0NWVmNzEyOTYwYjljY2I5N2Q5MWIzYTRmNWYx
15
+ ZDkxMzdkMzljNmU4MDA0YThkZjliYTMzZWM0NzM3OWJkZWZiOWI=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord-jdbc-plsql.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pierrick Rouxel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # activerecord-jdbc-plsql
2
+
3
+ activerecord-jdbc-plsql provide a Ruby wrapper to use PL/SQL with Active Record and JDBD.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activerecord-jdbc-plsql'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activerecord-jdbc-plsql
18
+
19
+ ## Usage
20
+
21
+ activerecord-jdbc-plsql provide a new method to call PL/SQL programs. Use **call_procedure** from your models. Example:
22
+
23
+ ```ruby
24
+ result = call_procedure('my_procedure', an_input_parameter: 'value1', an_other_input_parameter: 'value2', an_output_parameter: :integer)
25
+ ```
26
+
27
+ This call will return this ruby hash:
28
+
29
+ ```ruby
30
+ {
31
+ an_output_parameter: 'the expected value'
32
+ }
33
+ ```
34
+
35
+ Supported types are:
36
+
37
+ ```ruby
38
+ :binary
39
+ :boolean
40
+ :date
41
+ :datetime
42
+ :decimal
43
+ :float
44
+ :integer
45
+ :string
46
+ :text
47
+ :time
48
+ :timestamp
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activerecord/jdbc/plsql/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord-jdbc-plsql"
8
+ spec.version = Activerecord::Jdbc::Plsql::VERSION
9
+ spec.authors = ["Pierrick Rouxel"]
10
+ spec.email = ["pierrick.rouxel@me.com"]
11
+ spec.description = %q{activerecord-jdbc-plsql provide a Ruby wrapper to use PL/SQL with Active Record and JDBD}
12
+ spec.summary = %q{PL/SQL with Active Record}
13
+ spec.homepage = "https://github.com/pierrickrouxel/activerecord-jdbc-plsql"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,7 @@
1
+ module Activerecord
2
+ module Jdbc
3
+ module Plsql
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,126 @@
1
+ require "activerecord/jdbc/plsql/version"
2
+
3
+ module ActiveRecord
4
+ module Jdbc
5
+ module PLSql
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+
10
+ SQL_TYPES = {
11
+ binary: java.sql.Types::BINARY,
12
+ boolean: java.sql.Types::BOOLEAN,
13
+ date: java.sql.Types::DATE,
14
+ datetime: java.sql.Types::TIMESTAMP,
15
+ decimal: java.sql.Types::DECIMAL,
16
+ float: java.sql.Types::FLOAT,
17
+ integer: java.sql.Types::INTEGER,
18
+ string: java.sql.Types::VARCHAR,
19
+ text: java.sql.Types::VARCHAR,
20
+ time: java.sql.Types::TIME,
21
+ timestamp: java.sql.Types::TIMESTAMP
22
+ }
23
+
24
+ # Create parameter part of call string
25
+ def stringify_parameters(attributes)
26
+ if attributes.is_a?(Hash)
27
+ stringify_parameters(attributes.values)
28
+ elsif attributes.is_a?(Array)
29
+ attributes.map { |k| stringify_parameters(k) }.join(',')
30
+ elsif !attributes.nil?
31
+ '?'
32
+ end
33
+ end
34
+
35
+ # Create request string
36
+ def create_request_string(name, attributes)
37
+ "{CALL #{name}(#{stringify_parameters(attributes)})}"
38
+ end
39
+
40
+ # Register parameters for callable statement
41
+ def register_parameters(statement, attributes)
42
+ if attributes.is_a?(Hash)
43
+ attributes.each { |k, v| register_parameter(statement, k, v) }
44
+ elsif attributes.is_a?(Array)
45
+ attributes.each_with_index { |v, i| register_parameter(statement, i, v) }
46
+ elsif !attributes.nil?
47
+ statement.setString(1, attributes.to_s)
48
+ end
49
+ end
50
+
51
+ # Choose the best way to register parameter (IN or OUT)
52
+ def register_parameter(statement, key, value)
53
+ case value
54
+ when Symbol
55
+ statement.registerOutParameter(key.to_s, SQL_TYPES[value])
56
+ else
57
+ statement.setString(key.to_s, value.to_s)
58
+ end
59
+ end
60
+
61
+ # Store results in hash
62
+ def parse_results(statement, attributes)
63
+ result = Hash.new
64
+
65
+ if attributes.is_a?(Hash)
66
+ attributes.each { |k, v|
67
+ result[k] = parse_result(statement, k.to_s, v) if v.is_a? Symbol
68
+ }
69
+ elsif attributes.is_a?(Array)
70
+ attributes.each_with_index { |v, i|
71
+ result[i] = parse_result(statement, i, :string) if v.nil?
72
+ }
73
+ end
74
+
75
+ result
76
+ end
77
+
78
+ # Choose the method to call with type
79
+ def parse_result(statement, key, type)
80
+ case type
81
+ when :binary
82
+ statement.getString(key)
83
+ when :boolean
84
+ statement.getBoolean(key)
85
+ when :date
86
+ statement.getDate(key)
87
+ when :datetime
88
+ statement.getTimestamp(key)
89
+ when :decimal
90
+ statement.getDouble(key)
91
+ when :float
92
+ statement.getFloat(key)
93
+ when :integer
94
+ statement.getInt(key)
95
+ when :string
96
+ statement.getString(key)
97
+ when :text
98
+ statement.getString(key)
99
+ when :time
100
+ statement.getTime(key)
101
+ when :timestamp
102
+ statement.getTimestamp(key)
103
+ else
104
+ statement.getObject(key)
105
+ end
106
+ end
107
+
108
+ # Entry point to call procedure
109
+ def call_procedure(name, attributes = nil)
110
+ request_string = create_request_string(name, attributes)
111
+ statement = connection.jdbc_connection.prepareCall(request_string)
112
+
113
+ register_parameters(statement, attributes)
114
+
115
+ logger.info 'Call procedure: ' + request_string
116
+ statement.execute
117
+
118
+ parse_results(statement, attributes)
119
+ end
120
+
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ ActiveRecord::Base.send(:include, ActiveRecord::Jdbc::PLSql)
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-jdbc-plsql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pierrick Rouxel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - "~>"
23
+ - !ruby/object:Gem::Version
24
+ version: '1.3'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ description: activerecord-jdbc-plsql provide a Ruby wrapper to use PL/SQL with Active Record and JDBD
42
+ email:
43
+ - pierrick.rouxel@me.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - activerecord-jdbc-plsql.gemspec
54
+ - lib/activerecord/jdbc/plsql.rb
55
+ - lib/activerecord/jdbc/plsql/version.rb
56
+ homepage: https://github.com/pierrickrouxel/activerecord-jdbc-plsql
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.0.3
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: PL/SQL with Active Record
80
+ test_files: []