spreadsheet_db-cache_refi 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spreadsheet_db-cache_refi.rb +115 -0
- metadata +93 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "spreadsheet_manager_refi"
|
4
|
+
require "spreadsheet_db_refi"
|
5
|
+
|
6
|
+
# modifications to the db in SpreadsheetDb:
|
7
|
+
# * add metadata to the metadata table
|
8
|
+
# * creates a new table "sheet_cached"
|
9
|
+
|
10
|
+
module Refi
|
11
|
+
|
12
|
+
class SpreadsheetDbCache < SpreadsheetDb
|
13
|
+
|
14
|
+
@@ext1_create_tbls_strs = {
|
15
|
+
sheet_cached: %q(
|
16
|
+
create table sheet_cached(
|
17
|
+
sheet_id integer,
|
18
|
+
cached integer,
|
19
|
+
|
20
|
+
primary key(sheet_id),
|
21
|
+
foreign key(sheet_id) references sheet(id)
|
22
|
+
);
|
23
|
+
)
|
24
|
+
}.inject({}){|memo,(k,v)| memo[k] = v.strip_a_lot ; memo}.merge(@@std_create_tbls_strs)
|
25
|
+
|
26
|
+
@@ext1_stmts_strs = {
|
27
|
+
sheet_cached_set_sheet_cached: "insert or replace into sheet_cached(sheet_id,cached) values(?,?);",
|
28
|
+
sheet_cached_get_cached_by_sheet: "select cached from sheet_cached where sheet_id=?;",
|
29
|
+
sheet_cached_get_all: "select * from sheet_cached;",
|
30
|
+
}.merge(@@std_stmts_strs)
|
31
|
+
|
32
|
+
@@ext1_tbl_create_order = @@std_tbl_create_order + [:sheet_cached]
|
33
|
+
|
34
|
+
def initialize(db_pn,ss_pn,ss_manager)
|
35
|
+
@create_tbls_strs = @@ext1_create_tbls_strs
|
36
|
+
@stmts_strs = @@ext1_stmts_strs
|
37
|
+
@tbl_create_order = @@ext1_tbl_create_order
|
38
|
+
init2
|
39
|
+
@pn = db_pn
|
40
|
+
@ss_pn = ss_pn
|
41
|
+
@ss_manager = ss_manager
|
42
|
+
@db_pn = db_pn
|
43
|
+
has_old_db = File.exist?(db_pn)
|
44
|
+
if(has_old_db)
|
45
|
+
open
|
46
|
+
old_db_metadata = get_metadata()
|
47
|
+
if(old_db_metadata.at_least?(@ss_manager.get_metadata(ss_pn)))
|
48
|
+
# old db good
|
49
|
+
else
|
50
|
+
# old db metadata bad
|
51
|
+
reset
|
52
|
+
File.delete(db_pn)
|
53
|
+
create_cache
|
54
|
+
end
|
55
|
+
else
|
56
|
+
# no old db
|
57
|
+
create_cache
|
58
|
+
end
|
59
|
+
end
|
60
|
+
def create_cache
|
61
|
+
open
|
62
|
+
@db.transaction{|foo|
|
63
|
+
#set_feature("sheet_cache",true)
|
64
|
+
import_sheet_names(@ss_manager.get_ss(@ss_pn).sheets)
|
65
|
+
import_metadata(@ss_manager.get_metadata(@ss_pn))
|
66
|
+
}
|
67
|
+
end
|
68
|
+
def import_sheet_names(sheet_names)
|
69
|
+
sheet_names.each_index{|sheet_ix|
|
70
|
+
sheet_name = sheet_names[sheet_ix]
|
71
|
+
pos = sheet_ix
|
72
|
+
id = create_sheet(sheet_name,pos)
|
73
|
+
set_sheet_cached_state(id,0)
|
74
|
+
}
|
75
|
+
end
|
76
|
+
def set_sheet_cached_state(sheet_id,state)
|
77
|
+
dperr(324,"sheet_id must be of integer type (sheet_id.class:#{sheet_id.class.to_s})") unless sheet_id.is_a?(Fixnum)
|
78
|
+
@prep_stmts[:sheet_cached_set_sheet_cached].execute(sheet_id,state)
|
79
|
+
end
|
80
|
+
def import_metadata(metadata)
|
81
|
+
metadata.each{|name,value|
|
82
|
+
@prep_stmts[:metadata_set_nam_val].execute(name,value)
|
83
|
+
}
|
84
|
+
end
|
85
|
+
def is_sheet_cached?(sheet_id)
|
86
|
+
# TODO prep_ex ?
|
87
|
+
is_cached = ( @prep_stmts[:sheet_cached_get_cached_by_sheet].execute!(sheet_id).flatten[0] == 1 )
|
88
|
+
#pp @prep_stmts[:sheet_cached_get_cached_by_sheet].execute!(sheet_id)
|
89
|
+
return is_cached
|
90
|
+
end
|
91
|
+
def get_sheet(sheet_xid)
|
92
|
+
if sheet_xid == nil
|
93
|
+
$Log.tlog({id: 'err1040'})
|
94
|
+
end
|
95
|
+
sheet_id = get_sheet_id_from_xid(sheet_xid)
|
96
|
+
if(!is_sheet_cached?(sheet_id))
|
97
|
+
ss = @ss_manager.get_ss(@ss_pn)
|
98
|
+
sheet_name = get_sheet_name_from_xid(sheet_id)
|
99
|
+
if sheet_name == nil
|
100
|
+
$Log.tlog({id: 'err1070',sheet_id:sheet_id,sheet_xid:sheet_xid})
|
101
|
+
end
|
102
|
+
puts 'sheet_name:'
|
103
|
+
pp sheet_name
|
104
|
+
ss.default_sheet = sheet_name
|
105
|
+
import_sheet(sheet_id,ss)
|
106
|
+
end
|
107
|
+
super
|
108
|
+
end
|
109
|
+
def import_sheet(sheet_id,ss)
|
110
|
+
super
|
111
|
+
set_sheet_cached_state(sheet_id,1)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end # module Refi
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spreadsheet_db-cache_refi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Robert Fey
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-07-26 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: spreadsheet_db_refi
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 0.0.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: spreadsheet_manager_refi
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - "="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 0.0.0
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: cache reads from spreadsheet files in a sqilte db
|
51
|
+
email: feyrob@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- lib/spreadsheet_db-cache_refi.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://rubygems.org/gems/spreadsheet_db-cache_refi
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: nowarning
|
88
|
+
rubygems_version: 1.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: ""
|
92
|
+
test_files: []
|
93
|
+
|