Class: Orientdb4r::Client

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/orientdb4r/client.rb

Direct Known Subclasses

RestClient

Instance Method Summary collapse

Methods included from Utils

#blank?, #random_string, #verify_and_sanitize_options, #verify_options

Constructor Details

#initializeClient

Constructor.



8
9
10
# File 'lib/orientdb4r/client.rb', line 8

def initialize
  @connected = false
end

Instance Method Details

#command(sql) ⇒ Object

Executes a command against the database.

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/orientdb4r/client.rb', line 71

def command(sql)
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#connect(options) ⇒ Object

Connects client to the server.

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/orientdb4r/client.rb', line 16

def connect options
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#connected?Boolean

Gets flag whenever the client is connected or not.

Returns:

  • (Boolean)


30
31
32
# File 'lib/orientdb4r/client.rb', line 30

def connected?
  @connected
end

#create_class(name, options = {}) ⇒ Object

Creates a new class in the schema.

Raises:

  • (ArgumentError)


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/orientdb4r/client.rb', line 79

def create_class(name, options={})
  raise ArgumentError, "class name is blank" if blank?(name)
  opt_pattern = { :extends => :optional , :cluster => :optional, :force => false }
  verify_options(options, opt_pattern)

  sql = "CREATE CLASS #{name}"
  sql << " EXTENDS #{options[:extends]}" if options.include? :extends
  sql << " CLUSTER #{options[:cluster]}" if options.include? :cluster

  drop_class name if options[:force]

  command sql

  if block_given?
    proxy = Orientdb4r::Utils::Proxy.new(self, name)
    def proxy.property(property, type, options={})
      self.target.send :create_property, self.context, property, type, options
    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.

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/orientdb4r/client.rb', line 49

def create_database(options)
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#create_document(doc) ⇒ Object

Create a new document. Returns the Record-id assigned.

Raises:

  • (NotImplementedError)


150
151
152
# File 'lib/orientdb4r/client.rb', line 150

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.

Raises:

  • (ArgumentError)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/orientdb4r/client.rb', line 126

def create_property(clazz, property, type, options={})
  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
  }
  verify_options(options, opt_pattern)

  cmd = "CREATE PROPERTY #{clazz}.#{property} #{type.to_s}"
  command cmd

  unless options.empty?
    options.each do |k,v|
      command "ALTER PROPERTY #{clazz}.#{property} #{k.to_s.upcase} #{v}"
    end
  end
end

#delete_document(rid) ⇒ Object

Deletes an existing document.

Raises:

  • (NotImplementedError)


171
172
173
# File 'lib/orientdb4r/client.rb', line 171

def delete_document(rid)
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#disconnectObject

Disconnects client from the server.

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/orientdb4r/client.rb', line 23

def disconnect
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#drop_class(name, options = {}) ⇒ Object

Removes a class from the schema.

Raises:

  • (ArgumentError)


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/orientdb4r/client.rb', line 104

def drop_class(name, options={})
  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 }
  verify_options(options, opt_pattern)
  if :strict == options[:mode]
    response = @resource["connect/#{@database}"].get
    connect_info = process_response(response, :mode => :strict)
    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.

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/orientdb4r/client.rb', line 56

def get_class(name)
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#get_document(rid) ⇒ Object

Retrieves a document by given ID.

Raises:

  • (NotImplementedError)


157
158
159
# File 'lib/orientdb4r/client.rb', line 157

def get_document(rid)
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#query(sql) ⇒ Object

Executes a query against the database.

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/orientdb4r/client.rb', line 64

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.

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/orientdb4r/client.rb', line 39

def server(options={})
  raise NotImplementedError, 'this should be overridden by concrete client'
end

#update_document(doc) ⇒ Object

Updates an existing document.

Raises:

  • (NotImplementedError)


164
165
166
# File 'lib/orientdb4r/client.rb', line 164

def update_document(doc)
  raise NotImplementedError, 'this should be overridden by concrete client'
end