Class: Orientdb4r::Client
- Inherits:
-
Object
- Object
- Orientdb4r::Client
- Includes:
- Utils
- Defined in:
- lib/orientdb4r/client.rb
Direct Known Subclasses
Constant Summary collapse
- SERVER_VERSION_PATTERN =
# Regexp to validate format of provided version.
/^\d+\.\d+\.\d+[-SNAPHOT]*$/
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.
-
#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.
-
#export(options) ⇒ Object
Exports a gzip file that contains the database JSON export.
-
#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.
-
#import(options) ⇒ Object
Imports a database from an uploaded JSON text file.
-
#initialize ⇒ Client
constructor
Constructor.
-
#list_databases(options) ⇒ Object
Retrieves the available databases.
-
#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.
29 30 31 32 |
# File 'lib/orientdb4r/client.rb', line 29 def initialize @nodes = [] @connected = false end |
Instance Attribute Details
#connection_library ⇒ Object (readonly)
type of connection library [:restclient, :excon]
14 15 16 |
# File 'lib/orientdb4r/client.rb', line 14 def connection_library @connection_library end |
#database ⇒ Object (readonly)
connection parameters
12 13 14 |
# File 'lib/orientdb4r/client.rb', line 12 def database @database end |
#lb_strategy ⇒ Object (readonly)
object implementing a LB strategy
25 26 27 |
# File 'lib/orientdb4r/client.rb', line 25 def lb_strategy @lb_strategy end |
#load_balancing ⇒ Object (readonly)
type of load balancing [:sequence, :round_robin]
16 17 18 |
# File 'lib/orientdb4r/client.rb', line 16 def load_balancing @load_balancing end |
#nodes ⇒ Object (readonly)
nodes responsible for communication with a server
23 24 25 |
# File 'lib/orientdb4r/client.rb', line 23 def nodes @nodes end |
#password ⇒ Object (readonly)
connection parameters
12 13 14 |
# File 'lib/orientdb4r/client.rb', line 12 def password @password end |
#proxy ⇒ Object (readonly)
proxy for remote communication
18 19 20 |
# File 'lib/orientdb4r/client.rb', line 18 def proxy @proxy end |
#user ⇒ Object (readonly)
connection parameters
12 13 14 |
# File 'lib/orientdb4r/client.rb', line 12 def user @user end |
Instance Method Details
#class_exists?(name) ⇒ Boolean
Checks existence of a given class.
208 209 210 211 212 213 214 215 216 217 |
# File 'lib/orientdb4r/client.rb', line 208 def class_exists?(name) rslt = true begin get_class name rescue OrientdbError => e raise e if e.is_a? ConnectionError and e. == 'not connected' # workaround for AOP2 (unable to decorate already existing methods) rslt = false end rslt end |
#command(sql) ⇒ Object
Executes a command against the database.
145 146 147 |
# File 'lib/orientdb4r/client.rb', line 145 def command(sql) raise NotImplementedError, 'this should be overridden by concrete client' end |
#connect(options) ⇒ Object
Connects client to the server.
39 40 41 |
# File 'lib/orientdb4r/client.rb', line 39 def connect raise NotImplementedError, 'this should be overridden by concrete client' end |
#connected? ⇒ Boolean
Gets flag whenever the client is connected or not.
53 54 55 |
# File 'lib/orientdb4r/client.rb', line 53 def connected? @connected end |
#create_class(name, options = {}) ⇒ Object
Creates a new class in the schema.
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 |
# File 'lib/orientdb4r/client.rb', line 154 def create_class(name, ={}) raise ArgumentError, "class name is blank" if blank?(name) opt_pattern = { :extends => :optional, :cluster => :optional, :force => false, :abstract => false, :properties => :optional } (, opt_pattern) sql = "CREATE CLASS #{name}" sql << " EXTENDS #{[:extends]}" if .include? :extends sql << " CLUSTER #{[:cluster]}" if .include? :cluster sql << ' ABSTRACT' if .include?(:abstract) 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. *options
*storage - 'memory' (by default) or 'local'
*type - 'document' (by default) or 'graph'
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 for OrientDB version <= 1.3.x and the whole new document for version >= 1.4.x (see groups.google.com/forum/?fromgroups=#!topic/orient-database/UJGAXYpHDmo for more info).
277 278 279 |
# File 'lib/orientdb4r/client.rb', line 277 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.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/orientdb4r/client.rb', line 243 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, :readonly => :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.
298 299 300 |
# File 'lib/orientdb4r/client.rb', line 298 def delete_document(rid) raise NotImplementedError, 'this should be overridden by concrete client' end |
#disconnect ⇒ Object
Disconnects client from the server.
46 47 48 |
# File 'lib/orientdb4r/client.rb', line 46 def disconnect raise NotImplementedError, 'this should be overridden by concrete client' end |
#drop_class(name, options = {}) ⇒ Object
Removes a class from the schema.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/orientdb4r/client.rb', line 222 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 = get_database children = response['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 |
#export(options) ⇒ Object
Exports a gzip file that contains the database JSON export. Returns name of stored file.
123 124 125 |
# File 'lib/orientdb4r/client.rb', line 123 def export() raise NotImplementedError, 'this should be overridden by concrete client' end |
#get_class(name) ⇒ Object
Gets informations about requested class.
201 202 203 |
# File 'lib/orientdb4r/client.rb', line 201 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.
284 285 286 |
# File 'lib/orientdb4r/client.rb', line 284 def get_document(rid) raise NotImplementedError, 'this should be overridden by concrete client' end |
#import(options) ⇒ Object
Imports a database from an uploaded JSON text file.
130 131 132 |
# File 'lib/orientdb4r/client.rb', line 130 def import() raise NotImplementedError, 'this should be overridden by concrete client' end |
#list_databases(options) ⇒ Object
Retrieves the available databases. That is protected by the resource “server.listDatabases” that by default is assigned to the guest (anonymous) user in orientdb-server-config.xml.
115 116 117 |
# File 'lib/orientdb4r/client.rb', line 115 def list_databases() raise NotImplementedError, 'this should be overridden by concrete client' end |
#query(sql, options) ⇒ Object
Executes a query against the database.
138 139 140 |
# File 'lib/orientdb4r/client.rb', line 138 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.
62 63 64 |
# File 'lib/orientdb4r/client.rb', line 62 def server(={}) raise NotImplementedError, 'this should be overridden by concrete client' end |
#update_document(doc) ⇒ Object
Updates an existing document.
291 292 293 |
# File 'lib/orientdb4r/client.rb', line 291 def update_document(doc) raise NotImplementedError, 'this should be overridden by concrete client' end |