manqod-server 1.280.0 → 1.281.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/DrbDB/DrbRelationBuilder.rb +89 -58
  2. metadata +3 -3
@@ -16,70 +16,101 @@ class DrbRelationBuilder
16
16
  end
17
17
  attr_reader :moditem
18
18
 
19
- def update
20
- @relations.clear
21
- @tables.clear
22
- @drbdb.rows("select * from tables").each{|row|
23
- @tables[row["name"]]={
24
- "id" => row["id"],
25
- "name" => row["name"],
26
- "rbx" => row["rbx"].to_f,
27
- "rby" => row["rby"].to_f
28
- }
29
- #indexes
30
- begin
31
- @tables[row["name"]]["indexes"]=Array.new
32
- @drbdb.client.rows("show indexes from #{row['name']}").each{|index|
33
- @tables[row["name"]]["indexes"].push({
34
- "name"=>index["Key_name"],
35
- "unique"=>index["Non_unique"]=="0",
36
- "field"=>index["Column_name"]
37
- }
38
- )
19
+ def update(table=nil,relation=nil)
20
+ #specify one table or one relation or nothing
21
+
22
+ #clear related relations
23
+ if table.nil? && relation.nil?
24
+ @relations.clear
25
+ else
26
+ #reload table related relations
27
+ @relations.delete_if{|key,val|
28
+ val["src_table"] == table || val["dst_table"] == table
29
+ } if table
30
+ #reload specified relation
31
+ @relations.delete(relation) if relation
32
+ end
33
+ #clear related tables
34
+ if relation.nil?
35
+ if table.nil?
36
+ @tables.clear
37
+ else
38
+ @tables.delete_if{|key,val|
39
+ val["name"] == table
39
40
  }
40
- rescue => err
41
- eerror(err)
42
41
  end
42
+ end
43
+
44
+ #load table or talbes
45
+ if relation.nil?
46
+ @drbdb.rows("select * from tables " + (table ? "where name='#{table}'" : "") ).each{|row|
47
+ @tables[row["name"]]={
48
+ "id" => row["id"],
49
+ "name" => row["name"],
50
+ "rbx" => row["rbx"].to_f,
51
+ "rby" => row["rby"].to_f
52
+ }
53
+ #indexes
54
+ begin
55
+ @tables[row["name"]]["indexes"]=Array.new
56
+ @drbdb.client.rows("show indexes from #{row['name']}").each{|index|
57
+ @tables[row["name"]]["indexes"].push({
58
+ "name"=>index["Key_name"],
59
+ "unique"=>index["Non_unique"]=="0",
60
+ "field"=>index["Column_name"]
61
+ }
62
+ )
63
+ }
64
+ rescue => err
65
+ eerror(err)
66
+ end
43
67
 
44
- #is view?
45
- is_view=false
46
- begin
47
- @drbdb.client.fields("show create table `#{row['name']}`").each{|f| is_view=true if f["name"].include?("View")}
48
- @tables[row["name"]]["view"]=is_view
49
- rescue => err
50
- eerror(err)
51
- end
68
+ #is view?
69
+ is_view=false
70
+ begin
71
+ @drbdb.client.fields("show create table `#{row['name']}`").each{|f| is_view=true if f["name"].include?("View")}
72
+ @tables[row["name"]]["view"]=is_view
73
+ rescue => err
74
+ eerror(err)
75
+ end
52
76
 
53
- #fields
54
- @tables[row["name"]]["fields"]=Hash.new
55
- begin
56
- @drbdb.client.rows("show fields from #{row['name']}").each{|field|
57
- fi=field.rehash
58
- if f=field["Type"].index("(")
59
- fi["Size"]=field["Type"][f+1 .. field["Type"].index(")") -1]
60
- fi["Type"]=field["Type"][0 .. f-1]
61
- end
62
- @tables[row["name"]]["fields"][field["Field"]]=fi
63
- }
64
- rescue => err
65
- eerror(err)
66
- end
77
+ #fields
78
+ @tables[row["name"]]["fields"]=Hash.new
79
+ begin
80
+ @drbdb.client.rows("show fields from #{row['name']}").each{|field|
81
+ fi=field.rehash
82
+ if f=field["Type"].index("(")
83
+ fi["Size"]=field["Type"][f+1 .. field["Type"].index(")") -1]
84
+ fi["Type"]=field["Type"][0 .. f-1]
85
+ end
86
+ @tables[row["name"]]["fields"][field["Field"]]=fi
87
+ }
88
+ rescue => err
89
+ eerror(err)
90
+ end
67
91
 
68
- }
69
- @drbdb.rows("select * from relations").each{|row|
70
- @relations[row["id"]]={
71
- "id" => row["id"],
72
- "src_table" => row["src_table"],
73
- "src_field" => row["src_field"],
74
- "dst_table" => row["dst_table"],
75
- "dst_field" => row["dst_field"],
76
- "rel_name" => row['rel_name'],
77
- "rel_type" => row["rel_type"],
78
- "rbx" => row["rbx"].to_f,
79
- "rby" => row["rby"].to_f,
80
- "rel_custom" => row['rel_custom']
81
92
  }
82
- }
93
+ end
94
+
95
+ #relations
96
+ if table.nil?
97
+ @drbdb.rows("select * from relations " + (relation ? "where id='#{relation}'" : "") ).each{|row|
98
+ @relations[row["id"]]={
99
+ "id" => row["id"],
100
+ "src_table" => row["src_table"],
101
+ "src_field" => row["src_field"],
102
+ "dst_table" => row["dst_table"],
103
+ "dst_field" => row["dst_field"],
104
+ "rel_name" => row['rel_name'],
105
+ "rel_type" => row["rel_type"],
106
+ "rbx" => row["rbx"].to_f,
107
+ "rby" => row["rby"].to_f,
108
+ "rel_custom" => row['rel_custom']
109
+ }
110
+ }
111
+ end
112
+
113
+ #store in the cache
83
114
  @drbdb.cache.set("tables",@tables)
84
115
  einfo("#{@tables.size} tables")
85
116
  @drbdb.cache.set("relations",@relations)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 280
7
+ - 281
8
8
  - 0
9
- version: 1.280.0
9
+ version: 1.281.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dobai-Pataky Balint
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-25 00:00:00 +03:00
17
+ date: 2011-06-23 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency