cloudwow-not_relational 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +7 -0
- data/VERSION.yml +4 -0
- data/lib/not_relational/acts_as_not_relational_application.rb +11 -0
- data/lib/not_relational/and_condition.rb +10 -0
- data/lib/not_relational/attribute_range.rb +57 -0
- data/lib/not_relational/berkeley_repository.rb +48 -0
- data/lib/not_relational/configuration.rb +111 -0
- data/lib/not_relational/crypto.rb +58 -0
- data/lib/not_relational/domain_model.rb +855 -0
- data/lib/not_relational/domain_model_cache_item.rb +14 -0
- data/lib/not_relational/equals_condition.rb +18 -0
- data/lib/not_relational/geo.rb +188 -0
- data/lib/not_relational/index_description.rb +41 -0
- data/lib/not_relational/is_null_transform.rb +16 -0
- data/lib/not_relational/lazy_loading_text.rb +29 -0
- data/lib/not_relational/local_storage.rb +38 -0
- data/lib/not_relational/memcache_repository.rb +91 -0
- data/lib/not_relational/memory_repository.rb +273 -0
- data/lib/not_relational/memory_storage.rb +33 -0
- data/lib/not_relational/or_condition.rb +53 -0
- data/lib/not_relational/property_description.rb +102 -0
- data/lib/not_relational/query_string_auth_generator.rb +166 -0
- data/lib/not_relational/reference.rb +28 -0
- data/lib/not_relational/repository.rb +419 -0
- data/lib/not_relational/repository_factory.rb +67 -0
- data/lib/not_relational/repository_interface.rb +48 -0
- data/lib/not_relational/s3.rb +581 -0
- data/lib/not_relational/sdb_formatter.rb +119 -0
- data/lib/not_relational/sdb_monkey_patch.rb +47 -0
- data/lib/not_relational/starts_with_condition.rb +21 -0
- data/lib/not_relational/storage.rb +223 -0
- data/lib/not_relational/tag_cloud.rb +56 -0
- data/lib/not_relational/tracker_description.rb +26 -0
- data/lib/not_relational/uuid.rb +285 -0
- data/lib/not_relational.rb +17 -0
- data/test/models/album.rb +206 -0
- data/test/models/blurb.rb +65 -0
- data/test/models/blurb_wording.rb +18 -0
- data/test/models/comment.rb +27 -0
- data/test/models/error.rb +14 -0
- data/test/models/friend.rb +27 -0
- data/test/models/friend_request.rb +34 -0
- data/test/models/geo.rb +186 -0
- data/test/models/group.rb +283 -0
- data/test/models/language.rb +16 -0
- data/test/models/media_file.rb +32 -0
- data/test/models/media_item.rb +258 -0
- data/test/models/message.rb +26 -0
- data/test/models/node.rb +282 -0
- data/test/models/outgoing_email.rb +26 -0
- data/test/models/page_view_detail.rb +15 -0
- data/test/models/page_view_summary.rb +15 -0
- data/test/models/place.rb +103 -0
- data/test/models/rating.rb +21 -0
- data/test/models/tag.rb +89 -0
- data/test/models/user.rb +289 -0
- data/test/models/user_event.rb +67 -0
- data/test/models/weblab.rb +17 -0
- data/test/unit_tests/album_test.rb +181 -0
- data/test/unit_tests/bdb_test.rb +34 -0
- data/test/unit_tests/blurb_test.rb +110 -0
- data/test/unit_tests/comment_test.rb +42 -0
- data/test/unit_tests/composite_key_test.rb +75 -0
- data/test/unit_tests/enum_test.rb +32 -0
- data/test/unit_tests/group_test.rb +214 -0
- data/test/unit_tests/mediaitem_test.rb +412 -0
- data/test/unit_tests/memcache_repository_test.rb +40 -0
- data/test/unit_tests/memory_repository_test.rb +69 -0
- data/test/unit_tests/node_test.rb +490 -0
- data/test/unit_tests/place_test.rb +219 -0
- data/test/unit_tests/reference_set_test.rb +66 -0
- data/test/unit_tests/repository_factory_test.rb +16 -0
- data/test/unit_tests/tag_test.rb +86 -0
- data/test/unit_tests/user_test.rb +102 -0
- data/test/unit_tests/uuid.state +3 -0
- data/test/utils/create_sdb_domains.rb +44 -0
- data/test/utils/whack_domains.rb +32 -0
- metadata +134 -0
data/README.rdoc
ADDED
data/VERSION.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module NotRelational
|
2
|
+
module ActsAsNotRelationalApplication
|
3
|
+
def self.included(base)
|
4
|
+
base.before_filter :prepare_repository
|
5
|
+
end
|
6
|
+
def prepare_repository
|
7
|
+
puts "prepare repo"
|
8
|
+
NotRelational::RepositoryFactory.instance.clear_session_cache
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module NotRelational
|
2
|
+
|
3
|
+
class AttributeRange
|
4
|
+
attr_accessor :less_than
|
5
|
+
attr_accessor :greater_than
|
6
|
+
attr_accessor :less_than_or_equal_to
|
7
|
+
attr_accessor :greater_than_or_equal_to
|
8
|
+
attr_accessor :attribute_description #if this exists we act on objects else we act on attributes
|
9
|
+
|
10
|
+
def initialize(options)
|
11
|
+
|
12
|
+
self.attribute_description=options[:attribute_description]
|
13
|
+
|
14
|
+
self.less_than=options[:less_than]
|
15
|
+
self.greater_than=options[:greater_than]
|
16
|
+
self.less_than_or_equal_to=options[:less_than_or_equal_to]
|
17
|
+
self.greater_than_or_equal_to=options[:greater_than_or_equal_to]
|
18
|
+
|
19
|
+
end
|
20
|
+
def matches?(arg)
|
21
|
+
value=arg
|
22
|
+
if self.attribute_description
|
23
|
+
#its an object so pull out the value
|
24
|
+
value=arg[attribute_description.name]
|
25
|
+
end
|
26
|
+
return false if value==nil
|
27
|
+
return false if self.less_than && (value <=> self.less_than) >-1
|
28
|
+
return false if self.less_than_or_equal_to && (value <=> self.less_than_or_equal_to) ==1
|
29
|
+
return false if self.greater_than && (value<=>self.greater_than) <1
|
30
|
+
return false if self.greater_than_or_equal_to &&(value<=>self.greater_than_or_equal_to) ==-1
|
31
|
+
|
32
|
+
return true
|
33
|
+
end
|
34
|
+
def to_sdb_query
|
35
|
+
query=''
|
36
|
+
if self.less_than
|
37
|
+
query << " '#{attribute_description.name}' < '#{ attribute_description.format_for_sdb( self.less_than)}'"
|
38
|
+
end
|
39
|
+
if self.greater_than
|
40
|
+
query << ' and ' if query.length>0
|
41
|
+
query << " '#{attribute_description.name}' > '#{ attribute_description.format_for_sdb( self.greater_than)}'"
|
42
|
+
end
|
43
|
+
if self.less_than_or_equal_to
|
44
|
+
query << ' and ' if query.length>0
|
45
|
+
query << " '#{attribute_description.name}' <= '#{ attribute_description.format_for_sdb( self.less_than_or_equal_to)}'"
|
46
|
+
end
|
47
|
+
if self.greater_than_or_equal_to
|
48
|
+
query << ' and ' if query.length>0
|
49
|
+
query << " '#{attribute_description.name}' >= '#{ attribute_description.format_for_sdb( self.greater_than_or_equal_to)}'"
|
50
|
+
end
|
51
|
+
|
52
|
+
return query
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
module NotRelational
|
5
|
+
class BerkeleyRepository
|
6
|
+
def initialize(
|
7
|
+
domain_name= nil,
|
8
|
+
clob_bucket= nil,
|
9
|
+
aws_key_id= nil,
|
10
|
+
aws_secret_key= nil,
|
11
|
+
memcache_servers = nil ,
|
12
|
+
dummy=nil,
|
13
|
+
append_table_to_domain=nil,
|
14
|
+
options={}
|
15
|
+
)
|
16
|
+
|
17
|
+
end
|
18
|
+
def pause
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear_session_cache
|
22
|
+
|
23
|
+
end
|
24
|
+
def save(table_name, primary_key, attributes,index_descriptions)
|
25
|
+
end
|
26
|
+
def save_into_index(table_name,record,index_name,index_value)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def retrieve_from_index(table_name,index_name,index_value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def query_ids(table_name,attribute_descriptions,options)
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def query(table_name,attribute_descriptions,options)
|
38
|
+
end
|
39
|
+
def find_one(table_name, primary_key,attribute_descriptions)#, non_clob_attribute_names, clob_attribute_names)
|
40
|
+
end
|
41
|
+
def get_clob(table_name,primary_key,clob_name)
|
42
|
+
end
|
43
|
+
def destroy(table_name, primary_key)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "openssl"
|
2
|
+
|
3
|
+
|
4
|
+
module NotRelational
|
5
|
+
class Configuration
|
6
|
+
|
7
|
+
attr_reader :repository_class
|
8
|
+
attr_reader :domain_prefix
|
9
|
+
attr_reader :clob_bucket
|
10
|
+
attr_reader :aws_key_id
|
11
|
+
attr_reader :aws_secret_key
|
12
|
+
attr_reader :memcache_servers
|
13
|
+
attr_reader :append_table_to_domain
|
14
|
+
attr_reader :fail_fast
|
15
|
+
|
16
|
+
attr_reader :cipher_key_file
|
17
|
+
attr_reader :cipher_iv_file
|
18
|
+
|
19
|
+
def self.singleton
|
20
|
+
@singleton ||= NotRelational::Configuration.new
|
21
|
+
return @singleton
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize()
|
25
|
+
not_relational_config=find_config_section
|
26
|
+
|
27
|
+
if not_relational_config
|
28
|
+
if not_relational_config.has_key?("repository_class")
|
29
|
+
@repository_class=eval not_relational_config["repository_class"]
|
30
|
+
else
|
31
|
+
@repository_class=NotRelational::Repository
|
32
|
+
end
|
33
|
+
@domain_prefix= not_relational_config["domain_name_prefix"] || ""
|
34
|
+
@clob_bucket= not_relational_config["s3_clob_bucket"]
|
35
|
+
@aws_key_id = not_relational_config["aws_key_id"]
|
36
|
+
@aws_secret_key = not_relational_config["aws_secret_key"]
|
37
|
+
@memcache_servers= not_relational_config['memcache_servers']
|
38
|
+
@memcache_servers = memcache_servers.split(",") if memcache_servers
|
39
|
+
|
40
|
+
@append_table_to_domain=not_relational_config['append_table_to_domain']
|
41
|
+
@fail_fast=not_relational_config['fail_fast']
|
42
|
+
|
43
|
+
@cipher_key_file = not_relational_config['cipher_key_file']
|
44
|
+
@cipher_key_file ||= "./.cipher_key"
|
45
|
+
if @cipher_key_file and File.exists?(@cipher_key_file)
|
46
|
+
@cipher_key=File.open(@cipher_key_file).read
|
47
|
+
end
|
48
|
+
|
49
|
+
@cipher_iv_file ||= "./cipher_iv"
|
50
|
+
@cipher_iv_file=not_relational_config['cipher_iv_file']
|
51
|
+
if @cipher_iv_file and File.exists?(@cipher_iv_file)
|
52
|
+
@cipher_iv=File.open(@cipher_iv_file).read
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
def crypto
|
58
|
+
return @crypto if @crypto
|
59
|
+
options={}
|
60
|
+
if cipher_key
|
61
|
+
options[:cipher_key=]= cipher_key
|
62
|
+
options[:cipher_iv ]= cipher_iv
|
63
|
+
@crypto=Crypto.new()
|
64
|
+
else
|
65
|
+
@crypto=Crypto.new
|
66
|
+
File.open(self.cipher_key_file,'w').write(@crypto.key)
|
67
|
+
File.open(self.cipher_iv_file,'w').write(@crypto.iv)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def cipher_key
|
71
|
+
return @cipher_key
|
72
|
+
end
|
73
|
+
|
74
|
+
def cipher_iv
|
75
|
+
return @cipher_iv
|
76
|
+
end
|
77
|
+
|
78
|
+
def find_config_section
|
79
|
+
return $not_relational_config if $not_relational_config
|
80
|
+
config_file_path=nil
|
81
|
+
config_section=nil
|
82
|
+
|
83
|
+
#when using rails use config/database.yml
|
84
|
+
if Object.const_defined?(:RAILS_ROOT) and ENV.has_key?('RAILS_ENV')
|
85
|
+
config_file_path = File.join("#{RAILS_ROOT}","config","database.yml")
|
86
|
+
|
87
|
+
config_section =ENV['RAILS_ENV']+"_not_relational"
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
else
|
92
|
+
#when not using rails use try database.yml then try config/database.yml
|
93
|
+
|
94
|
+
if File.exists?("database.yml")
|
95
|
+
|
96
|
+
config_file_path = "database.yml"
|
97
|
+
elsif File.exists?(File.join("config", "database.yml"))
|
98
|
+
config_file_path = File.join("config", "database.yml")
|
99
|
+
end
|
100
|
+
|
101
|
+
config_section =(ENV['not_relational_ENV'] || "production")+"_not_relational"
|
102
|
+
end
|
103
|
+
if config_file_path and config_section
|
104
|
+
config_file = YAML.load(File.open( config_file_path))
|
105
|
+
|
106
|
+
$not_relational_config = config_file[config_section]
|
107
|
+
end
|
108
|
+
return $not_relational_config
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "openssl"
|
2
|
+
|
3
|
+
module NotRelational
|
4
|
+
class Crypto
|
5
|
+
|
6
|
+
attr_reader :key
|
7
|
+
attr_reader :iv
|
8
|
+
def initialize(options={})
|
9
|
+
@cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
|
10
|
+
|
11
|
+
@key=options[:cipher_key] if options.has_key?(:cipher_key)
|
12
|
+
@iv=options[:cipher_iv] if options.has_key?(:cipher_iv)
|
13
|
+
|
14
|
+
unless @key
|
15
|
+
key_dir=options[:key_dir] if options.has_key?(:key_dir)
|
16
|
+
key_dir ||="/tmp"
|
17
|
+
|
18
|
+
if File.exists?(key_dir+'/.cipher_key')
|
19
|
+
@key=File.open(key_dir+'/.cipher_key').read
|
20
|
+
else
|
21
|
+
@key = @cipher.random_key()
|
22
|
+
File.open(key_dir+"/.cipher_key",'w').write(@key)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
unless @iv
|
28
|
+
if File.exists?(key_dir+'/.cipher_iv')
|
29
|
+
@iv=File.open(key_dir+'/.cipher_iv').read
|
30
|
+
else
|
31
|
+
@iv = @cipher.random_iv()
|
32
|
+
File.open(key_dir+"/.cipher_iv",'w').write(@iv)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def encrypt(text)
|
38
|
+
|
39
|
+
@cipher.encrypt(@key,@iv)
|
40
|
+
@cipher.key=@key
|
41
|
+
@cipher.iv = @iv
|
42
|
+
e = @cipher.update(text)
|
43
|
+
e << @cipher.final()
|
44
|
+
Base64.encode64(e)#.chomp
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def decrypt(text)
|
49
|
+
x=Base64.decode64(text)
|
50
|
+
@cipher.decrypt(@key,@iv)
|
51
|
+
@cipher.key = @key
|
52
|
+
@cipher.iv = @iv
|
53
|
+
d = @cipher.update(x)
|
54
|
+
d << @cipher.final()
|
55
|
+
return d
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|