unidata 0.0.1 → 0.0.2
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.
- data/README.md +4 -4
- data/lib/unidata/asjava.jar +0 -0
- data/lib/unidata/connection.rb +10 -8
- data/lib/unidata/extensions/big_decimal.rb +2 -0
- data/lib/unidata/extensions/date.rb +2 -0
- data/lib/unidata/extensions/time.rb +2 -0
- data/lib/unidata/model.rb +1 -1
- data/lib/unidata/version.rb +1 -1
- data/lib/unidata.rb +9 -5
- data/spec/unidata/connection_spec.rb +38 -26
- data/spec/unidata/model_spec.rb +3 -3
- metadata +3 -18
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
UniData ORM
|
1
|
+
UniData ORM [](http://travis-ci.org/jisraelsen/unidata)
|
2
2
|
===========
|
3
3
|
|
4
4
|
A simple ORM for Rocket's UniData database.
|
@@ -91,9 +91,9 @@ COVERAGE=on rake spec
|
|
91
91
|
Issues
|
92
92
|
------
|
93
93
|
|
94
|
-
Please use GitHub's [issue tracker](http://github.com/
|
94
|
+
Please use GitHub's [issue tracker](http://github.com/jisraelsen/unidata/issues).
|
95
95
|
|
96
|
-
|
97
|
-
|
96
|
+
Author
|
97
|
+
------
|
98
98
|
|
99
99
|
[Jeremy Israelsen](http://github.com/jisraelsen)
|
Binary file
|
data/lib/unidata/connection.rb
CHANGED
@@ -14,11 +14,13 @@ module Unidata
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def open
|
17
|
-
@session =
|
17
|
+
@session = Unidata.unijava.open_session
|
18
|
+
@session.set_data_source_type "UNIDATA"
|
19
|
+
@session.connect(host, user, password, data_dir)
|
18
20
|
end
|
19
21
|
|
20
22
|
def close
|
21
|
-
|
23
|
+
Unidata.unijava.close_session @session
|
22
24
|
@session = nil
|
23
25
|
end
|
24
26
|
|
@@ -29,7 +31,7 @@ module Unidata
|
|
29
31
|
begin
|
30
32
|
file.read_field(record_id, 0)
|
31
33
|
exists = true
|
32
|
-
rescue
|
34
|
+
rescue Unidata::UniFileException
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
@@ -41,8 +43,8 @@ module Unidata
|
|
41
43
|
|
42
44
|
open_file(filename) do |file|
|
43
45
|
begin
|
44
|
-
record =
|
45
|
-
rescue
|
46
|
+
record = Unidata::UniDynArray.new(file.read(record_id))
|
47
|
+
rescue Unidata::UniFileException
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
@@ -55,7 +57,7 @@ module Unidata
|
|
55
57
|
open_file(filename) do |file|
|
56
58
|
begin
|
57
59
|
value = file.read_field(record_id, field).to_s
|
58
|
-
rescue
|
60
|
+
rescue Unidata::UniFileException
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
@@ -63,7 +65,7 @@ module Unidata
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def write(filename, record_id, record)
|
66
|
-
record = record.to_unidata unless record.kind_of?(
|
68
|
+
record = record.to_unidata unless record.kind_of?(Unidata::UniDynArray)
|
67
69
|
|
68
70
|
open_file(filename) do |file|
|
69
71
|
file.write(record_id, record)
|
@@ -82,7 +84,7 @@ module Unidata
|
|
82
84
|
begin
|
83
85
|
file.lock_record(record_id, lock_flag)
|
84
86
|
yield
|
85
|
-
rescue
|
87
|
+
rescue Unidata::UniFileException
|
86
88
|
# try to obtain a record lock at most 3 times, then give up
|
87
89
|
if retry_count < 2
|
88
90
|
sleep 5
|
data/lib/unidata/model.rb
CHANGED
data/lib/unidata/version.rb
CHANGED
data/lib/unidata.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'date'
|
4
|
-
require 'bigdecimal'
|
1
|
+
require 'java'
|
2
|
+
require 'unidata/asjava.jar'
|
5
3
|
require 'unidata/extensions'
|
6
4
|
require 'unidata/connection'
|
7
5
|
require 'unidata/field'
|
@@ -9,9 +7,16 @@ require 'unidata/model'
|
|
9
7
|
require "unidata/version"
|
10
8
|
|
11
9
|
module Unidata
|
10
|
+
include_package 'asjava.uniobjects'
|
11
|
+
include_package 'asjava.uniclientlibs'
|
12
|
+
|
12
13
|
class << self
|
13
14
|
attr_reader :connection
|
14
15
|
|
16
|
+
def unijava
|
17
|
+
@unijava ||= Unidata::UniJava.new
|
18
|
+
end
|
19
|
+
|
15
20
|
def prepare_connection(config={})
|
16
21
|
@connection = Connection.new(config[:user], config[:password], config[:host], config[:data_dir])
|
17
22
|
end
|
@@ -30,4 +35,3 @@ module Unidata
|
|
30
35
|
end
|
31
36
|
end
|
32
37
|
end
|
33
|
-
|
@@ -3,6 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe Unidata::Connection do
|
4
4
|
let(:connection) { Unidata::Connection.new('test', 'secret', 'localhost', 'tmp') }
|
5
5
|
|
6
|
+
before(:each) do
|
7
|
+
@session = double('UniSession', :set_data_source_type => nil, :connect => nil)
|
8
|
+
|
9
|
+
Unidata.unijava.stub(:open_session).and_return(@session)
|
10
|
+
Unidata.unijava.stub(:close_session)
|
11
|
+
end
|
12
|
+
|
6
13
|
describe '#initialize' do
|
7
14
|
it 'captures and assigns arguments' do
|
8
15
|
connection.user.should == 'test'
|
@@ -15,7 +22,8 @@ describe Unidata::Connection do
|
|
15
22
|
describe '#open?' do
|
16
23
|
context 'with existing active session' do
|
17
24
|
it 'returns true' do
|
18
|
-
|
25
|
+
@session.stub(:is_active).and_return(true)
|
26
|
+
|
19
27
|
connection.open
|
20
28
|
connection.open?.should == true
|
21
29
|
end
|
@@ -23,7 +31,8 @@ describe Unidata::Connection do
|
|
23
31
|
|
24
32
|
context 'with existing inactive session' do
|
25
33
|
it 'returns false' do
|
26
|
-
|
34
|
+
@session.stub(:is_active).and_return(false)
|
35
|
+
|
27
36
|
connection.open
|
28
37
|
connection.open?.should == false
|
29
38
|
end
|
@@ -37,19 +46,27 @@ describe Unidata::Connection do
|
|
37
46
|
end
|
38
47
|
|
39
48
|
describe '#open' do
|
40
|
-
it '
|
41
|
-
|
49
|
+
it 'opens a new session' do
|
50
|
+
Unidata.unijava.should_receive(:open_session)
|
51
|
+
connection.open
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'sets data source type to UNIDATA' do
|
55
|
+
@session.should_receive(:set_data_source_type).with('UNIDATA')
|
56
|
+
connection.open
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'connects the session' do
|
60
|
+
@session.should_receive(:connect).with(connection.host, connection.user, connection.password, connection.data_dir)
|
42
61
|
connection.open
|
43
62
|
end
|
44
63
|
end
|
45
64
|
|
46
65
|
describe '#close' do
|
47
|
-
it '
|
48
|
-
session = double('UDJrb::Session', :disconnect => nil)
|
49
|
-
UDJrb::Session.stub(:new).and_return(session)
|
66
|
+
it 'closes the session' do
|
50
67
|
connection.open
|
51
68
|
|
52
|
-
|
69
|
+
Unidata.unijava.should_receive(:close_session).with(@session)
|
53
70
|
connection.close
|
54
71
|
end
|
55
72
|
end
|
@@ -57,9 +74,8 @@ describe Unidata::Connection do
|
|
57
74
|
describe '#exists?' do
|
58
75
|
before(:each) do
|
59
76
|
@file = double('UniFile', :close => nil, :read_field => nil)
|
60
|
-
@session
|
77
|
+
@session.stub(:open).and_return(@file)
|
61
78
|
|
62
|
-
UDJrb::Session.stub(:new).and_return(@session)
|
63
79
|
connection.open
|
64
80
|
end
|
65
81
|
|
@@ -87,7 +103,7 @@ describe Unidata::Connection do
|
|
87
103
|
|
88
104
|
context 'when file has no given record_id' do
|
89
105
|
it 'returns false' do
|
90
|
-
uni_file_exception = package_local_constructor
|
106
|
+
uni_file_exception = package_local_constructor Unidata::UniFileException
|
91
107
|
|
92
108
|
@file.stub(:read_field).and_raise(uni_file_exception)
|
93
109
|
connection.exists?('TEST', 123).should == false
|
@@ -98,9 +114,8 @@ describe Unidata::Connection do
|
|
98
114
|
describe '#read' do
|
99
115
|
before(:each) do
|
100
116
|
@file = double('UniFile', :close => nil, :read => nil)
|
101
|
-
@session
|
117
|
+
@session.stub(:open).and_return(@file)
|
102
118
|
|
103
|
-
UDJrb::Session.stub(:new).and_return(@session)
|
104
119
|
connection.open
|
105
120
|
end
|
106
121
|
|
@@ -120,15 +135,15 @@ describe Unidata::Connection do
|
|
120
135
|
end
|
121
136
|
|
122
137
|
context 'when record exists' do
|
123
|
-
it 'returns record as a
|
138
|
+
it 'returns record as a Unidata::UniDynArray' do
|
124
139
|
@file.stub(:read).and_return('')
|
125
|
-
connection.read('TEST', 123).should be_kind_of(
|
140
|
+
connection.read('TEST', 123).should be_kind_of(Unidata::UniDynArray)
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|
129
144
|
context 'when record does not exist' do
|
130
145
|
it 'returns nil' do
|
131
|
-
uni_file_exception = package_local_constructor
|
146
|
+
uni_file_exception = package_local_constructor Unidata::UniFileException
|
132
147
|
|
133
148
|
@file.stub(:read).and_raise(uni_file_exception)
|
134
149
|
connection.read('TEST', 123).should be_nil
|
@@ -139,9 +154,8 @@ describe Unidata::Connection do
|
|
139
154
|
describe '#read_field' do
|
140
155
|
before(:each) do
|
141
156
|
@file = double('UniFile', :close => nil, :read_field => nil)
|
142
|
-
@session
|
157
|
+
@session.stub(:open).and_return(@file)
|
143
158
|
|
144
|
-
UDJrb::Session.stub(:new).and_return(@session)
|
145
159
|
connection.open
|
146
160
|
end
|
147
161
|
|
@@ -169,7 +183,7 @@ describe Unidata::Connection do
|
|
169
183
|
|
170
184
|
context 'when field does not exist' do
|
171
185
|
it 'returns nil' do
|
172
|
-
uni_file_exception = package_local_constructor
|
186
|
+
uni_file_exception = package_local_constructor Unidata::UniFileException
|
173
187
|
|
174
188
|
@file.stub(:read_field).and_raise(uni_file_exception)
|
175
189
|
connection.read_field('TEST', 123, 5).should be_nil
|
@@ -180,10 +194,9 @@ describe Unidata::Connection do
|
|
180
194
|
describe '#write' do
|
181
195
|
before(:each) do
|
182
196
|
@file = double('UniFile', :close => nil, :write => nil)
|
183
|
-
@session
|
184
|
-
@record =
|
197
|
+
@session.stub(:open).and_return(@file)
|
198
|
+
@record = Unidata::UniDynArray.new
|
185
199
|
|
186
|
-
UDJrb::Session.stub(:new).and_return(@session)
|
187
200
|
connection.open
|
188
201
|
end
|
189
202
|
|
@@ -192,9 +205,9 @@ describe Unidata::Connection do
|
|
192
205
|
connection.write('TEST', 123, @record)
|
193
206
|
end
|
194
207
|
|
195
|
-
it 'calls to_unidata on record if record not a
|
208
|
+
it 'calls to_unidata on record if record not a Unidata::UniDynArray' do
|
196
209
|
record = double('Record')
|
197
|
-
record.should_receive(:to_unidata).and_return(
|
210
|
+
record.should_receive(:to_unidata).and_return(Unidata::UniDynArray.new)
|
198
211
|
|
199
212
|
connection.write('TEST', 123, record)
|
200
213
|
end
|
@@ -213,9 +226,8 @@ describe Unidata::Connection do
|
|
213
226
|
describe '#write_field' do
|
214
227
|
before(:each) do
|
215
228
|
@file = double('UniFile', :close => nil, :write_field => nil)
|
216
|
-
@session
|
229
|
+
@session.stub(:open).and_return(@file)
|
217
230
|
|
218
|
-
UDJrb::Session.stub(:new).and_return(@session)
|
219
231
|
connection.open
|
220
232
|
end
|
221
233
|
|
data/spec/unidata/model_spec.rb
CHANGED
@@ -67,7 +67,7 @@ describe Unidata::Model do
|
|
67
67
|
|
68
68
|
describe '.from_unidata' do
|
69
69
|
before(:each) do
|
70
|
-
@record =
|
70
|
+
@record = Unidata::UniDynArray.new
|
71
71
|
@record.replace 0, 123
|
72
72
|
@record.replace 1, 'JOHN DOE'
|
73
73
|
@record.replace 2, 25
|
@@ -113,7 +113,7 @@ describe Unidata::Model do
|
|
113
113
|
|
114
114
|
describe '.find' do
|
115
115
|
before(:each) do
|
116
|
-
@record =
|
116
|
+
@record = Unidata::UniDynArray.new
|
117
117
|
@record.replace 1, 'JOHN DOE'
|
118
118
|
@record.replace 2, 25
|
119
119
|
@record.replace 3, Date.to_unidata(Date.today)
|
@@ -169,7 +169,7 @@ describe Unidata::Model do
|
|
169
169
|
:salary => BigDecimal.new('60_000.00')
|
170
170
|
)
|
171
171
|
|
172
|
-
record =
|
172
|
+
record = Unidata::UniDynArray.new
|
173
173
|
record.replace 1, 'JOHN DOE'
|
174
174
|
record.replace 2, 25
|
175
175
|
record.replace 3, Date.to_unidata(Date.today)
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: unidata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremy Israelsen
|
@@ -11,22 +11,6 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: udjrb
|
16
|
-
version_requirements: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ~>
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 0.0.3
|
21
|
-
none: false
|
22
|
-
requirement: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.0.3
|
27
|
-
none: false
|
28
|
-
prerelease: false
|
29
|
-
type: :runtime
|
30
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: rake
|
32
16
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -83,6 +67,7 @@ extensions: []
|
|
83
67
|
extra_rdoc_files: []
|
84
68
|
files:
|
85
69
|
- lib/unidata.rb
|
70
|
+
- lib/unidata/asjava.jar
|
86
71
|
- lib/unidata/connection.rb
|
87
72
|
- lib/unidata/extensions.rb
|
88
73
|
- lib/unidata/extensions/big_decimal.rb
|
@@ -101,7 +86,7 @@ files:
|
|
101
86
|
- spec/unidata/field_spec.rb
|
102
87
|
- spec/unidata/model_spec.rb
|
103
88
|
- spec/unidata_spec.rb
|
104
|
-
homepage: http://github.com/
|
89
|
+
homepage: http://github.com/jisraelsen/unidata
|
105
90
|
licenses: []
|
106
91
|
post_install_message:
|
107
92
|
rdoc_options: []
|