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
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/framework/rho/rhoutils.rb', line 33
def self.load_offline_data(tables=[], dir_prefix=nil, source_map=nil)
columns = []
tables.each do |filename|
if @@mapSrc.nil?
@@mapSrc = {}
@@mapSrcByIdx = {}
arSrcs = Rhom::RhomSource.find(:all)
arSrcs.each do |src|
@@mapSrc[src.name()] = src
@@mapSrcByIdx[src.source_id()] = src
end
end
mapDeleted = {}
mapPartDeleted = {}
db = nil
first_row=true
prefix = dir_prefix.nil? ? "" : dir_prefix
cur_src = nil
hashItem = {}
cur_objid = nil
f = File.open(File.join(Rho::RhoFSConnector.get_base_app_path(),'app',prefix,'fixtures',filename+'.txt'))
f.each do |line|
if first_row
columns = line.chomp.split('|'); first_row = false; next;
end
parts = line.chomp.split('|')
row = {}
columns.each_with_index do |col,idx|
col.strip!
if col == 'source_name'
src_name = parts[idx]
src_name = source_map[src_name] if source_map
row['source_id'] = @@mapSrc[src_name].source_id()
else
row[col] = parts[idx]
end
end
src = @@mapSrcByIdx[ row['source_id'].to_i ]
src_db = src ? ::Rho::RHO.get_src_db(src.name() ) : ::Rho::RHO.get_user_db()
if src_db != db
db.commit if db
db = src_db
db.start_transaction
if !mapPartDeleted[db]
db.delete_all_from_table(filename)
mapPartDeleted[db] = 1
end
end
if ( cur_objid != row['object'] )
if cur_src && hashItem && hashItem.length() > 0
if !mapDeleted[cur_src.name()]
db.delete_all_from_table(cur_src.name())
mapDeleted[cur_src.name()] = 1
end
hashItem['object'] = cur_objid
db.insert_into_table(cur_src.name(),hashItem)
end
hashItem = {}
cur_objid = row['object']
end
cur_src = @@mapSrcByIdx[ row['source_id'].to_i ]
if ( cur_src && cur_src.schema() )
hashItem[ row['attrib'] ] = row['value'] if row['value']
else
db.insert_into_table(filename,row)
end
end
f.close
if cur_src && hashItem && hashItem.length() > 0
if !mapDeleted[cur_src.name()]
db.delete_all_from_table(cur_src.name())
mapDeleted[cur_src.name()] = 1
end
hashItem['object'] = cur_objid
db.insert_into_table(cur_src.name(),hashItem)
end
db.commit if db
columns = []
end
end
|