Class: Orientdb4r::Client
- Inherits:
-
Object
- Object
- Orientdb4r::Client
- Includes:
- Utils
- Defined in:
- lib/orientdb4r/client.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_SERVER_VERSION =
Server version used if no concrete version identified.
'1.0.0--'
- SERVER_VERSION_PATTERN =
# Regexp to validate format of providet version.
/^\d+\.\d+\.\d+/
Instance Attribute Summary collapse
-
#connection_library ⇒ Object
readonly
type of connection library [:restclient, :excon].
-
#database ⇒ Object
readonly
connection parameters.
-
#lb_strategy ⇒ Object
readonly
object implementing a LB strategy.
-
#load_balancing ⇒ Object
readonly
type of load balancing [:sequence, :round_robin].
-
#nodes ⇒ Object
readonly
nodes responsible for communication with a server.
-
#password ⇒ Object
readonly
connection parameters.
-
#proxy ⇒ Object
readonly
proxy for remote communication.
-
#server_version ⇒ Object
readonly
version loaded from server.
-
#user ⇒ Object
readonly
connection parameters.
Instance Method Summary collapse
-
#class_exists?(name) ⇒ Boolean
Checks existence of a given class.
-
#command(sql) ⇒ Object
Executes a command against the database.
-
#connect(options) ⇒ Object
Connects client to the server.
-
#connected? ⇒ Boolean
Gets flag whenever the client is connected or not.
-
#create_class(name, options = {}) ⇒ Object
Creates a new class in the schema.
-
#create_database(options) ⇒ Object
Creates a new database.
-
#create_document(doc) ⇒ Object
Create a new document.
-
#create_property(clazz, property, type, options = {}) ⇒ Object
Creates a new property in the schema.
-
#database_exists?(options) ⇒ Boolean
Checks existence of a given database.
-
#delete_database(options) ⇒ Object
Drops a database.
-
#delete_document(rid) ⇒ Object
Deletes an existing document.
-
#disconnect ⇒ Object
Disconnects client from the server.
-
#drop_class(name, options = {}) ⇒ Object
Removes a class from the schema.
-
#get_class(name) ⇒ Object
Gets informations about requested class.
-
#get_database(options) ⇒ Object
Retrieves all the information about a database.
-
#get_document(rid) ⇒ Object
Retrieves a document by given ID.
-
#initialize ⇒ Client
constructor
Constructor.
-
#query(sql, options) ⇒ Object
Executes a query against the database.
-
#server(options = {}) ⇒ Object
Retrieve information about the connected OrientDB Server.
-
#update_document(doc) ⇒ Object
Updates an existing document.
Methods included from Utils
#blank?, #compare_versions, #random_string, #verify_and_sanitize_options, #verify_options
Constructor Details
#initialize ⇒ Client
Constructor.
32 33 34 35 |
# File 'lib/orientdb4r/client.rb', line 32 def initialize @nodes = [] @connected = false end |
Instance Attribute Details
#connection_library ⇒ Object (readonly)
type of connection library [:restclient, :excon]
17 18 19 |
# File 'lib/orientdb4r/client.rb', line 17 def connection_library @connection_library end |
#database ⇒ Object (readonly)
connection parameters
13 14 15 |
# File 'lib/orientdb4r/client.rb', line 13 def database @database end |
#lb_strategy ⇒ Object (readonly)
object implementing a LB strategy
28 29 30 |
# File 'lib/orientdb4r/client.rb', line 28 def lb_strategy @lb_strategy end |
#load_balancing ⇒ Object (readonly)
type of load balancing [:sequence, :round_robin]
19 20 21 |
# File 'lib/orientdb4r/client.rb', line 19 def load_balancing @load_balancing end |
#nodes ⇒ Object (readonly)
nodes responsible for communication with a server
26 27 28 |
# File 'lib/orientdb4r/client.rb', line 26 def nodes @nodes end |
#password ⇒ Object (readonly)
connection parameters
13 14 15 |
# File 'lib/orientdb4r/client.rb', line 13 def password @password end |
#proxy ⇒ Object (readonly)
proxy for remote communication
21 22 23 |
# File 'lib/orientdb4r/client.rb', line 21 def proxy @proxy end |
#server_version ⇒ Object (readonly)
version loaded from server
15 16 17 |
# File 'lib/orientdb4r/client.rb', line 15 def server_version @server_version end |
#user ⇒ Object (readonly)
connection parameters
13 14 15 |
# File 'lib/orientdb4r/client.rb', line 13 def user @user end |
Instance Method Details
#class_exists?(name) ⇒ Boolean
Checks existence of a given class.
180 181 182 183 184 185 186 187 188 |
# File 'lib/orientdb4r/client.rb', line 180 def class_exists?(name) rslt = true begin get_class name rescue OrientdbError rslt = false end rslt end |
#command(sql) ⇒ Object
Executes a command against the database.
121 122 123 |
# File 'lib/orientdb4r/client.rb', line 121 def command(sql) raise NotImplementedError, 'this should be overridden by concrete client' end |
#connect(options) ⇒ Object
Connects client to the server.
42 43 44 |
# File 'lib/orientdb4r/client.rb', line 42 def connect raise NotImplementedError, 'this should be overridden by concrete client' end |
#connected? ⇒ Boolean
Gets flag whenever the client is connected or not.
56 57 58 |
# File 'lib/orientdb4r/client.rb', line 56 def connected? @connected end |
#create_class(name, options = {}) ⇒ Object
Creates a new class in the schema.
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 |
# File 'lib/orientdb4r/client.rb', line 130 def create_class(name, ={}) raise ArgumentError, "class name is blank" if blank?(name) opt_pattern = { :extends => :optional , :cluster => :optional, :force => false, :properties => :optional } (, opt_pattern) sql = "CREATE CLASS #{name}" sql << " EXTENDS #{[:extends]}" if .include? :extends sql << " CLUSTER #{[:cluster]}" if .include? :cluster drop_class name if [:force] command sql # properties given? if .include? :properties props = [:properties] raise ArgumentError, 'properties have to be an array' unless props.is_a? Array props.each do |prop| raise ArgumentError, 'property definition has to be a hash' unless prop.is_a? Hash prop_name = prop.delete :property prop_type = prop.delete :type create_property(name, prop_name, prop_type, prop) end end if block_given? proxy = Orientdb4r::Utils::Proxy.new(self, name) def proxy.property(property, type, ={}) self.target.send :create_property, self.context, property, type, end def proxy.link(property, type, linked_class, ={}) raise ArgumentError, "type has to be a linked-type, given=#{type}" unless type.to_s.start_with? 'link' [:linked_class] = linked_class self.target.send :create_property, self.context, property, type, end yield proxy end end |
#create_database(options) ⇒ Object
Creates a new database. You can provide an additional authentication to the server with ‘database.create’ resource or the current one will be used.
76 77 78 |
# File 'lib/orientdb4r/client.rb', line 76 def create_database() raise NotImplementedError, 'this should be overridden by concrete client' end |
#create_document(doc) ⇒ Object
Create a new document. Returns the Record-id assigned.
247 248 249 |
# File 'lib/orientdb4r/client.rb', line 247 def create_document(doc) raise NotImplementedError, 'this should be overridden by concrete client' end |
#create_property(clazz, property, type, options = {}) ⇒ Object
Creates a new property in the schema. You need to create the class before.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/orientdb4r/client.rb', line 215 def create_property(clazz, property, type, ={}) raise ArgumentError, "class name is blank" if blank?(clazz) raise ArgumentError, "property name is blank" if blank?(property) opt_pattern = { :mandatory => :optional , :notnull => :optional, :min => :optional, :max => :optional, :regexp => :optional, :custom => :optional, :linked_class => :optional } (, opt_pattern) cmd = "CREATE PROPERTY #{clazz}.#{property} #{type.to_s}" # link? if [:link, :linklist, :linkset, :linkmap].include? type.to_s.downcase.to_sym raise ArgumentError, "defined linked-type, but not linked-class" unless .include? :linked_class cmd << " #{[:linked_class]}" end command cmd # ALTER PROPERTY ... .delete :linked_class # it's not option for ALTER unless .empty? .each do |k,v| command "ALTER PROPERTY #{clazz}.#{property} #{k.to_s.upcase} #{v}" end end end |
#database_exists?(options) ⇒ Boolean
Checks existence of a given database. Client has not to be connected to see databases suitable to connect.
92 93 94 95 96 97 98 99 100 |
# File 'lib/orientdb4r/client.rb', line 92 def database_exists?() rslt = true begin get_database rescue OrientdbError rslt = false end rslt end |
#delete_database(options) ⇒ Object
Drops a database. Requires additional authentication to the server.
106 107 108 |
# File 'lib/orientdb4r/client.rb', line 106 def delete_database() raise NotImplementedError, 'this should be overridden by concrete client' end |
#delete_document(rid) ⇒ Object
Deletes an existing document.
268 269 270 |
# File 'lib/orientdb4r/client.rb', line 268 def delete_document(rid) raise NotImplementedError, 'this should be overridden by concrete client' end |
#disconnect ⇒ Object
Disconnects client from the server.
49 50 51 |
# File 'lib/orientdb4r/client.rb', line 49 def disconnect raise NotImplementedError, 'this should be overridden by concrete client' end |
#drop_class(name, options = {}) ⇒ Object
Removes a class from the schema.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/orientdb4r/client.rb', line 193 def drop_class(name, ={}) raise ArgumentError, "class name is blank" if blank?(name) # :mode=>:strict forbids to drop a class that is a super class for other one opt_pattern = { :mode => :nil } (, opt_pattern) if :strict == [:mode] response = call_server(:method => :get, :uri => "connect/#{@database}") # TODO there cannot be REST connect_info = process_response response children = connect_info['classes'].select { |i| i['superClass'] == name } unless children.empty? raise OrientdbError, "class is super-class, cannot be deleted, name=#{name}" end end command "DROP CLASS #{name}" end |
#get_class(name) ⇒ Object
Gets informations about requested class.
173 174 175 |
# File 'lib/orientdb4r/client.rb', line 173 def get_class(name) raise NotImplementedError, 'this should be overridden by concrete client' end |
#get_database(options) ⇒ Object
Retrieves all the information about a database. Client has not to be connected to see databases suitable to connect.
84 85 86 |
# File 'lib/orientdb4r/client.rb', line 84 def get_database() raise NotImplementedError, 'this should be overridden by concrete client' end |
#get_document(rid) ⇒ Object
Retrieves a document by given ID.
254 255 256 |
# File 'lib/orientdb4r/client.rb', line 254 def get_document(rid) raise NotImplementedError, 'this should be overridden by concrete client' end |
#query(sql, options) ⇒ Object
Executes a query against the database.
114 115 116 |
# File 'lib/orientdb4r/client.rb', line 114 def query(sql, ) raise NotImplementedError, 'this should be overridden by concrete client' end |
#server(options = {}) ⇒ Object
Retrieve information about the connected OrientDB Server. Enables additional authentication to the server with an account that can access the ‘server.info’ resource.
65 66 67 |
# File 'lib/orientdb4r/client.rb', line 65 def server(={}) raise NotImplementedError, 'this should be overridden by concrete client' end |
#update_document(doc) ⇒ Object
Updates an existing document.
261 262 263 |
# File 'lib/orientdb4r/client.rb', line 261 def update_document(doc) raise NotImplementedError, 'this should be overridden by concrete client' end |