This repository has been archived by the owner on Jan 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
connection.rb
211 lines (180 loc) · 5.8 KB
/
connection.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Copyright (C) 2008-2010 10gen Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module Mongo
class Connection
attr_reader :connection
def initialize host = nil, port = nil, opts = {}
@host = host || 'localhost'
@port = port || 27017
server_address = JMongo::ServerAddress.new @host, @port
options = JMongo::MongoOptions.new
options.connectionsPerHost = opts[:pool_size] || 1
options.socketTimeout = opts[:timeout].to_i * 1000 || 5000
@connection = JMongo::Mongo.new server_address, options
end
def self.paired(nodes, opts={})
raise_not_implemented
end
# Initialize a connection to MongoDB using the MongoDB URI spec:
#
# @param uri [String]
# A string of the format mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/database]
#
# @param opts Any of the options available for Connection.new
#
# @return [Mongo::Connection]
def self.from_uri(uri, opts={})
raise_not_implemented
end
# Apply each of the saved database authentications.
#
# @return [Boolean] returns true if authentications exist and succeeed, false
# if none exists.
#
# @raise [AuthenticationError] raises an exception if any one
# authentication fails.
def apply_saved_authentication
raise_not_implemented
end
# Save an authentication to this connection. When connecting,
# the connection will attempt to re-authenticate on every db
# specificed in the list of auths. This method is called automatically
# by DB#authenticate.
#
# @param [String] db_name
# @param [String] username
# @param [String] password
#
# @return [Hash] a hash representing the authentication just added.
def add_auth(db_name, username, password)
raise_not_implemented
end
# Remove a saved authentication for this connection.
#
# @param [String] db_name
#
# @return [Boolean]
def remove_auth(db_name)
raise_not_implemented
end
# Remove all authenication information stored in this connection.
#
# @return [true] this operation return true because it always succeeds.
def clear_auths
raise_not_implemented
end
# Return a hash with all database names
# and their respective sizes on disk.
#
# @return [Hash]
def database_info
raise_not_implemented
end
# Return an array of database names.
#
# @return [Array]
def database_names
raise_not_implemented
end
# Return a database with the given name.
# See DB#new for valid options hash parameters.
#
# @param [String] db_name a valid database name.
#
# @return [Mongo::DB]
#
# @core databases db-instance_method
def db(db_name, options={})
DB.new db_name, self, options
end
# Shortcut for returning a database. Use DB#db to accept options.
#
# @param [String] db_name a valid database name.
#
# @return [Mongo::DB]
#
# @core databases []-instance_method
def [](db_name)
raise_not_implemented
end
# Drop a database.
#
# @param [String] name name of an existing database.
def drop_database(name)
raise_not_implemented
end
# Copy the database +from+ to +to+ on localhost. The +from+ database is
# assumed to be on localhost, but an alternate host can be specified.
#
# @param [String] from name of the database to copy from.
# @param [String] to name of the database to copy to.
# @param [String] from_host host of the 'from' database.
# @param [String] username username for authentication against from_db (>=1.3.x).
# @param [String] password password for authentication against from_db (>=1.3.x).
def copy_database(from, to, from_host="localhost", username=nil, password=nil)
raise_not_implemented
end
# Increment and return the next available request id.
#
# return [Integer]
def get_request_id
raise_not_implemented
end
# Get the build information for the current connection.
#
# @return [Hash]
def server_info
raise_not_implemented
end
# Get the build version of the current server.
#
# @return [Mongo::ServerVersion]
# object allowing easy comparability of version.
def server_version
raise_not_implemented
end
# Is it okay to connect to a slave?
#
# @return [Boolean]
def slave_ok?
raise_not_implemented
end
## Connections and pooling ##
# Send a message to MongoDB, adding the necessary headers.
#
# @param [Integer] operation a MongoDB opcode.
# @param [BSON::ByteBuffer] message a message to send to the database.
# @param [String] log_message text version of +message+ for logging.
#
# @return [True]
def send_message(operation, message, log_message=nil)
raise_not_implemented
end
def send_message_with_safe_check(operation, message, db_name, log_message=nil)
raise_not_implemented
end
def receive_message(operation, message, log_message=nil, socket=nil)
raise_not_implemented
end
def connect_to_master
raise_not_implemented
end
def connected?
raise_not_implemented
end
def close
raise_not_implemented
end
end # class Connection
end # module Mongo