jvertica 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ced7735ddb127ea13cb6842a1902a1acc0258a7
4
- data.tar.gz: 0664701771ce55dd33c22da4e1a082c752034be4
3
+ metadata.gz: c23d87043466109fa58a4068771e6fbdfb5a7130
4
+ data.tar.gz: 970b488aa5d74b94a59fe131d265c56e4ebf8a40
5
5
  SHA512:
6
- metadata.gz: 54184b00b156248c46ed561da8442f4a2b9c133b8ca4847f079c3e1d08af09967c2c2185e51573817fe668b698971069e6aea07e71d8ad6f660fbcfbdbce29d4
7
- data.tar.gz: b20be8aebf799dd32e928bfbbd4009fdedf1b15805647d94fabf8887ad70501c402f8edb17a09870a7c41556be5c094aeb58070461a804b43ad58a4d54b9d832
6
+ metadata.gz: c702a7ef2da491b0b261b1dacd51eec569e386e8d37c1af276069fbb3441451ed8fdaa3ae2c7abb9e33ff28f3a6f1730b1927545bb70ff7bf551e1d4abb639cd
7
+ data.tar.gz: 8eeadf300ea89cbf68f9ba63296a932a7cc2d84e05f5705160960d4bdbc0c55b574edd97bd64fb504443435a4257b54b34b16e1ca408de1d6ce5a5794191d9e3
@@ -1,3 +1,3 @@
1
1
  class Jvertica
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
data/lib/jvertica.rb CHANGED
@@ -16,7 +16,7 @@ class Jvertica
16
16
  password: '',
17
17
  user: 'dbadmin',
18
18
  AutoCommit: false,
19
- }
19
+ }
20
20
 
21
21
  def self.connect options = {}
22
22
  new options
@@ -41,8 +41,8 @@ class Jvertica
41
41
  @connection = begin
42
42
  DriverManager.getConnection "jdbc:vertica://#{host}:#{port}/#{database}", prop
43
43
  rescue => e
44
- raise ConnectionError.new("Connection Failed.\n" +
45
- "Error Message => #{e.message}\n" +
44
+ raise ConnectionError.new("Connection Failed.\n" +
45
+ "Error Message => #{e.message}\n" +
46
46
  "see documentation => #{Constant::CONNECTION_PROPERTY_DOCUMENT_URL}\n")
47
47
  end
48
48
  @closed = false
@@ -58,7 +58,7 @@ class Jvertica
58
58
  end
59
59
 
60
60
  def commit
61
- @connection.commit
61
+ @connection.commit
62
62
  end
63
63
 
64
64
  def rollback
@@ -89,7 +89,7 @@ class Jvertica
89
89
  def query query, &blk
90
90
  stmt = @connection.createStatement
91
91
  case query
92
- when %r{\A\s*copy}miu then raise InvalidQuery.new('cannot use "copy".')
92
+ when %r{\A\s*copy}miu then return stmt.execute query
93
93
  when %r{\A\s*insert}miu then return stmt.executeUpdate query
94
94
  when %r{\A\s*update}miu then return stmt.executeUpdate query
95
95
  when %r{\A\s*delete}miu then return stmt.executeUpdate query
@@ -110,19 +110,22 @@ class Jvertica
110
110
 
111
111
  def copy query, source = nil, &blk
112
112
  raise InvalidQuery.new('can use only "copy".') unless %r{\A\s*copy}miu === query
113
+ if !source.nil?
114
+ copy_stream(query, source, &blk)
115
+ else
116
+ [query(query), nil]
117
+ end
118
+ end
119
+
120
+ private
121
+ def copy_stream query, io = nil, &blk
113
122
  stream = com.vertica.jdbc.VerticaCopyStream.new @connection, query
114
123
  stream.start
115
124
  thread = nil
116
125
  begin
117
- if !source.nil?
118
126
 
119
- if source.is_a? IO
120
- stream.addStream org.jruby.util.IOInputStream.new(source)
121
- else
122
- raise InvalidObject.new("source must be a IO.")
123
- end
127
+ if block_given?
124
128
 
125
- elsif block_given?
126
129
  i, o = IO.pipe
127
130
  begin
128
131
  thread = Thread.new do
@@ -134,8 +137,17 @@ class Jvertica
134
137
  raise e
135
138
  ensure
136
139
  end
140
+
141
+ else
142
+
143
+ if source.is_a? IO
144
+ stream.addStream org.jruby.util.IOInputStream.new(source)
145
+ else
146
+ raise InvalidObject.new("source must be a IO.")
147
+ end
148
+
137
149
  end
138
-
150
+
139
151
  rescue => e
140
152
  r = stream.finish
141
153
  raise e.class.new("[affected rows: #{r}] #{e.message}")
@@ -147,14 +159,13 @@ class Jvertica
147
159
  results = stream.finish
148
160
  rescue => e
149
161
  raise e
150
- ensure
151
- thread.join
162
+ ensure
163
+ thread.join unless thread.nil?
152
164
  end
153
165
 
154
166
  [results, rejects.to_ary]
155
167
  end
156
168
 
157
- private
158
169
  class ConnectionError < StandardError
159
170
  end
160
171
 
@@ -357,7 +368,7 @@ class Jvertica
357
368
  module Constant
358
369
  CONNECTION_PROPERTY_DOCUMENT_URL =
359
370
  'http://my.vertica.com/docs/7.1.x/HTML/index.htm#Authoring/ProgrammersGuide/ClientJDBC/JDBCConnectionProperties.htm'
360
-
371
+
361
372
  RUBY_SQL_TYPE_MAP = {
362
373
  Fixnum => java.sql.Types::INTEGER,
363
374
  Bignum => java.sql.Types::BIGINT,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jvertica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - takahiro.nakayama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement