Class: Pacer::Orient::Graph

Inherits:
PacerGraph
  • Object
show all
Defined in:
lib/pacer-orient/graph.rb

Constant Summary collapse

OTYPES =

Marked the types that should be most commonly used.

{
  :any          => OType::ANY,
  :all          => 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
  #HINT: If using the BinaryDateEncoder, use :binary instead of the :date or :datetime types.
  :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

Instance Method Details

#add_vertex_types(*types) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
# File 'lib/pacer-orient/graph.rb', line 218

def add_vertex_types(*types)
  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

#allow_auto_txObject



93
94
95
# File 'lib/pacer-orient/graph.rb', line 93

def allow_auto_tx
  blueprints_graph.isAutoStartTx or not blueprints_graph.isRequireTransaction
end

#allow_auto_tx=(b) ⇒ Object



88
89
90
91
# File 'lib/pacer-orient/graph.rb', line 88

def allow_auto_tx=(b)
  blueprints_graph.setRequireTransaction !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

#drop_handler(h) ⇒ Object



112
113
114
# File 'lib/pacer-orient/graph.rb', line 112

def drop_handler(h)
  # todo
end

#in_transaction?Boolean

Returns:

  • (Boolean)


230
231
232
# File 'lib/pacer-orient/graph.rb', line 230

def in_transaction?
  orient_graph.getTransaction.isActive
end

#index_type(t) ⇒ Object



210
211
212
213
214
215
216
# File 'lib/pacer-orient/graph.rb', line 210

def index_type(t)
  if t.is_a? String or t.is_a? Symbol
    ITYPES[t.to_sym]
  else
    t
  end
end

#lightweight_edgesObject 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.setUseLightweightEdges 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_graphObject



84
85
86
# File 'lib/pacer-orient/graph.rb', line 84

def orient_graph
  blueprints_graph.getRawGraph
end

#orient_type(t = nil, element_type = :vertex) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/pacer-orient/graph.rb', line 187

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
# 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
    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

#property_type(t) ⇒ Object



202
203
204
205
206
207
208
# File 'lib/pacer-orient/graph.rb', line 202

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

#thread_local(revert = false) ⇒ Object

Enables using multiple graphs at once.



235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/pacer-orient/graph.rb', line 235

def thread_local(revert = false)
  orig = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined
  if orig == orient_graph
    yield
  else
    begin
      ODatabaseRecordThreadLocal.INSTANCE.set orient_graph
      yield
    ensure
      ODatabaseRecordThreadLocal.INSTANCE.set orig if revert
    end
  end
end

#transaction(opts = {}) ⇒ Object Also known as: tx



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/pacer-orient/graph.rb', line 249

def transaction(opts = {})
  thread_local do
    if opts[:schema]
      begin
        if in_transaction?
          in_tx = true
          blueprints_graph.commit
        end
        c, r = nested_tx_finalizers
        yield c, r
      ensure
        blueprints_graph.begin if in_tx
      end
    else
      super
    end
  end
end

#use_class_for_edge_labelObject



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.setUseClassForEdgeLabel b
end

#use_class_for_vertex_labelObject



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.setUseClassForVertexLabel b
end