Class: OrientDbClient::Connection
- Inherits:
-
Object
- Object
- OrientDbClient::Connection
- Defined in:
- lib/orient_db_client/connection.rb
Instance Method Summary collapse
- #close ⇒ Object
- #close_database(session) ⇒ Object
- #closed? ⇒ Boolean
- #cluster_exists?(session, cluster_id_or_name) ⇒ Boolean
- #count(session, cluster_name) ⇒ Object
- #create_cluster(session, type, options) ⇒ Object
- #create_database(session, database, options = {}) ⇒ Object
- #create_record(session, cluster_id, record) ⇒ Object
- #database_exists?(session, database) ⇒ Boolean
- #delete_cluster(session, cluster_id) ⇒ Object
- #delete_database(session, database) ⇒ Object
- #delete_record(session, rid, version) ⇒ Object
- #get_cluster_datarange(session, cluster_id) ⇒ Object
-
#initialize(socket, protocol_version, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #load_record(session, rid) ⇒ Object
- #open_database(database, options = {}) ⇒ Object
- #open_server(options = {}) ⇒ Object
- #query(session, text, options = {}) ⇒ Object
- #reload(session) ⇒ Object
- #update_record(session, rid, record, version) ⇒ Object
Constructor Details
#initialize(socket, protocol_version, options = {}) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 |
# File 'lib/orient_db_client/connection.rb', line 7 def initialize(socket, protocol_version, = {}) @socket = socket @protocol = ([:protocol_factory] || ProtocolFactory).get_protocol(protocol_version) @sessions = {} end |
Instance Method Details
#close ⇒ Object
13 14 15 |
# File 'lib/orient_db_client/connection.rb', line 13 def close @socket.close end |
#close_database(session) ⇒ Object
17 18 19 |
# File 'lib/orient_db_client/connection.rb', line 17 def close_database(session) @protocol.db_close(@socket, session) end |
#closed? ⇒ Boolean
21 22 23 |
# File 'lib/orient_db_client/connection.rb', line 21 def closed? @socket.closed? end |
#cluster_exists?(session, cluster_id_or_name) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/orient_db_client/connection.rb', line 25 def cluster_exists?(session, cluster_id_or_name) result = true begin if cluster_id_or_name.is_a?(String) @protocol.count(@socket, session, cluster_id_or_name) else @protocol.datacluster_datarange(@socket, session, cluster_id_or_name) end rescue OrientDbClient::ProtocolError => err case err.exception_class when 'java.lang.IndexOutOfBoundsException', 'java.lang.IllegalArgumentException' result = false else raise err end end result end |
#count(session, cluster_name) ⇒ Object
46 47 48 |
# File 'lib/orient_db_client/connection.rb', line 46 def count(session, cluster_name) @protocol.count(@socket, session, cluster_name) end |
#create_cluster(session, type, options) ⇒ Object
54 55 56 57 58 |
# File 'lib/orient_db_client/connection.rb', line 54 def create_cluster(session, type, ) result = @protocol.datacluster_add(@socket, session, type, ) result[:message_content][:new_cluster_number] end |
#create_database(session, database, options = {}) ⇒ Object
50 51 52 |
# File 'lib/orient_db_client/connection.rb', line 50 def create_database(session, database, = {}) @protocol.db_create(@socket, session, database, ) end |
#create_record(session, cluster_id, record) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/orient_db_client/connection.rb', line 60 def create_record(session, cluster_id, record) response = @protocol.record_create(@socket, session, cluster_id, record) = response[:message_content] OrientDbClient::Rid.new([:cluster_id], [:cluster_position]) end |
#database_exists?(session, database) ⇒ Boolean
67 68 69 70 71 |
# File 'lib/orient_db_client/connection.rb', line 67 def database_exists?(session, database) response = @protocol.db_exist(@socket, session, database) response[:message_content][:result] == 1 end |
#delete_cluster(session, cluster_id) ⇒ Object
77 78 79 |
# File 'lib/orient_db_client/connection.rb', line 77 def delete_cluster(session, cluster_id) @protocol.datacluster_remove(@socket, session, cluster_id) end |
#delete_database(session, database) ⇒ Object
73 74 75 |
# File 'lib/orient_db_client/connection.rb', line 73 def delete_database(session, database) @protocol.db_delete(@socket, session, database) end |
#delete_record(session, rid, version) ⇒ Object
81 82 83 84 85 |
# File 'lib/orient_db_client/connection.rb', line 81 def delete_record(session, rid, version) response = @protocol.record_delete(@socket, session, rid.cluster_id, rid.cluster_position, version) response[:message_content][:result] == 1 end |
#get_cluster_datarange(session, cluster_id) ⇒ Object
87 88 89 |
# File 'lib/orient_db_client/connection.rb', line 87 def get_cluster_datarange(session, cluster_id) @protocol.datacluster_datarange(@socket, session, cluster_id) end |
#load_record(session, rid) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/orient_db_client/connection.rb', line 91 def load_record(session, rid) rid = OrientDbClient::Rid.new(rid) if rid.is_a?(String) result = @protocol.record_load(@socket, session, rid) if result[:message_content] result[:message_content].tap do |r| r[:cluster_id] = rid.cluster_id r[:cluster_position] = rid.cluster_position end end result end |
#open_database(database, options = {}) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/orient_db_client/connection.rb', line 114 def open_database(database, = {}) response = @protocol.db_open(@socket, database, ) session = response[:session] = response[:message_content] @sessions[session] = DatabaseSession.new([:session], self, [:clusters]) end |
#open_server(options = {}) ⇒ Object
106 107 108 109 110 111 112 |
# File 'lib/orient_db_client/connection.rb', line 106 def open_server( = {}) response = @protocol.connect(@socket, ) session = response[:session] = response[:message_content] @sessions[session] = ServerSession.new([:session], self) end |
#query(session, text, options = {}) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/orient_db_client/connection.rb', line 122 def query(session, text, = {}) [:query_class_name] = :query result = @protocol.command(@socket, session, text, ) result[:message_content] end |
#reload(session) ⇒ Object
130 131 132 133 134 135 136 137 |
# File 'lib/orient_db_client/connection.rb', line 130 def reload(session) result = @protocol.db_reload(@socket, session) clusters = result[:message_content][:clusters] @sessions.values.each do |s| s.send :store_clusters, clusters end end |
#update_record(session, rid, record, version) ⇒ Object
139 140 141 142 143 |
# File 'lib/orient_db_client/connection.rb', line 139 def update_record(session, rid, record, version) response = @protocol.record_update(@socket, session, rid.cluster_id, rid.cluster_position, record, version) response[:message_content][:record_version] end |