jmongo 1.0.3 → 1.1.0
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/Gemfile +8 -0
- data/Gemfile.lock +43 -0
- data/Rakefile +72 -0
- data/jmongo.gemspec +84 -6
- data/lib/jmongo.rb +6 -14
- data/lib/jmongo/collection.rb +196 -114
- data/lib/jmongo/connection.rb +39 -13
- data/lib/jmongo/cursor.rb +161 -63
- data/lib/jmongo/db.rb +119 -30
- data/lib/jmongo/exceptions.rb +39 -0
- data/lib/jmongo/mongo-2.6.5.gb1.jar +0 -0
- data/lib/jmongo/mongo/bson.rb +130 -0
- data/lib/jmongo/mongo/collection.rb +185 -0
- data/lib/jmongo/mongo/connection.rb +45 -0
- data/lib/jmongo/mongo/db.rb +31 -0
- data/lib/jmongo/mongo/jmongo.rb +44 -0
- data/lib/jmongo/mongo/mongo.rb +98 -0
- data/lib/jmongo/mongo/ruby_ext.rb +38 -0
- data/lib/jmongo/mongo/utils.rb +136 -0
- data/lib/jmongo/version.rb +1 -1
- data/test-results.txt +98 -0
- data/test/auxillary/1.4_features.rb +166 -0
- data/test/auxillary/authentication_test.rb +68 -0
- data/test/auxillary/autoreconnect_test.rb +41 -0
- data/test/auxillary/fork_test.rb +30 -0
- data/test/auxillary/repl_set_auth_test.rb +58 -0
- data/test/auxillary/slave_connection_test.rb +36 -0
- data/test/auxillary/threaded_authentication_test.rb +101 -0
- data/test/bson/binary_test.rb +15 -0
- data/test/bson/bson_test.rb +657 -0
- data/test/bson/byte_buffer_test.rb +208 -0
- data/test/bson/hash_with_indifferent_access_test.rb +38 -0
- data/test/bson/json_test.rb +17 -0
- data/test/bson/object_id_test.rb +138 -0
- data/test/bson/ordered_hash_test.rb +245 -0
- data/test/bson/test_helper.rb +46 -0
- data/test/bson/timestamp_test.rb +46 -0
- data/test/collection_test.rb +933 -0
- data/test/connection_test.rb +325 -0
- data/test/conversions_test.rb +121 -0
- data/test/cursor_fail_test.rb +75 -0
- data/test/cursor_message_test.rb +43 -0
- data/test/cursor_test.rb +547 -0
- data/test/data/empty_data +0 -0
- data/test/data/sample_data +0 -0
- data/test/data/sample_file.pdf +0 -0
- data/test/data/small_data.txt +1 -0
- data/test/db_api_test.rb +739 -0
- data/test/db_connection_test.rb +15 -0
- data/test/db_test.rb +325 -0
- data/test/grid_file_system_test.rb +260 -0
- data/test/grid_io_test.rb +210 -0
- data/test/grid_test.rb +259 -0
- data/test/load/thin/config.ru +6 -0
- data/test/load/thin/config.yml.template +6 -0
- data/test/load/thin/load.rb +24 -0
- data/test/load/unicorn/config.ru +6 -0
- data/test/load/unicorn/load.rb +23 -0
- data/test/load/unicorn/unicorn.rb.template +29 -0
- data/test/replica_sets/connect_test.rb +111 -0
- data/test/replica_sets/connection_string_test.rb +29 -0
- data/test/replica_sets/count_test.rb +36 -0
- data/test/replica_sets/insert_test.rb +54 -0
- data/test/replica_sets/pooled_insert_test.rb +58 -0
- data/test/replica_sets/query_secondaries.rb +109 -0
- data/test/replica_sets/query_test.rb +52 -0
- data/test/replica_sets/read_preference_test.rb +43 -0
- data/test/replica_sets/refresh_test.rb +123 -0
- data/test/replica_sets/replication_ack_test.rb +71 -0
- data/test/replica_sets/rs_test_helper.rb +27 -0
- data/test/safe_test.rb +68 -0
- data/test/support/hash_with_indifferent_access.rb +186 -0
- data/test/support/keys.rb +45 -0
- data/test/support_test.rb +19 -0
- data/test/test_helper.rb +111 -0
- data/test/threading/threading_with_large_pool_test.rb +90 -0
- data/test/threading_test.rb +88 -0
- data/test/tools/auth_repl_set_manager.rb +14 -0
- data/test/tools/keyfile.txt +1 -0
- data/test/tools/repl_set_manager.rb +377 -0
- data/test/unit/collection_test.rb +128 -0
- data/test/unit/connection_test.rb +85 -0
- data/test/unit/cursor_test.rb +127 -0
- data/test/unit/db_test.rb +96 -0
- data/test/unit/grid_test.rb +51 -0
- data/test/unit/node_test.rb +73 -0
- data/test/unit/pool_manager_test.rb +47 -0
- data/test/unit/pool_test.rb +9 -0
- data/test/unit/read_test.rb +101 -0
- data/test/unit/safe_test.rb +125 -0
- data/test/uri_test.rb +92 -0
- metadata +170 -99
- data/lib/jmongo/ajrb.rb +0 -189
- data/lib/jmongo/jmongo_jext.rb +0 -302
- data/lib/jmongo/mongo-2.6.3.jar +0 -0
- data/lib/jmongo/utils.rb +0 -61
data/lib/jmongo/jmongo_jext.rb
DELETED
@@ -1,302 +0,0 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
require 'java'
|
3
|
-
|
4
|
-
module JMongo
|
5
|
-
java_import com.mongodb.BasicDBList
|
6
|
-
java_import com.mongodb.BasicDBObject
|
7
|
-
java_import com.mongodb.Bytes
|
8
|
-
java_import com.mongodb.DB
|
9
|
-
java_import com.mongodb.DBCollection
|
10
|
-
java_import com.mongodb.DBCursor
|
11
|
-
java_import com.mongodb.DBObject
|
12
|
-
java_import com.mongodb.Mongo
|
13
|
-
java_import com.mongodb.MongoOptions
|
14
|
-
java_import com.mongodb.ServerAddress
|
15
|
-
java_import com.mongodb.WriteConcern
|
16
|
-
java_import com.mongodb.MongoException
|
17
|
-
java_import com.mongodb.MongoURI
|
18
|
-
end
|
19
|
-
|
20
|
-
class Java::ComMongodb::BasicDBObject
|
21
|
-
if RUBY_PLATFORM == 'java' && JRUBY_VERSION =~ /(1\.[6-9]|[2-9]\.[0-9])..*/
|
22
|
-
def hashify
|
23
|
-
self.to_map.to_hash
|
24
|
-
end
|
25
|
-
else
|
26
|
-
def hashify
|
27
|
-
Hash[self.key_set.to_a.zip(self.values.to_a)]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class Java::ComMongodb::BasicDBList
|
33
|
-
def arrayify
|
34
|
-
self.to_array
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# add missing BSON::ObjectId ruby methods
|
39
|
-
class Java::OrgBsonTypes::ObjectId
|
40
|
-
def self.create_pk(doc)
|
41
|
-
doc.has_key?(:_id) || doc.has_key?('_id') ? doc : doc.merge!(:_id => self.new)
|
42
|
-
end
|
43
|
-
|
44
|
-
#"data=", "decode64", "encode64", "decode_b", "b64encode" - shout out if these methods are needed
|
45
|
-
|
46
|
-
def data
|
47
|
-
self.to_byte_array.to_a.map{|x| x & 0xFF}
|
48
|
-
end
|
49
|
-
def inspect
|
50
|
-
"BSON::ObjectID('#{self.to_s}')"
|
51
|
-
end
|
52
|
-
def generation_time
|
53
|
-
Time.at(self.get_time/1000).utc
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
module BSON
|
58
|
-
|
59
|
-
class Java::OrgBsonTypes::ObjectId
|
60
|
-
def self.from_string(str)
|
61
|
-
v = is_valid?(str.to_s)
|
62
|
-
raise BSON::InvalidObjectId, "illegal ObjectID format" unless v
|
63
|
-
new(str.to_s)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
ObjectId = Java::OrgBsonTypes::ObjectId
|
68
|
-
|
69
|
-
OrderedHash = Java::ComMongodb::BasicDBObject
|
70
|
-
|
71
|
-
class Java::ComMongodb::BasicDBObject
|
72
|
-
def get(key)
|
73
|
-
self.java_send(:get,key.to_s)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
class Code < String
|
78
|
-
# copied verbatim from ruby driver
|
79
|
-
# Hash mapping identifiers to their values
|
80
|
-
attr_accessor :scope
|
81
|
-
def initialize(code, scope={})
|
82
|
-
super(code)
|
83
|
-
@scope = scope
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
# Generic Mongo Ruby Driver exception class.
|
89
|
-
class MongoRubyError < StandardError; end
|
90
|
-
|
91
|
-
# Raised when MongoDB itself has returned an error.
|
92
|
-
class MongoDBError < RuntimeError; end
|
93
|
-
|
94
|
-
# This will replace MongoDBError.
|
95
|
-
class BSONError < MongoDBError; end
|
96
|
-
|
97
|
-
# Raised when given a string is not valid utf-8 (Ruby 1.8 only).
|
98
|
-
class InvalidStringEncoding < BSONError; end
|
99
|
-
|
100
|
-
# Raised when attempting to initialize an invalid ObjectId.
|
101
|
-
class InvalidObjectId < BSONError; end
|
102
|
-
class InvalidObjectID < BSONError; end
|
103
|
-
|
104
|
-
# Raised when trying to insert a document that exceeds the 4MB limit or
|
105
|
-
# when the document contains objects that can't be serialized as BSON.
|
106
|
-
class InvalidDocument < BSONError; end
|
107
|
-
|
108
|
-
# Raised when an invalid name is used.
|
109
|
-
class InvalidKeyName < BSONError; end
|
110
|
-
end
|
111
|
-
|
112
|
-
module Mongo
|
113
|
-
def self.logger(logger=nil)
|
114
|
-
logger ? @logger = logger : @logger
|
115
|
-
end
|
116
|
-
# Generic Mongo Ruby Driver exception class.
|
117
|
-
class MongoRubyError < StandardError; end
|
118
|
-
|
119
|
-
# Raised when MongoDB itself has returned an error.
|
120
|
-
class MongoDBError < RuntimeError; end
|
121
|
-
|
122
|
-
# Raised when invalid arguments are sent to Mongo Ruby methods.
|
123
|
-
class MongoArgumentError < MongoRubyError; end
|
124
|
-
|
125
|
-
# Raised on failures in connection to the database server.
|
126
|
-
class ConnectionError < MongoRubyError; end
|
127
|
-
|
128
|
-
# Raised on failures in connection to the database server.
|
129
|
-
class ReplicaSetConnectionError < ConnectionError; end
|
130
|
-
|
131
|
-
# Raised on failures in connection to the database server.
|
132
|
-
class ConnectionTimeoutError < MongoRubyError; end
|
133
|
-
|
134
|
-
# Raised when a connection operation fails.
|
135
|
-
class ConnectionFailure < MongoDBError; end
|
136
|
-
|
137
|
-
# Raised when authentication fails.
|
138
|
-
class AuthenticationError < MongoDBError; end
|
139
|
-
|
140
|
-
# Raised when a database operation fails.
|
141
|
-
class OperationFailure < MongoDBError; end
|
142
|
-
|
143
|
-
# Raised when a socket read operation times out.
|
144
|
-
class OperationTimeout < MongoDBError; end
|
145
|
-
|
146
|
-
# Raised when a client attempts to perform an invalid operation.
|
147
|
-
class InvalidOperation < MongoDBError; end
|
148
|
-
|
149
|
-
# Raised when an invalid collection or database name is used (invalid namespace name).
|
150
|
-
class InvalidNSName < RuntimeError; end
|
151
|
-
|
152
|
-
# Raised when the client supplies an invalid value to sort by.
|
153
|
-
class InvalidSortValueError < MongoRubyError; end
|
154
|
-
end
|
155
|
-
|
156
|
-
__END__
|
157
|
-
|
158
|
-
module BasicDBObjectExtentions
|
159
|
-
def keys
|
160
|
-
self.key_set.to_a
|
161
|
-
end
|
162
|
-
def values
|
163
|
-
self.java_send(:values).to_a
|
164
|
-
end
|
165
|
-
def merge!(other)
|
166
|
-
self.put_all(other)
|
167
|
-
self
|
168
|
-
end
|
169
|
-
def merge(other)
|
170
|
-
obj = new
|
171
|
-
obj.merge!(self)
|
172
|
-
obj.merge!(other)
|
173
|
-
end
|
174
|
-
def put(key,val)
|
175
|
-
self.java_send(:put,key.to_s,val)
|
176
|
-
end
|
177
|
-
def get(key)
|
178
|
-
self.java_send(:get,key.to_s)
|
179
|
-
end
|
180
|
-
def [](key)
|
181
|
-
self.get(key)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
include JMongo::BasicDBObjectExtentions
|
186
|
-
|
187
|
-
# ["ordered_keys=", "invert", "rehash", "replace"] - these methods don't make much sense for a BasicBSONObject and derivative classes
|
188
|
-
|
189
|
-
alias :update :merge!
|
190
|
-
alias :each_pair :each
|
191
|
-
alias :length :size
|
192
|
-
|
193
|
-
def hashify
|
194
|
-
Hash[self.keys.zip(self.values)]
|
195
|
-
end
|
196
|
-
|
197
|
-
def ordered_keys
|
198
|
-
self.keys
|
199
|
-
end
|
200
|
-
|
201
|
-
def index(val)
|
202
|
-
ix = self.values.to_a.index(val)
|
203
|
-
return nil unless ix
|
204
|
-
self.key_set.to_a[ix]
|
205
|
-
end
|
206
|
-
|
207
|
-
def reject!(&block)
|
208
|
-
n = self.size
|
209
|
-
self.each do |k,v|
|
210
|
-
if yield(k, v)
|
211
|
-
delete(k)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
return nil if n == self.size
|
215
|
-
self
|
216
|
-
end
|
217
|
-
|
218
|
-
def each_key
|
219
|
-
keys_ = self.key_set.to_a
|
220
|
-
while keys_.length > 0
|
221
|
-
yield keys_.shift
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def each_value
|
226
|
-
vals = self.values
|
227
|
-
while vals.length > 0
|
228
|
-
yield vals.shift
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def fetch(key,default=nil)
|
233
|
-
v = self.get(key)
|
234
|
-
return v if !!(v)
|
235
|
-
return yield(key) if block_given?
|
236
|
-
return default unless default.nil?
|
237
|
-
raise "index not found"
|
238
|
-
end
|
239
|
-
|
240
|
-
def values_at(*args)
|
241
|
-
ret = []
|
242
|
-
args.each do |key|
|
243
|
-
if self.contains_key?(key)
|
244
|
-
ret << self.get(key)
|
245
|
-
else
|
246
|
-
ret << nil
|
247
|
-
end
|
248
|
-
end
|
249
|
-
ret
|
250
|
-
end
|
251
|
-
alias :indexes :values_at
|
252
|
-
alias :indices :values_at
|
253
|
-
|
254
|
-
def shift
|
255
|
-
if self.size == 0
|
256
|
-
nil
|
257
|
-
else
|
258
|
-
k = self.keys.first
|
259
|
-
[k, self.remove_field(k)]
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
def []=(key,val)
|
264
|
-
k = key.kind_of?(String) ? key : key.to_s
|
265
|
-
self.put(k, val)
|
266
|
-
end
|
267
|
-
|
268
|
-
def store(key,val)
|
269
|
-
k = key.kind_of?(String) ? key : key.to_s
|
270
|
-
self.put(k.dup.freeze, val)
|
271
|
-
end
|
272
|
-
|
273
|
-
def key?(key)
|
274
|
-
self.contains_key?(key)
|
275
|
-
end
|
276
|
-
alias :has_key? :key?
|
277
|
-
|
278
|
-
def value?(val)
|
279
|
-
self.contains_value?(val)
|
280
|
-
end
|
281
|
-
alias :has_value? :value?
|
282
|
-
|
283
|
-
def inspect
|
284
|
-
self.to_hash.inspect
|
285
|
-
end
|
286
|
-
alias :to_s :inspect
|
287
|
-
|
288
|
-
def delete(key)
|
289
|
-
unless self.contains_key?(key)
|
290
|
-
block_given? ? yield(key) : nil
|
291
|
-
else
|
292
|
-
self.remove_field(key)
|
293
|
-
end
|
294
|
-
end
|
295
|
-
|
296
|
-
def delete_if(&block)
|
297
|
-
self.each do |k,v|
|
298
|
-
if yield(k, v)
|
299
|
-
delete(k)
|
300
|
-
end
|
301
|
-
end
|
302
|
-
end
|
data/lib/jmongo/mongo-2.6.3.jar
DELETED
Binary file
|
data/lib/jmongo/utils.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# Copyright (C) 2010 Chuck Remes
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
module Mongo
|
15
|
-
|
16
|
-
# module Utils
|
17
|
-
# def to_dbobject obj
|
18
|
-
# case obj
|
19
|
-
# when Array
|
20
|
-
# array_to_dblist obj
|
21
|
-
# when Hash
|
22
|
-
# hash_to_dbobject obj
|
23
|
-
# else
|
24
|
-
# puts "Un-handled class type [#{obj.class}]"
|
25
|
-
# obj
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# def from_dbobject obj
|
30
|
-
# hsh = {}
|
31
|
-
# obj.toMap.keySet.each do |key|
|
32
|
-
# value = obj.get key
|
33
|
-
# puts "value class [#{value.class}]"
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
#
|
37
|
-
# private
|
38
|
-
#
|
39
|
-
# def hash_to_dbobject doc
|
40
|
-
# obj = JMongo::BasicDBObject.new
|
41
|
-
#
|
42
|
-
# doc.each_pair do |key, value|
|
43
|
-
# obj.append(key, to_dbobject(value))
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# obj
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# def array_to_dblist ary
|
50
|
-
# list = JMongo::BasicDBList.new
|
51
|
-
#
|
52
|
-
# ary.each_with_index do |element, index|
|
53
|
-
# list.put(index, to_dbobject(value))
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# list
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# end # module Utils
|
60
|
-
|
61
|
-
end # module Mongo
|