Method: ActiveOrient::API#create_properties

Defined in:
lib/jdbc.rb,
lib/java-api.rb

#create_properties(o_class, **all_properties, &b) ⇒ Object

Creates properties and optional an associated index as defined in the provided block

  create_properties(classname or class, properties as hash){index}

The default-case
  create_properties(:my_high_sophisticated_database_class,
    con_id: {type: :integer},
    details: {type: :link, linked_class: 'Contracts'}) do
      contract_idx: :notunique
    end

A composite index
  create_properties(:my_high_sophisticated_database_class,
    con_id: {type: :integer},
    symbol: {type: :string}) do
      {name: 'indexname',
       on: [:con_id, :details]    # default: all specified properties
       type: :notunique            # default: :unique
      }
    end

supported types: {

:bool          => "BOOLEAN",
:double        => "BYTE",
:datetime      => "DATE",
:float         => "FLOAT",
:decimal       => "DECIMAL",
:embedded_list => "EMBEDDEDLIST",
:list          => "EMBEDDEDLIST",
:embedded_map  => "EMBEDDEDMAP",
:map           => "EMBEDDEDMAP",
:embedded_set  => "EMBEDDEDSET",
:set           => "EMBEDDEDSET",
:int           => "INTEGER",
:integer       => "INTEGER",
:link_list     => "LINKLIST",
:link_map      => "LINKMAP",
:link_set      => "LINKSET",
}


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/jdbc.rb', line 136

def create_properties o_class, **all_properties, &b
logger.progname = 'JavaApi#CreateProperties'
ap =  all_properties
created_properties = ap.map do |property, specification | 
  puts "specification:  #{specification.inspect}"
  field_type = ( specification.is_a?( Hash) ?  specification[:type] : specification ).downcase.to_sym rescue :string
  the_other_class =  specification.is_a?(Hash) ?  specification[:other_class] : nil
  other_class = if the_other_class.present? 
      @db.get_class( the_other_class)
  end
  index =  ap.is_a?(Hash) ?  ap[:index] : nil
  if other_class.present?
    @db.get_class(classname(o_class)).add property,[ field_type, other_class ], { :index => index }
  else
    @db.get_class(classname(o_class)).add property, field_type, { :index => index }
  end
end
if block_given?
  attr =  yield
  index_parameters = case attr 
  when String, Symbol
    { name: attr }
  when Hash
    { name: attr.keys.first , type: attr.values.first, on: all_properties.keys.map(&:to_s) }
  else
    nil
  end
  create_index o_class, **index_parameters unless index_parameters.blank?
end
created_properties.size # return_value

end