Class: AllegroGraph::Repository
Overview
The Repository class wrap the corresponding resource on the AllegroGraph server. A repository acts as a scope for statements. Simple management methods are provided.
Instance Attribute Summary collapse
Attributes inherited from Resource
#geometric, #mapping, #query, #statements
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(server_or_catalog, name) ⇒ Repository
Returns a new instance of Repository.
12
13
14
15
16
17
|
# File 'lib/allegro_graph/repository.rb', line 12
def initialize(server_or_catalog, name)
super
@catalog = server_or_catalog.is_a?(AllegroGraph::Server) ? server_or_catalog.root_catalog : server_or_catalog
@server = @catalog.server
@name = name
end
|
Instance Attribute Details
#catalog ⇒ Object
Returns the value of attribute catalog.
9
10
11
|
# File 'lib/allegro_graph/repository.rb', line 9
def catalog
@catalog
end
|
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/allegro_graph/repository.rb', line 10
def name
@name
end
|
#server ⇒ Object
Returns the value of attribute server.
8
9
10
|
# File 'lib/allegro_graph/repository.rb', line 8
def server
@server
end
|
Class Method Details
.transaction(repository, options = { }, &block) ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/allegro_graph/repository.rb', line 93
def self.transaction(repository, options = { }, &block)
session = Session.create repository, options
begin
session.instance_eval &block
rescue Object => error
session.rollback
raise error
end
session.commit
end
|
Instance Method Details
#==(other) ⇒ Object
19
20
21
|
# File 'lib/allegro_graph/repository.rb', line 19
def ==(other)
other.is_a?(self.class) && self.catalog == other.catalog && self.name == other.name
end
|
#create! ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/allegro_graph/repository.rb', line 39
def create!
@server.request_http :put, self.path, :expected_status_code => 204
true
rescue ::Transport::UnexpectedStatusCodeError => error
return false if error.status_code == 400
raise error
end
|
#create_if_missing! ⇒ Object
47
48
49
|
# File 'lib/allegro_graph/repository.rb', line 47
def create_if_missing!
create! unless exists?
end
|
#delete! ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/allegro_graph/repository.rb', line 51
def delete!
@server.request_http :delete, self.path, :expected_status_code => 200
true
rescue ::Transport::UnexpectedStatusCodeError => error
return false if error.status_code == 400
raise error
end
|
#delete_if_exists! ⇒ Object
59
60
61
|
# File 'lib/allegro_graph/repository.rb', line 59
def delete_if_exists!
delete! if exists?
end
|
#exists? ⇒ Boolean
35
36
37
|
# File 'lib/allegro_graph/repository.rb', line 35
def exists?
@catalog.repositories.include? self
end
|
#optimize(parameters = {}) ⇒ Object
83
84
85
86
87
|
# File 'lib/allegro_graph/repository.rb', line 83
def optimize(parameters={})
parameters = { :wait => 'false', :level => '1' }.merge(parameters)
response = @server.request_http :post, self.path + "/indices/optimize", :parameters => parameters, :expected_status_code => 204
response == 'nil'
end
|
#path ⇒ Object
23
24
25
|
# File 'lib/allegro_graph/repository.rb', line 23
def path
"#{@catalog.path}/repositories/#{@name}"
end
|
#remove_duplicates(mode = :spog) ⇒ Object
68
69
70
71
|
# File 'lib/allegro_graph/repository.rb', line 68
def remove_duplicates(mode=:spog)
response = @server.request_http :delete, self.path + "/statements/duplicates", :parameters => {:mode => mode.to_s}, :expected_status_code => 200
response.to_i
end
|
#request_http(*arguments) ⇒ Object
27
28
29
|
# File 'lib/allegro_graph/repository.rb', line 27
def request_http(*arguments)
@server.request_http *arguments
end
|
#request_json(*arguments) ⇒ Object
31
32
33
|
# File 'lib/allegro_graph/repository.rb', line 31
def request_json(*arguments)
@server.request_json *arguments
end
|
#size ⇒ Object
63
64
65
66
|
# File 'lib/allegro_graph/repository.rb', line 63
def size
response = @server.request_http :get, self.path + "/size", :type => :text, :expected_status_code => 200
response.to_i
end
|
#suppress_duplicates ⇒ Object
78
79
80
81
|
# File 'lib/allegro_graph/repository.rb', line 78
def suppress_duplicates
strategy = @server.request_http :get, self.path + "/suppressDuplicates", :expected_status_code => 200
strategy == 'false' ? false : strategy.to_sym
end
|
#suppress_duplicates=(type = :spog) ⇒ Object
73
74
75
76
|
# File 'lib/allegro_graph/repository.rb', line 73
def suppress_duplicates=(type=:spog)
response = @server.request_http :put, self.path + "/suppressDuplicates", :parameters => {:type => type.to_s}, :expected_status_code => 204
true
end
|
#transaction(options = {}, &block) ⇒ Object
89
90
91
|
# File 'lib/allegro_graph/repository.rb', line 89
def transaction(options={}, &block)
self.class.transaction self, options, &block
end
|