Class: Pacer::Orient::Graph
- Inherits:
-
PacerGraph
- Object
- PacerGraph
- Pacer::Orient::Graph
- Defined in:
- lib/pacer-orient/graph.rb
Constant Summary collapse
- OTYPES =
Marked the types that should be most commonly used.
{ :any => OType::ANY, :boolean => OType::BOOLEAN, # use this one :bool => OType::BOOLEAN, :short => OType::SHORT, :integer => OType::INTEGER, :int => OType::INTEGER, :long => OType::LONG, # use this one :float => OType::FLOAT, :double => OType::DOUBLE, # use this one :decimal => OType::DECIMAL, # use this one #If encoding dates to binary #:date => OType::BINARY, #:datetime => OType::BINARY, #:date_time => OType::BINARY, :date => OType::DATE, # use this one :datetime => OType::DATETIME, # use this one :date_time => OType::DATETIME, :byte => OType::BYTE, :string => OType::STRING, # use this one :binary => OType::BINARY, :embedded => OType::EMBEDDED, :embeddedlist => OType::EMBEDDEDLIST, :embeddedset => OType::EMBEDDEDSET, :embeddedmap => OType::EMBEDDEDMAP, :link => OType::LINK, :linklist => OType::LINKLIST, :linkset => OType::LINKSET, :linkmap => OType::LINKMAP, :linkbag => OType::LINKBAG, :transient => OType::TRANSIENT, :custom => OType::CUSTOM }
- ITYPES =
{ :range_dictionary => OClass::INDEX_TYPE::DICTIONARY, :range_fulltext => OClass::INDEX_TYPE::FULLTEXT, :range_full_text => OClass::INDEX_TYPE::FULLTEXT, :range_notunique => OClass::INDEX_TYPE::NOTUNIQUE, :range_nonunique => OClass::INDEX_TYPE::NOTUNIQUE, :range_not_unique => OClass::INDEX_TYPE::NOTUNIQUE, :range_unique => OClass::INDEX_TYPE::UNIQUE, :proxy => OClass::INDEX_TYPE::PROXY, :dictionary => OClass::INDEX_TYPE::DICTIONARY_HASH_INDEX, :fulltext => OClass::INDEX_TYPE::FULLTEXT_HASH_INDEX, :full_text => OClass::INDEX_TYPE::FULLTEXT_HASH_INDEX, :notunique => OClass::INDEX_TYPE::NOTUNIQUE_HASH_INDEX, :nonunique => OClass::INDEX_TYPE::NOTUNIQUE_HASH_INDEX, :not_unique => OClass::INDEX_TYPE::NOTUNIQUE_HASH_INDEX, :spatial => OClass::INDEX_TYPE::SPATIAL, :unique => OClass::INDEX_TYPE::UNIQUE_HASH_INDEX }
- ITYPE_REVERSE =
{ 'DICTIONARY' => { range: true, unique: false, type: :range_dictionary } , 'DICTIONARY_HASH_INDEX' => { range: false, unique: false, type: :dictionary } , 'FULLTEXT' => { range: true, unique: false, type: :range_fulltext } , 'FULLTEXT_HASH_INDEX' => { range: false, unique: false, type: :fulltext } , 'NOTUNIQUE' => { range: true, unique: false, type: :range_notunique } , 'NOTUNIQUE_HASH_INDEX' => { range: false, unique: false, type: :notunique } , 'PROXY' => { range: false, unique: false, type: :proxy } , 'SPATIAL' => { range: false, unique: false, type: :spatial } , 'UNIQUE' => { range: true, unique: true, type: :range_unique } , 'UNIQUE_HASH_INDEX' => { range: false, unique: true, type: :unique } , }
Instance Method Summary collapse
- #add_vertex_types(*types) ⇒ Object
- #allow_auto_tx ⇒ Object
- #allow_auto_tx=(b) ⇒ Object
- #before_commit(&block) ⇒ Object
- #create_key_index(name, element_type = :vertex, itype = :non_unique) ⇒ Object
- #drop_handler(h) ⇒ Object
- #drop_key_index(name, element_type = :vertex) ⇒ Object
- #index_type(t) ⇒ Object
-
#lightweight_edges ⇒ Object
(also: #lightweight_edges?)
NOTE: if you use lightweight edges (they are on by default), g.e will only return edges that have been reified by having properties added to them.
- #lightweight_edges=(b) ⇒ Object
- #on_commit(&block) ⇒ Object
- #on_commit_failed(&block) ⇒ Object
- #orient_graph ⇒ Object
- #orient_type(t = nil, element_type = :vertex) ⇒ Object
-
#orient_type!(t, element_type = :vertex) ⇒ Object
Find or create a vertex or edge class.
- #property_type(t) ⇒ Object
- #sql(sql = nil, args = nil, opts = {}) ⇒ Object
- #sql_command(sql, args = nil) ⇒ Object
- #sql_e(extensions, sql = nil, args) ⇒ Object
- #use_class_for_edge_label ⇒ Object
- #use_class_for_edge_label=(b) ⇒ Object
- #use_class_for_vertex_label ⇒ Object
- #use_class_for_vertex_label=(b) ⇒ Object
Instance Method Details
#add_vertex_types(*types) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/pacer-orient/graph.rb', line 220 def add_vertex_types(*types) in_pure_transaction do types.map do |t| existing = orient_type(t, :vertex) if existing existing else t = blueprints_graph.createVertexType(t.to_s) OrientType.new(self, :vertex, t) if t end end end end |
#allow_auto_tx ⇒ Object
93 94 95 |
# File 'lib/pacer-orient/graph.rb', line 93 def allow_auto_tx blueprints_graph.autoStartTx end |
#allow_auto_tx=(b) ⇒ Object
89 90 91 |
# File 'lib/pacer-orient/graph.rb', line 89 def allow_auto_tx=(b) blueprints_graph.setAutoStartTx b end |
#before_commit(&block) ⇒ Object
107 108 109 110 |
# File 'lib/pacer-orient/graph.rb', line 107 def before_commit(&block) return unless block # todo end |
#create_key_index(name, element_type = :vertex, itype = :non_unique) ⇒ Object
234 235 236 237 |
# File 'lib/pacer-orient/graph.rb', line 234 def create_key_index(name, element_type = :vertex, itype = :non_unique) type = orient_type(nil, element_type) type.property!(name).create_index!(itype) if type end |
#drop_handler(h) ⇒ Object
112 113 114 |
# File 'lib/pacer-orient/graph.rb', line 112 def drop_handler(h) # todo end |
#drop_key_index(name, element_type = :vertex) ⇒ Object
239 240 241 242 243 |
# File 'lib/pacer-orient/graph.rb', line 239 def drop_key_index(name, element_type = :vertex) in_pure_transaction do super end end |
#index_type(t) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/pacer-orient/graph.rb', line 212 def index_type(t) if t.is_a? String or t.is_a? Symbol ITYPES[t.to_sym] else t end end |
#lightweight_edges ⇒ Object Also known as: lightweight_edges?
NOTE: if you use lightweight edges (they are on by default), g.e will only return edges that have been reified by having properties added to them.
118 119 120 |
# File 'lib/pacer-orient/graph.rb', line 118 def lightweight_edges blueprints_graph.useLightweightEdges end |
#lightweight_edges=(b) ⇒ Object
124 125 126 |
# File 'lib/pacer-orient/graph.rb', line 124 def lightweight_edges=(b) blueprints_graph.useLightweightEdges = b end |
#on_commit(&block) ⇒ Object
97 98 99 100 |
# File 'lib/pacer-orient/graph.rb', line 97 def on_commit(&block) return unless block # todo end |
#on_commit_failed(&block) ⇒ Object
102 103 104 105 |
# File 'lib/pacer-orient/graph.rb', line 102 def on_commit_failed(&block) return unless block # todo end |
#orient_graph ⇒ Object
85 86 87 |
# File 'lib/pacer-orient/graph.rb', line 85 def orient_graph blueprints_graph.raw_graph end |
#orient_type(t = nil, element_type = :vertex) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/pacer-orient/graph.rb', line 189 def orient_type(t = nil, element_type = :vertex) t ||= :V if element_type == :vertex t ||= :E if element_type == :edge if t.is_a? String or t.is_a? Symbol t = if element_type == :vertex blueprints_graph.getVertexType(t.to_s) elsif element_type == :edge blueprints_graph.getEdgeType(t.to_s) end OrientType.new self, element_type, t if t elsif t.is_a? OrientType t end end |
#orient_type!(t, element_type = :vertex) ⇒ Object
Find or create a vertex or edge class
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/pacer-orient/graph.rb', line 173 def orient_type!(t, element_type = :vertex) r = orient_type(t, element_type) if r r else in_pure_transaction do t = if element_type == :vertex blueprints_graph.createVertexType(t.to_s) elsif element_type == :edge blueprints_graph.createEdgeType(t.to_s) end OrientType.new self, element_type, t if t end end end |
#property_type(t) ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/pacer-orient/graph.rb', line 204 def property_type(t) if t.is_a? String or t.is_a? Symbol OTYPES[t.to_sym] else t end end |
#sql(sql = nil, args = nil, opts = {}) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/pacer-orient/graph.rb', line 144 def sql(sql = nil, args = nil, opts = {}) opts = { back: self, element_type: :vertex }.merge opts chain_route(opts.merge(sql: sql, query_args: args, filter: Pacer::Filter::SqlFilter)) end |
#sql_command(sql, args = nil) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/pacer-orient/graph.rb', line 160 def sql_command(sql, args = nil) if args and not args.frozen? args = args.map { |a| encoder.encode_property(a) } end command = blueprints_graph.command(OCommandSQL.new(sql)) if args command.execute(*args) else command.execute end end |
#sql_e(extensions, sql = nil, args) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/pacer-orient/graph.rb', line 151 def sql_e(extensions, sql = nil, args) if extensions.is_a? String args = sql sql = extensions extensions = [] end sql_command(sql, args).iterator.to_route(based_on: self.e(extensions)) end |
#use_class_for_edge_label ⇒ Object
128 129 130 |
# File 'lib/pacer-orient/graph.rb', line 128 def use_class_for_edge_label blueprints_graph.useClassForEdgeLabel end |
#use_class_for_edge_label=(b) ⇒ Object
132 133 134 |
# File 'lib/pacer-orient/graph.rb', line 132 def use_class_for_edge_label=(b) blueprints_graph.useClassForEdgeLabel = b end |
#use_class_for_vertex_label ⇒ Object
136 137 138 |
# File 'lib/pacer-orient/graph.rb', line 136 def use_class_for_vertex_label blueprints_graph.useClassForVertexLabel end |
#use_class_for_vertex_label=(b) ⇒ Object
140 141 142 |
# File 'lib/pacer-orient/graph.rb', line 140 def use_class_for_vertex_label=(b) blueprints_graph.useClassForVertexLabel = b end |