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.
27 28 29 30 |
# File 'lib/orientdb4r/client.rb', line 27 def initialize @nodes = [] @connected = false end |
Instance Attribute Details
#connection_library ⇒ Object (readonly)
type of connection library [:restclient, :excon]
12 13 14 |
# File 'lib/orientdb4r/client.rb', line 12 def connection_library @connection_library end |
#database ⇒ Object (readonly)
connection parameters
10 11 12 |
# File 'lib/orientdb4r/client.rb', line 10 def database @database end |
#lb_strategy ⇒ Object (readonly)
object implementing a LB strategy
23 24 25 |
# File 'lib/orientdb4r/client.rb', line 23 def lb_strategy @lb_strategy end |
#load_balancing ⇒ Object (readonly)
type of load balancing [:sequence, :round_robin]
14 15 16 |
# File 'lib/orientdb4r/client.rb', line 14 def load_balancing @load_balancing end |
#nodes ⇒ Object (readonly)
nodes responsible for communication with a server
21 22 23 |
# File 'lib/orientdb4r/client.rb', line 21 def nodes @nodes end |
#password ⇒ Object (readonly)
connection parameters
10 11 12 |
# File 'lib/orientdb4r/client.rb', line 10 def password @password end |
#proxy ⇒ Object (readonly)
proxy for remote communication
16 17 18 |
# File 'lib/orientdb4r/client.rb', line 16 def proxy @proxy end |
#user ⇒ Object (readonly)
connection parameters
10 11 12 |
# File 'lib/orientdb4r/client.rb', line 10 def user @user end |
Instance Method Details
#class_exists?(name) ⇒ Boolean
Checks existence of a given class.
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/orientdb4r/client.rb', line 206 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.
143 144 145 |
# File 'lib/orientdb4r/client.rb', line 143 def command(sql) raise NotImplementedError, 'this should be overridden by concrete client' end |
#connect(options) ⇒ Object
Connects client to the server.
37 38 39 |
# File 'lib/orientdb4r/client.rb', line 37 def connect raise NotImplementedError, 'this should be overridden by concrete client' end |
#connected? ⇒ Boolean
Gets flag whenever the client is connected or not.
51 52 53 |
# File 'lib/orientdb4r/client.rb', line 51 def connected? @connected end |
#create_class(name, options = {}) ⇒ Object
Creates a new class in the schema.
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 |
# File 'lib/orientdb4r/client.rb', line 152 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'
74 75 76 |
# File 'lib/orientdb4r/client.rb', line 74 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).
275 276 277 |
# File 'lib/orientdb4r/client.rb', line 275 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.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/orientdb4r/client.rb', line 241 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.
90 91 92 93 94 95 96 97 98 |
# File 'lib/orientdb4r/client.rb', line 90 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.
104 105 106 |
# File 'lib/orientdb4r/client.rb', line 104 def delete_database() raise NotImplementedError, 'this should be overridden by concrete client' end |
#delete_document(rid) ⇒ Object
Deletes an existing document.
296 297 298 |
# File 'lib/orientdb4r/client.rb', line 296 def delete_document(rid) raise NotImplementedError, 'this should be overridden by concrete client' end |
#disconnect ⇒ Object
Disconnects client from the server.
44 45 46 |
# File 'lib/orientdb4r/client.rb', line 44 def disconnect raise NotImplementedError, 'this should be overridden by concrete client' end |
#drop_class(name, options = {}) ⇒ Object
Removes a class from the schema.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/orientdb4r/client.rb', line 220 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.
121 122 123 |
# File 'lib/orientdb4r/client.rb', line 121 def export() raise NotImplementedError, 'this should be overridden by concrete client' end |
#get_class(name) ⇒ Object
Gets informations about requested class.
199 200 201 |
# File 'lib/orientdb4r/client.rb', line 199 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.
82 83 84 |
# File 'lib/orientdb4r/client.rb', line 82 def get_database() raise NotImplementedError, 'this should be overridden by concrete client' end |
#get_document(rid) ⇒ Object
Retrieves a document by given ID.
282 283 284 |
# File 'lib/orientdb4r/client.rb', line 282 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.
128 129 130 |
# File 'lib/orientdb4r/client.rb', line 128 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.
113 114 115 |
# File 'lib/orientdb4r/client.rb', line 113 def list_databases() raise NotImplementedError, 'this should be overridden by concrete client' end |
#query(sql, options) ⇒ Object
Executes a query against the database.
136 137 138 |
# File 'lib/orientdb4r/client.rb', line 136 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.
60 61 62 |
# File 'lib/orientdb4r/client.rb', line 60 def server(={}) raise NotImplementedError, 'this should be overridden by concrete client' end |
#update_document(doc) ⇒ Object
Updates an existing document.
289 290 291 |
# File 'lib/orientdb4r/client.rb', line 289 def update_document(doc) raise NotImplementedError, 'this should be overridden by concrete client' end |