Class: DrbRelationBuilder
- Inherits:
-
Object
- Object
- DrbRelationBuilder
- Includes:
- DRbUndumped, Eprint
- Defined in:
- lib/DrbDB/DrbRelationBuilder.rb
Overview
this file is part of manqod manqod is distributed under the CDDL licence the owner of manqod is Dobai-Pataky Balint([email protected])
Constant Summary
Constants included from Eprint
Instance Attribute Summary collapse
-
#moditem ⇒ Object
readonly
Returns the value of attribute moditem.
Instance Method Summary collapse
-
#initialize(drbdb, my_id) ⇒ DrbRelationBuilder
constructor
A new instance of DrbRelationBuilder.
- #mod_type ⇒ Object
- #to_s ⇒ Object
- #update(table = nil, relation = nil) ⇒ Object
Methods included from Eprint
#ecode, #edebug, #eerror, #eeval, #eexception, #efatal, #einfo, #eprint, #ewarn, #getBinding, #report_mail
Constructor Details
#initialize(drbdb, my_id) ⇒ DrbRelationBuilder
Returns a new instance of DrbRelationBuilder.
9 10 11 12 13 14 15 16 |
# File 'lib/DrbDB/DrbRelationBuilder.rb', line 9 def initialize(drbdb,my_id) @my_id=my_id.to_i @drbdb=drbdb @title="Relation Builder" @relations=Hash.new @tables=Hash.new end |
Instance Attribute Details
#moditem ⇒ Object (readonly)
Returns the value of attribute moditem.
17 18 19 |
# File 'lib/DrbDB/DrbRelationBuilder.rb', line 17 def moditem @moditem end |
Instance Method Details
#mod_type ⇒ Object
121 122 123 |
# File 'lib/DrbDB/DrbRelationBuilder.rb', line 121 def mod_type "relation_builder" end |
#to_s ⇒ Object
125 126 127 |
# File 'lib/DrbDB/DrbRelationBuilder.rb', line 125 def to_s "#{@drbdb}.RelationBuilder" end |
#update(table = nil, relation = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/DrbDB/DrbRelationBuilder.rb', line 19 def update(table=nil,relation=nil) #specify one table or one relation or nothing #clear related relations if table.nil? && relation.nil? @relations.clear else #reload table related relations @relations.delete_if{|key,val| val["src_table"] == table || val["dst_table"] == table } if table #reload specified relation @relations.delete(relation) if relation end #clear related tables if relation.nil? if table.nil? @tables.clear else @tables.delete_if{|key,val| val["name"] == table } end end #load table or talbes if relation.nil? @drbdb.rows("select * from tables " + (table ? "where name='#{table}'" : "") ).each{|row| @tables[row["name"]]={ "id" => row["id"], "name" => row["name"], "rbx" => row["rbx"].to_f, "rby" => row["rby"].to_f } #indexes begin @tables[row["name"]]["indexes"]=Array.new @drbdb.client.rows("show indexes from #{row['name']}").each{|index| @tables[row["name"]]["indexes"].push({ "name"=>index["Key_name"], "unique"=>index["Non_unique"]=="0", "field"=>index["Column_name"] } ) } rescue => err eerror(err) end #is view? is_view=false begin @drbdb.client.fields("show create table `#{row['name']}`").each{|f| is_view=true if f["name"].include?("View")} @tables[row["name"]]["view"]=is_view rescue => err eerror(err) end #fields @tables[row["name"]]["fields"]=Hash.new begin @drbdb.client.rows("show fields from #{row['name']}").each{|field| fi=field.rehash if f=field["Type"].index("(") fi["Size"]=field["Type"][f+1 .. field["Type"].index(")") -1] fi["Type"]=field["Type"][0 .. f-1] end @tables[row["name"]]["fields"][field["Field"]]=fi } rescue => err eerror(err) end } end #relations if table.nil? @drbdb.rows("select * from relations " + (relation ? "where id='#{relation}'" : "") ).each{|row| @relations[row["id"]]={ "id" => row["id"], "src_table" => row["src_table"], "src_field" => row["src_field"], "dst_table" => row["dst_table"], "dst_field" => row["dst_field"], "rel_name" => row['rel_name'], "rel_type" => row["rel_type"], "rbx" => row["rbx"].to_f, "rby" => row["rby"].to_f, "rel_custom" => row['rel_custom'] } } end #store in the cache @drbdb.cache.set("tables",@tables) einfo("#{@tables.size} tables") @drbdb.cache.set("relations",@relations) einfo("#{@relations.size} relations") self end |