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,
  :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
  :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_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,
  :not_unique       => OClass::INDEX_TYPE::NOTUNIQUE_HASH_INDEX,
  :spatial          => OClass::INDEX_TYPE::SPATIAL,
  :unique           => OClass::INDEX_TYPE::UNIQUE_HASH_INDEX
}

Instance Method Summary collapse

Instance Method Details

#add_vertex_types(*types) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/pacer-orient/graph.rb', line 198

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_txObject



74
75
76
# File 'lib/pacer-orient/graph.rb', line 74

def allow_auto_tx
  blueprints_graph.autoStartTx
end

#allow_auto_tx=(b) ⇒ Object



70
71
72
# File 'lib/pacer-orient/graph.rb', line 70

def allow_auto_tx=(b)
  blueprints_graph.setAutoStartTx b
end

#before_commit(&block) ⇒ Object



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

def before_commit(&block)
  return unless block
  # todo
end

#create_key_index(name, element_type = :vertex, itype = :non_unique) ⇒ Object



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

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



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

def drop_handler(h)
  # todo
end

#drop_key_index(name, element_type = :vertex) ⇒ Object



217
218
219
220
221
# File 'lib/pacer-orient/graph.rb', line 217

def drop_key_index(name, element_type = :vertex)
  in_pure_transaction do
    super
  end
end

#index_type(t) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/pacer-orient/graph.rb', line 190

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.



99
100
101
# File 'lib/pacer-orient/graph.rb', line 99

def lightweight_edges
  blueprints_graph.useLightweightEdges
end

#lightweight_edges=(b) ⇒ Object



105
106
107
# File 'lib/pacer-orient/graph.rb', line 105

def lightweight_edges=(b)
  blueprints_graph.useLightweightEdges = b
end

#on_commit(&block) ⇒ Object



78
79
80
81
# File 'lib/pacer-orient/graph.rb', line 78

def on_commit(&block)
  return unless block
  # todo
end

#on_commit_failed(&block) ⇒ Object



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

def on_commit_failed(&block)
  return unless block
  # todo
end

#orient_graphObject



66
67
68
# File 'lib/pacer-orient/graph.rb', line 66

def orient_graph
  blueprints_graph.raw_graph
end

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



167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/pacer-orient/graph.rb', line 167

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



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/pacer-orient/graph.rb', line 151

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



182
183
184
185
186
187
188
# File 'lib/pacer-orient/graph.rb', line 182

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

#sql(extensions, sql = nil, args) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/pacer-orient/graph.rb', line 125

def sql(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.v(extensions))
end

#sql_command(sql, args) ⇒ Object



143
144
145
146
147
148
# File 'lib/pacer-orient/graph.rb', line 143

def sql_command(sql, args)
  unless args.frozen?
    args = args.map { |a| encoder.encode_property(a) }
  end
  blueprints_graph.command(OCommandSQL.new(sql)).execute(*args)
end

#sql_e(extensions, sql = nil, args) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/pacer-orient/graph.rb', line 134

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_labelObject



109
110
111
# File 'lib/pacer-orient/graph.rb', line 109

def use_class_for_edge_label
  blueprints_graph.useClassForEdgeLabel
end

#use_class_for_edge_label=(b) ⇒ Object



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

def use_class_for_edge_label=(b)
  blueprints_graph.useClassForEdgeLabel = b
end

#use_class_for_vertex_labelObject



117
118
119
# File 'lib/pacer-orient/graph.rb', line 117

def use_class_for_vertex_label
  blueprints_graph.useClassForVertexLabel
end

#use_class_for_vertex_label=(b) ⇒ Object



121
122
123
# File 'lib/pacer-orient/graph.rb', line 121

def use_class_for_vertex_label=(b)
  blueprints_graph.useClassForVertexLabel = b
end