voltdbjruby 0.5.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eaaab5d2c7a8236503024c7f6ee4499582ae63be
4
+ data.tar.gz: 064dab498dcf9ad47fe7ecee78e44ca6d6ea0119
5
+ SHA512:
6
+ metadata.gz: 203959588f2cb4192d490d732104b5c01f80a11751be0a7889561466141635f03fbdee66aced11cce3ade8568195baaf829b7d766a5a2b7bb5c28f009b955aa9
7
+ data.tar.gz: 2748fd2b03f2dc0b323d5fa0d7f066984b54fba07107c99e70700a320916296f8c8f1f5aeb55846ca78ca9a75a7bd5d6d0cd82d4579ed8a057910847c3c21e8b
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-version
11
+ examples.txt
12
+ *.gem
13
+ Jarfile
14
+ Jarfile.lock
15
+ .jbundler
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ dist: trusty
2
+ sudo: false
3
+
4
+ language: ruby
5
+ cache: bundler
6
+ rvm:
7
+ - jruby-9.1.8.0
8
+ jdk:
9
+ - openjdk8
10
+
11
+ install: bin/setup
12
+ script: jruby -G -S rake
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## next
4
+
5
+ - Remove `pry` as a development dependency
6
+ - Add the examples dir with the Hello World example
7
+ [#5](https://github.com/full360/voltdb-client-jruby/pull/5)
8
+ - Set Platform to Java for the Gem and Vendor the `voltdbclient-6.8.jar` using
9
+ `jar-dependencies` [#6](https://github.com/full360/voltdb-client-jruby/pull/6)
10
+
11
+ ## 0.4.1
12
+
13
+ - Remove `voltdbclient-6.8.jar` as a dependency from the Gem
14
+ - Update development dependencies
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alberto@albertogrespan.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in voltdb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alberto Grespan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # Voltdb JRuby Client
2
+
3
+ A thin wrapper around the VoltDB Java client.
4
+
5
+ ## Versions
6
+
7
+ We've decided that vendoring the `voltdbclient-x.x.jar` in the Gem as a
8
+ dependency is the right way to do it. We are using VoltDB 6.8 and for that
9
+ reason that's the one that's vendored. We are open on doing a different thing if
10
+ it's the right solution.
11
+
12
+ If required we could do multiple releases with different vendored clients. Just
13
+ open an issue.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ gem "voltdbjruby"
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install voltdbjruby
28
+
29
+ ## Usage
30
+
31
+ ### Basic example
32
+
33
+ ```ruby
34
+ require "voltdb"
35
+
36
+ # Create a config
37
+ config = Voltdb::ClientConfig.new()
38
+
39
+ # Create a client and pass the config
40
+ voltdb_client = Voltdb::Client.create_client(config)
41
+
42
+ # Create a connection
43
+ voltdb_client.create_connection("localhost")
44
+
45
+ # Synchronous example
46
+ response = voltdb_client.call_procedure("SampleProc", 123, "abc")
47
+
48
+ # Asynchronous example
49
+ queued = voltdb_client.call_procedure("SampleProc", 123, "abc") do |response|
50
+ # interact with the async response...
51
+ end
52
+ ```
53
+
54
+ ### Utilities
55
+
56
+ Utilities are a custom addition from Full 360 to DRY things a little and add
57
+ some Ruby idioms.
58
+
59
+ #### ClientResponse utilities
60
+
61
+ ```ruby
62
+ ...
63
+
64
+ User = Struct.new(:id, :name)
65
+
66
+ # Synchronous example
67
+ response = voltdb_client.call_procedure("GetUsers")
68
+
69
+ response.map(0) do |row|
70
+ User.new(row.get_long(0), row.get_string(1))
71
+ end
72
+
73
+ response = voltdb_client.call_procedure("GetUser", 1)
74
+
75
+ response.map_first_row(0) do |row|
76
+ User.new(row.get_long(0), row.get_string(1))
77
+ end
78
+
79
+ # Asynchronous example
80
+ queued = voltdb_client.call_procedure("GetUsers") do |response|
81
+ response.map(0) do |row|
82
+ User.new(row.get_long(0), row.get_string(1))
83
+ end
84
+ end
85
+ ```
86
+
87
+ #### VoltTableRow utilities
88
+
89
+ ```ruby
90
+ User = Struct.new(:id, :name, :active, :created_at)
91
+
92
+ response = voltdb_client.call_procedure("GetUser", 1)
93
+
94
+ response.map_first_row(0) do |row|
95
+ User.new(
96
+ row.get_long(0),
97
+ row.get_string(1),
98
+ row.get_long_as_boolean(2),
99
+ row.get_timestamp_as_ruby_time(3)
100
+ )
101
+ end
102
+ ```
103
+
104
+ ## Development
105
+
106
+ After checking out the repo, run `bin/setup` to install dependencies. You can
107
+ also run `bin/console` for an interactive prompt that will allow you to
108
+ experiment.
109
+
110
+ To install this gem onto your local machine, run `bundle exec rake install`. To
111
+ release a new version, update the version number in `version.rb`, and then run
112
+ `bundle exec rake release`, which will create a git tag for the version, push
113
+ git commits and tags, and push the `.gem` file to
114
+ [rubygems.org](https://rubygems.org).
115
+
116
+ ## Contributing
117
+
118
+ Bug reports and pull requests are welcome on GitHub at
119
+ https://github.com/full360/voltdb-client-jruby. This project is intended to be a
120
+ safe, welcoming space for collaboration, and contributors are expected to adhere
121
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
122
+
123
+ ## License
124
+
125
+ The gem is available as open source under the terms of the [MIT
126
+ License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir["tasks/**/*.rake"].each { |task| load task }
4
+
5
+ task default: %w(spec)
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "voltdb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,48 @@
1
+ module Voltdb
2
+ class ProcCallback
3
+ include Java::OrgVoltdbClient::ClientResponse
4
+ include Java::OrgVoltdbClient::ProcedureCallback
5
+
6
+ def initialize(&block)
7
+ @block = block
8
+ end
9
+
10
+ def client_callback(client_response)
11
+ client_response.extend(ClientResponseUtils)
12
+ @block.call(client_response)
13
+ end
14
+ end
15
+
16
+ class BulkLoaderFailureCallback
17
+ java_import "org.voltdb.client.VoltBulkLoader.BulkLoaderFailureCallBack"
18
+ include Java::OrgVoltdbClient::ClientResponse
19
+ include Java::OrgVoltdbClientVoltBulkLoader::BulkLoaderFailureCallBack
20
+
21
+ def initialize(&block)
22
+ @block = block
23
+ end
24
+
25
+ def failure_callback(row_handle, field_list, client_response)
26
+ client_response.extend(ClientResponseUtils)
27
+ @block.call(row_handle, field_list.to_ary, client_response)
28
+ end
29
+ end
30
+
31
+ class AllPartitionProcCallback
32
+ java_import Java::OrgVoltdbClient::ClientResponseWithPartitionKey
33
+ include Java::OrgVoltdbClient::AllPartitionProcedureCallback
34
+
35
+ def initialize(&block)
36
+ @block = block
37
+ end
38
+
39
+ def client_callback(client_response_with_partition_key)
40
+ response = client_response_with_partition_key.map do |partition|
41
+ partition.response.extend(ClientResponseUtils)
42
+ partition
43
+ end
44
+
45
+ @block.call(response)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,198 @@
1
+ module Voltdb
2
+ class Client
3
+ include ClientUtils
4
+ extend Forwardable
5
+
6
+ java_import Java::OrgVoltdbClient::Client
7
+ java_import Java::OrgVoltdbClient::ClientFactory
8
+
9
+ # Persist ClientResponseImpl to avoid the warning when we extend the object
10
+ Java::OrgVoltdb::ClientResponseImpl.__persistent__ = true
11
+
12
+ attr_reader :java_client
13
+
14
+ # Factory of Voltdb::Client
15
+ #
16
+ # @param config Voltdb::ClientConfig
17
+ # @return Voltdb::Client
18
+ def self.create_client(config)
19
+ client = ClientFactory.create_client(config)
20
+
21
+ self.new(client)
22
+ end
23
+
24
+ def initialize(java_client)
25
+ @java_client = java_client
26
+ end
27
+
28
+ # Invokes a voltdb stored procedure based on its procedure name, a list of
29
+ # params and a block only if an asynchronous call is required
30
+ #
31
+ # @param proc_name [String] the stored procedure name
32
+ # @param *params [Array<Object>] a list of params
33
+ # @return [Java::OrgVoltdbClient::ClientResponse, True, False] Voltdb
34
+ # client response if the procedure was called synchronously, else will
35
+ # return true if the procedure was properly queued or false if it was not
36
+ # @raise [ProcCallException, NoConnectionsException, IOException]
37
+ # ProcCallException will be returned if called synchronously
38
+ def call_procedure(proc_name, *params, &block)
39
+ if block_given?
40
+ cb = ProcCallback.new(&block)
41
+ java_client.call_procedure(cb, proc_name, *params_to_java_objects(*params))
42
+ else
43
+ response = java_client.call_procedure(proc_name, *params_to_java_objects(*params))
44
+ response.extend(ClientResponseUtils)
45
+ response
46
+ end
47
+ end
48
+
49
+ # Invokes a voltdb stored procedure with an specific timeout a procedure
50
+ # name, a list of params and a block only if an asynchronous call is
51
+ # required
52
+ #
53
+ # @param query_timeout [Fixnum] the stored procedure timeout
54
+ # @param proc_name [String] the stored procedure name
55
+ # @param *params [Array<Object>] a list of params
56
+ # @return [Java::OrgVoltdbClient::ClientResponse, True, False] Voltdb
57
+ # client response if the procedure was called synchronously, else will
58
+ # return true if the procedure was properly queued or false if it was not
59
+ # @raise [ProcCallException, NoConnectionsException, IOException]
60
+ # ProcCallException will be returned if called synchronously
61
+ def call_procedure_with_timeout(query_timeout, proc_name, *params, &block)
62
+ if block_given?
63
+ cb = ProcCallback.new(&block)
64
+ java_client.call_procedure_with_timeout(cb, query_timeout, proc_name, *params_to_java_objects(*params))
65
+ else
66
+ response = java_client.call_procedure_with_timeout(query_timeout, proc_name, *params_to_java_objects(*params))
67
+ response.extend(ClientResponseUtils)
68
+ response
69
+ end
70
+ end
71
+
72
+ # This method is a convenience method that is equivalent to reading the
73
+ # catalog file into a byte array in Java code, then calling call_procedure
74
+ # with "@UpdateApplicationCatalog" as the procedure name, followed by they
75
+ # bytes of the catalog and the string value of the deployment file. If a
76
+ # block is passed to the method an asyncronous call will be made
77
+ #
78
+ # @param catalog_path [String] the path to the voltdb catalog
79
+ # @param deployment_path [String] deployment_path the path to the
80
+ # deployment.xml file
81
+ # @return [Java::OrgVoltdbClient::ClientResponse, True, False] Voltdb
82
+ # client response if the procedure was called synchronously, else will
83
+ # return true if the procedure was properly queued or false if it was not
84
+ # @raise [ProcCallException, NoConnectionsException, IOException]
85
+ # ProcCallException will be returned if called synchronously
86
+ def update_application_catalog(catalog_path, deployment_path, &block)
87
+ if block_given?
88
+ cb = ProcCallback.new(&block)
89
+ java_client.update_application_catalog(cb, catalog_path, deployment_path)
90
+ else
91
+ response = java_client.update_application_catalog(catalog_path, deployment_path)
92
+ response.extend(ClientResponseUtils)
93
+ response
94
+ end
95
+ end
96
+
97
+ # This method is a convenience method that is equivalent to reading a
98
+ # jarfile containing to be added/updated into a byte array in Java code,
99
+ # then calling call_procedure with "@UpdateClasses" as the procedure name,
100
+ # followed by the bytes of the jarfile and a string containing a
101
+ # comma-separates list of classes to delete from the catalog.If a block is
102
+ # passed to the method an asyncronous call will be made
103
+ #
104
+ # @param jar_path [String] path to the jar file with new/update clases
105
+ # @param classes_to_delete [String,String] comma-separated list of classes
106
+ # to delete
107
+ # @return [Java::OrgVoltdbClient::ClientResponse, True, False] Voltdb
108
+ # client response if the procedure was called synchronously, else will
109
+ # return true if the procedure was properly queued or false if it was not
110
+ # @raise [ProcCallException, NoConnectionsException, IOException]
111
+ # ProcCallException will be returned if called synchronously
112
+ def update_classes(jar_path, classes_to_delete, &block)
113
+ if block_given?
114
+ cb = ProcCallback.new(&block)
115
+ java_client.update_classes(cb, jar_path, classes_to_delete)
116
+ else
117
+ response = java_client.update_classes(jar_path, classes_to_delete)
118
+ response.extend(ClientResponseUtils)
119
+ response
120
+ end
121
+ end
122
+
123
+ # Get an identifier for the cluster that this client is currently connected
124
+ # to. This will be null if the client has not been connected. Currently
125
+ # these values have logical meaning, but they should just be interpreted as
126
+ # a unique per-cluster value
127
+ #
128
+ # @return [Array<Fixnum>] An array of Fixnum containing the millisecond
129
+ # timestamp when the cluster was started and the leader IP address
130
+ def get_instance_id
131
+ java_client.get_instance_id.to_ary
132
+ end
133
+
134
+ # Get the instantaneous values of the rate limiting values for this client
135
+ #
136
+ # @return [Array<Fixnum>] Array of Fixnum representing max throughput/sec
137
+ # and max outstanding txns
138
+ def get_throughput_and_outstanding_txn_limits
139
+ java_client.get_throughput_and_outstanding_txn_limits.to_ary
140
+ end
141
+
142
+ # Get the list of VoltDB server hosts that this client has open TCP
143
+ # connections to
144
+ #
145
+ # @return [Array<InetSocketAddress>] An list of InetSocketAddress
146
+ # representing the connected hosts
147
+ def get_connected_host_list
148
+ java_client.get_connected_host_list.to_ary
149
+ end
150
+
151
+ # Creates a new instance of a VoltBulkLoader that is bound to this Client.
152
+ # Multiple instances of a VoltBulkLoader created by a single Client will
153
+ # share some resources, particularly if they are inserting into the same
154
+ # table
155
+ #
156
+ # @param table_name [String] that bulk inserts are to be applied to
157
+ # @param max_batch_size [Fixnum] to collect for the table before pushing a
158
+ # bulk insert
159
+ # @param [Boolean] upsert true if want upsert instead of insert
160
+ # @return [VoltBulkLoader]
161
+ # @raise [Exception] if tableName can't be found in the catalog
162
+ def get_new_bulk_loader(table_name, max_batch_size, upsert, &block)
163
+ cb = BulkLoaderFailureCallback.new(&block)
164
+
165
+ if upsert
166
+ java_client.get_new_bulk_loader(table_name, max_batch_size, upsert, cb)
167
+ else
168
+ java_client.get_new_bulk_loader(table_name, max_batch_size, cb)
169
+ end
170
+ end
171
+
172
+ # The method uses system procedure @GetPartitionKeys to get a set of
173
+ # partition values and then execute the stored procedure one partition at a
174
+ # time, and return an aggregated response. If a block is passed to the
175
+ # method an asyncronous call will be made
176
+ #
177
+ # @param proc_name [String] proc_name the stored procedure name
178
+ # @param *param [Array<Object>] a list of params
179
+ # @return [ClientResponseWithPartitionKey, True, False] instances of
180
+ # procedure call results
181
+ # @raise [ProcCallException, NoConnectionsException, IOException]
182
+ def call_all_partition_procedure(proc_name, *params, &block)
183
+ if block_given?
184
+ cb = AllPartitionProcCallback.new(&block)
185
+ java_client.call_all_partition_procedure(cb, proc_name, *params_to_java_objects(*params))
186
+ else
187
+ java_client.call_all_partition_procedure(proc_name, *params_to_java_objects(*params)).map do |partition|
188
+ partition.response.extend(ClientResponseUtils)
189
+ partition
190
+ end
191
+ end
192
+ end
193
+
194
+ def_delegators :java_client,
195
+ :create_connection, :drain, :close, :create_stats_context,
196
+ :get_build_string, :write_summary_csv
197
+ end
198
+ end
@@ -0,0 +1,3 @@
1
+ module Voltdb
2
+ class ClientConfig < Java::OrgVoltdbClient::ClientConfig; end
3
+ end
@@ -0,0 +1,85 @@
1
+ module Voltdb
2
+ module ClientResponseUtils
3
+ java_import Java::OrgVoltdbClient::Client
4
+ java_import Java::OrgVoltdbClient::ClientResponse
5
+ java_import Java::OrgVoltdb::VoltTableRow
6
+
7
+ # This method is used for mapping VoltTableRows to an object. It receives
8
+ # the index of the VoltTable that we want to map and a block that will be
9
+ # executed in that context
10
+ #
11
+ # @param client_response [ClientResponseImpl] a voltdb ClientResponse
12
+ # interface implementation
13
+ # @param index [Fixnum] VoltTable index
14
+ # @param validate_status [Boolean] validate status of the client response
15
+ # @yield [VoltTableRow]
16
+ # @return [Array<Object, Object>]
17
+ def self.map_client_response_result(client_response, index, validate_status = true, &block)
18
+ validate_client_response_status(client_response) if (validate_status)
19
+ VoltTableUtils.map_volt_table(client_response.get_results[index], &block)
20
+ end
21
+
22
+ # This method is used for mapping the first row from a VoltTableRow to an
23
+ # object. It receives the index of the VoltTable that we want to map and a
24
+ # block that will be executed in that context
25
+ #
26
+ # @param client_response [ClientResponseImpl] a voltdb ClientResponse
27
+ # interface implementation
28
+ # @param index [Fixnum] VoltTable index
29
+ # @param validate_status [Boolean] validate status of the client response
30
+ # @yield [VoltTableRow]
31
+ # @return [Array<Object>]
32
+ def self.map_first_row_from_client_response_result(client_response, index, validate_status = true, &block)
33
+ validate_client_response_status(client_response) if (validate_status)
34
+ VoltTableUtils.map_first_row_from_volt_table(client_response.get_results[index], &block)
35
+ end
36
+
37
+ # Checks that the status of the client response is SUCCESS. If not, it
38
+ # throws an exception
39
+ #
40
+ # @param client_response [ClientResponseImpl] a voltdb ClientResponse
41
+ # interface implementation
42
+ # @return the same client response passed in when its status is equal to
43
+ # <code>ClientResponse.SUCCESS</code>
44
+ # @raise [ClientResponseStatusError] if the status is not SUCCESS
45
+ def self.validate_client_response_status(client_response)
46
+ unless ClientResponse.SUCCESS == client_response.get_status
47
+ raise ClientResponseStatusError.new(client_response)
48
+ end
49
+
50
+ client_response
51
+ end
52
+
53
+ # This method is used when we extend the Voltdb ClientResponse interface
54
+ # and it's used for mapping VoltTableRows to an object. It receives the
55
+ # index of the VoltTable that we want to map and a block that will be
56
+ # executed in that context
57
+ #
58
+ # @param index [Fixnum] VoltTable index
59
+ # @yield [VoltTableRow]
60
+ # @return [Array<Object, Object>]
61
+ def map(index, validate_status = true, &block)
62
+ ClientResponseUtils.map_client_response_result(self, index, validate_status, &block)
63
+ end
64
+
65
+ # This method is used when we extend the Voltdb ClientResponse interface
66
+ # and it's used for mapping the first row from a VoltTableRow to an object.
67
+ # It receives the index of the VoltTable that we want to map and a block
68
+ # that will be executed in that context
69
+ #
70
+ # @param index [Fixnum] VoltTable index
71
+ # @yield [VoltTableRow]
72
+ # @return [Array<Object>]
73
+ def map_first_row(index, validate_status = true, &block)
74
+ ClientResponseUtils.map_first_row_from_client_response_result(self, index, validate_status, &block)
75
+ end
76
+
77
+ # This method is used when we extend the Voltdb ClientResponse interface
78
+ # and it's used for valitation on the client response
79
+ #
80
+ # @return [client_response]
81
+ def validate_status
82
+ ClientResponseUtils.validate_client_response_status(self)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,39 @@
1
+ module Voltdb
2
+ module ClientUtils
3
+ java_import Java::OrgVoltdbTypes::TimestampType
4
+ java_import Java::OrgVoltdbClient::Client
5
+
6
+ # Transform Ruby objects to Java objects that VoltDB understands
7
+ #
8
+ # @param *params [Array<Object>] list of params
9
+ # @return [Array<JavaObjects>]
10
+ def params_to_java_objects(*params)
11
+ params.map do |param|
12
+ case param
13
+ when DateTime, Date, Time
14
+ TimestampType.new(param.strftime("%F %T.%L"))
15
+ else
16
+ param
17
+ end
18
+ end
19
+ end
20
+
21
+ # Transform a host:port or a host into an array of host and port
22
+ #
23
+ # @param address [String] voltdb server address
24
+ # @param default_port [Fixnum] override the default voltdb server port
25
+ # @return [Array<String, Fixnum>] represents host address and port
26
+ def host_and_port_from_address(address, default_port = Client.VOLTDB_SERVER_PORT)
27
+ s = address.split(":")
28
+
29
+ case s.size
30
+ when 1
31
+ ["#{s[0]}", default_port]
32
+ when 2
33
+ ["#{s[0]}", s[1].to_i]
34
+ else
35
+ ["", 0]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ module Voltdb
2
+ class ClientResponseStatusError < StandardError
3
+ attr_reader :client_response
4
+
5
+ def initialize(client_response, message = "Client response not successful")
6
+ @client_response = client_response
7
+ super(message)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Voltdb
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,58 @@
1
+ module Voltdb
2
+ module VoltTableRowUtils
3
+
4
+ # Get a long value from a VoltTableRow as a boolean value
5
+ #
6
+ # @param column_index_or_name [Fixnum, String]
7
+ # @return [Boolean]
8
+ def get_long_as_boolean(column_index_or_name)
9
+ self.get_long(column_index_or_name) == 1
10
+ end
11
+
12
+ # Get the value of the column or nil
13
+ #
14
+ # @param column_index_or_name [Fixnum, String]
15
+ # @return [VoltType, Boolean]
16
+ def get_long_or_nil(column_index_or_name)
17
+ value = self.get_long(column_index_or_name)
18
+
19
+ self.was_null? ? nil : value
20
+ end
21
+
22
+ # Get a Ruby DateTime from a VoltTableRow timestamp type value
23
+ #
24
+ # @param column_index_or_name [Fixnum, String]
25
+ # @return [DateTime]
26
+ def get_timestamp_as_ruby_date_time(column_index_or_name)
27
+ timestamp = get_timestamp_for_ruby(column_index_or_name)
28
+
29
+ timestamp ? DateTime.parse(timestamp.to_s) : timestamp
30
+ end
31
+
32
+ # Get a Ruby Date from a VoltTableRow timestamp type value
33
+ #
34
+ # @param column_index_or_name [Fixnum, String]
35
+ # @return [Date]
36
+ def get_timestamp_as_ruby_date(column_index_or_name)
37
+ timestamp = get_timestamp_for_ruby(column_index_or_name)
38
+
39
+ timestamp ? Date.parse(timestamp.to_s) : timestamp
40
+ end
41
+
42
+ # Get a Ruby Time from a VoltTableRow timestamp type value
43
+ #
44
+ # @param column_index_or_name [Fixnum, String]
45
+ # @return [Time]
46
+ def get_timestamp_as_ruby_time(column_index_or_name)
47
+ timestamp = get_timestamp_for_ruby(column_index_or_name)
48
+
49
+ timestamp ? Time.parse(timestamp.to_s) : timestamp
50
+ end
51
+
52
+ private
53
+
54
+ def get_timestamp_for_ruby(column_index_or_name)
55
+ self.get_timestamp_as_sql_timestamp(column_index_or_name)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,68 @@
1
+ module Voltdb
2
+ module VoltTableUtils
3
+ java_import Java::OrgVoltdb::VoltTable
4
+ java_import Java::OrgVoltdb::VoltTableRow
5
+
6
+ # Persist VoltTable to avoid the warning when we duplicate the object to
7
+ # extend it
8
+ Java::OrgVoltdb::VoltTable.__persistent__ = true
9
+
10
+ # This method is used when we extend the VoltDB VoltTable interface and
11
+ # it's used to iterate over a VoltTableRow while also adding VoltTableRow
12
+ # Ruby Utils
13
+ #
14
+ # @param volt_table [VoltTable]
15
+ # @yield [VoltTableRow]
16
+ # @return [Array<Object, Object>]
17
+ def self.map_volt_table(volt_table, &block)
18
+ results = []
19
+
20
+ volt_table.reset_row_position
21
+ volt_table.extend(VoltTableRowUtils)
22
+
23
+ while(volt_table.advance_row) do
24
+ results << block.call(volt_table)
25
+ end
26
+
27
+ results
28
+ end
29
+
30
+ # This method is used when we extend the VoltDB VoltTable interface and
31
+ # it's used to iterate over the first row of a VoltTableRow while also
32
+ # adding VoltTableRow Ruby Utils
33
+ #
34
+ # @param volt_table [VoltTable]
35
+ # @yield [VoltTableRow]
36
+ # @return [Object, nil]
37
+ def self.map_first_row_from_volt_table(volt_table, &block)
38
+ volt_table.reset_row_position
39
+ volt_table.extend(VoltTableRowUtils)
40
+
41
+ if(volt_table.advance_row)
42
+ block.call(volt_table)
43
+ else
44
+ nil
45
+ end
46
+ end
47
+
48
+ # This method is used when we extend the VoltDB VoltTable interface and
49
+ # it's used to iterate over a VoltTableRow while also adding VoltTableRow
50
+ # Ruby Utils
51
+ #
52
+ # @yield [VoltTableRow]
53
+ # @return [Array<Object, Object>]
54
+ def map
55
+ VoltTableUtils.map_volt_table(self, &block)
56
+ end
57
+
58
+ # This method is used when we extend the VoltDB VoltTable interface and
59
+ # it's used to iterate over the first row of a VoltTableRow while also
60
+ # adding VoltTableRow Ruby Utils
61
+ #
62
+ # @yield [VoltTableRow]
63
+ # @return [Object, nil]
64
+ def map_first_row
65
+ VoltTableUtils.map_first_row_from_volt_table(self, &block)
66
+ end
67
+ end
68
+ end
data/lib/voltdb.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "voltdbjruby_jars"
2
+ require "forwardable"
3
+ require "date"
4
+
5
+ module Voltdb
6
+ autoload :ClientResponseStatusError, "voltdb/exceptions"
7
+ autoload :ClientConfig, "voltdb/client_config"
8
+ autoload :ClientUtils, "voltdb/client_utils"
9
+ autoload :Client, "voltdb/client"
10
+ autoload :ProcCallback, "voltdb/callbacks"
11
+ autoload :BulkLoaderFailureCallback, "voltdb/callbacks"
12
+ autoload :AllPartitionProcCallback, "voltdb/callbacks"
13
+ autoload :ClientResponseUtils, "voltdb/client_response_utils"
14
+ autoload :VoltTableUtils, "voltdb/volt_table_utils"
15
+ autoload :VoltTableRowUtils, "voltdb/volt_table_row_utils"
16
+ autoload :VERSION, "voltdb/version"
17
+ end
@@ -0,0 +1,10 @@
1
+ # this is a generated file, to avoid over-writing it just delete this comment
2
+ begin
3
+ require 'jar_dependencies'
4
+ rescue LoadError
5
+ require 'org/voltdb/voltdbclient/6.8/voltdbclient-6.8.jar'
6
+ end
7
+
8
+ if defined? Jars
9
+ require_jar( 'org.voltdb', 'voltdbclient', '6.8' )
10
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,3 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new
data/voltdb.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'voltdb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "voltdbjruby"
8
+ spec.version = Voltdb::VERSION
9
+ spec.authors = ["Alberto Grespan"]
10
+ spec.email = ["alberto@albertogrespan.com"]
11
+
12
+ spec.summary = %q{JRuby VoltDB Client}
13
+ spec.description = %q{A thin wrapper around the VoltDB Java client}
14
+ spec.homepage = "https://github.com/full360/voltdb-client-jruby"
15
+ spec.license = "MIT"
16
+
17
+ # This is important to get the jars installed
18
+ spec.platform = "java"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(examples|test|spec|features)/})
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.requirements << "jar org.voltdb, voltdbclient, 6.8"
28
+
29
+ spec.add_development_dependency "jar-dependencies", "~> 0.3"
30
+ spec.add_development_dependency "bundler", "~> 1.14"
31
+ spec.add_development_dependency "rake", "~> 12"
32
+ spec.add_development_dependency "rspec", "~> 3.5"
33
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voltdbjruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: java
6
+ authors:
7
+ - Alberto Grespan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.3'
19
+ name: jar-dependencies
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.14'
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '12'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '12'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.5'
61
+ name: rspec
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
69
+ description: A thin wrapper around the VoltDB Java client
70
+ email:
71
+ - alberto@albertogrespan.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/org/voltdb/voltdbclient/6.8/voltdbclient-6.8.jar
88
+ - lib/voltdb.rb
89
+ - lib/voltdb/callbacks.rb
90
+ - lib/voltdb/client.rb
91
+ - lib/voltdb/client_config.rb
92
+ - lib/voltdb/client_response_utils.rb
93
+ - lib/voltdb/client_utils.rb
94
+ - lib/voltdb/exceptions.rb
95
+ - lib/voltdb/version.rb
96
+ - lib/voltdb/volt_table_row_utils.rb
97
+ - lib/voltdb/volt_table_utils.rb
98
+ - lib/voltdbjruby_jars.rb
99
+ - tasks/rspec.rake
100
+ - voltdb.gemspec
101
+ homepage: https://github.com/full360/voltdb-client-jruby
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements:
120
+ - jar org.voltdb, voltdbclient, 6.8
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.11
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: JRuby VoltDB Client
126
+ test_files: []