Class: OrientDbClient::Protocols::Protocol9

Inherits:
Protocol7
  • Object
show all
Defined in:
lib/orient_db_client/protocols/protocol9.rb

Constant Summary collapse

VERSION =
9

Constants inherited from Protocol7

OrientDbClient::Protocols::Protocol7::COMMAND_CLASS, OrientDbClient::Protocols::Protocol7::DRIVER_NAME, OrientDbClient::Protocols::Protocol7::DRIVER_VERSION, OrientDbClient::Protocols::Protocol7::NEW_SESSION, OrientDbClient::Protocols::Protocol7::QUERY_CLASS

Class Method Summary collapse

Methods inherited from Protocol7

connect, count, datacluster_add, datacluster_datarange, datacluster_remove, db_close, db_countrecords, db_delete, db_exist, db_reload, db_size, deserializer, record_create, record_delete, record_update, serializer, version

Class Method Details

.command(socket, session, command, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/orient_db_client/protocols/protocol9.rb', line 9

def self.command(socket, session, command, options = {})
    options[:query_class_name].tap do |qcn|
        if qcn.is_a?(Symbol)
            qcn = case qcn
                when :query then 'q'
                when :command then 'c'
            end
        end

        if qcn.nil? || qcn == 'com.orientechnologies.orient.core.sql.query.OSQLSynchQuery'
            qcn = 'q' 
        end

        options[:query_class_name] = qcn
    end

    super socket, session, command, options
end

.db_create(socket, session, database, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/orient_db_client/protocols/protocol9.rb', line 28

def self.db_create(socket, session, database, options = {})
    if options.is_a?(String)
        options = { :storage_type => options }
    end

    options = {
        :database_type => 'document'
    }.merge(options)

    super
end

.db_open(socket, database, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/orient_db_client/protocols/protocol9.rb', line 40

def self.db_open(socket, database, options = {})
    socket.write NetworkMessage.new { |m|
        m.add :byte,    Operations::DB_OPEN
        m.add :integer, NEW_SESSION
        m.add :string,  DRIVER_NAME
        m.add :string,  DRIVER_VERSION
        m.add :short,   self.version
        m.add :integer, 0
        m.add :string,  database
        m.add :string,  options[:database_type] || "document"
        m.add :string,  options[:user]
        m.add :string,  options[:password]
    }.pack

    read_response(socket)

    { :session          => read_integer(socket),
      :message_content  => read_db_open(socket) }
end

.record_load(socket, session, rid, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/orient_db_client/protocols/protocol9.rb', line 60

def self.record_load(socket, session, rid, options = {})
    socket.write NetworkMessage.new { |m|
        m.add :byte,    Operations::RECORD_LOAD
        m.add :integer, session
        m.add :short,   rid.cluster_id
        m.add :long,    rid.cluster_position
        m.add :string,  ""
        m.add :byte,    options[:ignore_cache] === true ? 1 : 0
    }.pack

    read_response(socket)

    { :session          => read_integer(socket),
      :message_content  => read_record_load(socket) }
end