massive_record 0.2.1 → 0.2.2.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/CHANGELOG.md +58 -2
  2. data/Gemfile.lock +17 -17
  3. data/README.md +98 -41
  4. data/lib/massive_record.rb +2 -1
  5. data/lib/massive_record/adapters/thrift/hbase/hbase.rb +2425 -2154
  6. data/lib/massive_record/adapters/thrift/hbase/hbase_constants.rb +3 -3
  7. data/lib/massive_record/adapters/thrift/hbase/hbase_types.rb +195 -195
  8. data/lib/massive_record/adapters/thrift/row.rb +35 -4
  9. data/lib/massive_record/adapters/thrift/table.rb +49 -12
  10. data/lib/massive_record/orm/attribute_methods.rb +77 -5
  11. data/lib/massive_record/orm/attribute_methods/cast_numbers_on_write.rb +24 -0
  12. data/lib/massive_record/orm/attribute_methods/dirty.rb +18 -0
  13. data/lib/massive_record/orm/attribute_methods/time_zone_conversion.rb +24 -3
  14. data/lib/massive_record/orm/attribute_methods/write.rb +8 -1
  15. data/lib/massive_record/orm/base.rb +62 -8
  16. data/lib/massive_record/orm/column.rb +7 -11
  17. data/lib/massive_record/orm/default_id.rb +1 -1
  18. data/lib/massive_record/orm/embedded.rb +66 -0
  19. data/lib/massive_record/orm/errors.rb +17 -0
  20. data/lib/massive_record/orm/finders.rb +124 -71
  21. data/lib/massive_record/orm/finders/rescue_missing_table_on_find.rb +1 -1
  22. data/lib/massive_record/orm/finders/scope.rb +58 -34
  23. data/lib/massive_record/orm/id_factory.rb +22 -105
  24. data/lib/massive_record/orm/id_factory/atomic_incrementation.rb +117 -0
  25. data/lib/massive_record/orm/id_factory/timestamp.rb +60 -0
  26. data/lib/massive_record/orm/identity_map.rb +256 -0
  27. data/lib/massive_record/orm/log_subscriber.rb +18 -0
  28. data/lib/massive_record/orm/observer.rb +69 -0
  29. data/lib/massive_record/orm/persistence.rb +47 -119
  30. data/lib/massive_record/orm/persistence/operations.rb +100 -0
  31. data/lib/massive_record/orm/persistence/operations/atomic_operation.rb +71 -0
  32. data/lib/massive_record/orm/persistence/operations/destroy.rb +17 -0
  33. data/lib/massive_record/orm/persistence/operations/embedded/destroy.rb +26 -0
  34. data/lib/massive_record/orm/persistence/operations/embedded/insert.rb +27 -0
  35. data/lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb +66 -0
  36. data/lib/massive_record/orm/persistence/operations/embedded/reload.rb +39 -0
  37. data/lib/massive_record/orm/persistence/operations/embedded/update.rb +29 -0
  38. data/lib/massive_record/orm/persistence/operations/insert.rb +19 -0
  39. data/lib/massive_record/orm/persistence/operations/reload.rb +26 -0
  40. data/lib/massive_record/orm/persistence/operations/suppress.rb +15 -0
  41. data/lib/massive_record/orm/persistence/operations/table_operation_helpers.rb +106 -0
  42. data/lib/massive_record/orm/persistence/operations/update.rb +25 -0
  43. data/lib/massive_record/orm/query_instrumentation.rb +26 -49
  44. data/lib/massive_record/orm/raw_data.rb +47 -0
  45. data/lib/massive_record/orm/relations.rb +4 -0
  46. data/lib/massive_record/orm/relations/interface.rb +134 -0
  47. data/lib/massive_record/orm/relations/metadata.rb +58 -12
  48. data/lib/massive_record/orm/relations/proxy.rb +17 -12
  49. data/lib/massive_record/orm/relations/proxy/embedded_in.rb +54 -0
  50. data/lib/massive_record/orm/relations/proxy/embedded_in_polymorphic.rb +15 -0
  51. data/lib/massive_record/orm/relations/proxy/embeds_many.rb +215 -0
  52. data/lib/massive_record/orm/relations/proxy/references_many.rb +112 -88
  53. data/lib/massive_record/orm/relations/proxy/references_one.rb +1 -1
  54. data/lib/massive_record/orm/relations/proxy/references_one_polymorphic.rb +1 -1
  55. data/lib/massive_record/orm/relations/proxy_collection.rb +84 -0
  56. data/lib/massive_record/orm/schema/column_family.rb +3 -2
  57. data/lib/massive_record/orm/schema/{column_interface.rb → embedded_interface.rb} +38 -4
  58. data/lib/massive_record/orm/schema/field.rb +2 -0
  59. data/lib/massive_record/orm/schema/table_interface.rb +19 -2
  60. data/lib/massive_record/orm/single_table_inheritance.rb +37 -2
  61. data/lib/massive_record/orm/timestamps.rb +17 -7
  62. data/lib/massive_record/orm/validations.rb +4 -0
  63. data/lib/massive_record/orm/validations/associated.rb +50 -0
  64. data/lib/massive_record/rails/railtie.rb +31 -0
  65. data/lib/massive_record/version.rb +1 -1
  66. data/lib/massive_record/wrapper/cell.rb +8 -1
  67. data/massive_record.gemspec +4 -4
  68. data/spec/adapter/thrift/atomic_increment_spec.rb +16 -0
  69. data/spec/adapter/thrift/table_find_spec.rb +14 -2
  70. data/spec/adapter/thrift/table_spec.rb +6 -6
  71. data/spec/adapter/thrift/utf8_encoding_of_id_spec.rb +71 -0
  72. data/spec/orm/cases/attribute_methods_spec.rb +215 -22
  73. data/spec/orm/cases/auto_generate_id_spec.rb +1 -1
  74. data/spec/orm/cases/change_id_spec.rb +62 -0
  75. data/spec/orm/cases/default_id_spec.rb +25 -6
  76. data/spec/orm/cases/default_values_spec.rb +6 -3
  77. data/spec/orm/cases/dirty_spec.rb +150 -102
  78. data/spec/orm/cases/embedded_spec.rb +250 -0
  79. data/spec/orm/cases/{finder_default_scope.rb → finder_default_scope_spec.rb} +4 -0
  80. data/spec/orm/cases/finder_scope_spec.rb +96 -29
  81. data/spec/orm/cases/finders_spec.rb +57 -10
  82. data/spec/orm/cases/id_factory/atomic_incrementation_spec.rb +72 -0
  83. data/spec/orm/cases/id_factory/timestamp_spec.rb +61 -0
  84. data/spec/orm/cases/identity_map/identity_map_spec.rb +357 -0
  85. data/spec/orm/cases/identity_map/middleware_spec.rb +74 -0
  86. data/spec/orm/cases/log_subscriber_spec.rb +15 -2
  87. data/spec/orm/cases/observing_spec.rb +61 -0
  88. data/spec/orm/cases/persistence_spec.rb +151 -60
  89. data/spec/orm/cases/raw_data_spec.rb +58 -0
  90. data/spec/orm/cases/single_table_inheritance_spec.rb +58 -2
  91. data/spec/orm/cases/table_spec.rb +3 -3
  92. data/spec/orm/cases/time_zone_awareness_spec.rb +27 -0
  93. data/spec/orm/cases/timestamps_spec.rb +23 -109
  94. data/spec/orm/cases/validation_spec.rb +9 -0
  95. data/spec/orm/models/address.rb +5 -1
  96. data/spec/orm/models/address_with_timestamp.rb +12 -0
  97. data/spec/orm/models/car.rb +5 -0
  98. data/spec/orm/models/person.rb +13 -1
  99. data/spec/orm/models/person_with_timestamp.rb +4 -2
  100. data/spec/orm/models/test_class.rb +1 -0
  101. data/spec/orm/persistence/operations/atomic_operation_spec.rb +58 -0
  102. data/spec/orm/persistence/operations/destroy_spec.rb +22 -0
  103. data/spec/orm/persistence/operations/embedded/destroy_spec.rb +71 -0
  104. data/spec/orm/persistence/operations/embedded/insert_spec.rb +59 -0
  105. data/spec/orm/persistence/operations/embedded/operation_helpers_spec.rb +92 -0
  106. data/spec/orm/persistence/operations/embedded/reload_spec.rb +67 -0
  107. data/spec/orm/persistence/operations/embedded/update_spec.rb +60 -0
  108. data/spec/orm/persistence/operations/insert_spec.rb +31 -0
  109. data/spec/orm/persistence/operations/reload_spec.rb +48 -0
  110. data/spec/orm/persistence/operations/suppress_spec.rb +17 -0
  111. data/spec/orm/persistence/operations/table_operation_helpers_spec.rb +98 -0
  112. data/spec/orm/persistence/operations/update_spec.rb +25 -0
  113. data/spec/orm/persistence/operations_spec.rb +58 -0
  114. data/spec/orm/relations/interface_spec.rb +188 -0
  115. data/spec/orm/relations/metadata_spec.rb +92 -15
  116. data/spec/orm/relations/proxy/embedded_in_polymorphic_spec.rb +37 -0
  117. data/spec/orm/relations/proxy/embedded_in_spec.rb +66 -0
  118. data/spec/orm/relations/proxy/embeds_many_spec.rb +651 -0
  119. data/spec/orm/relations/proxy/references_many_spec.rb +466 -2
  120. data/spec/orm/schema/column_family_spec.rb +21 -0
  121. data/spec/orm/schema/embedded_interface_spec.rb +181 -0
  122. data/spec/orm/schema/field_spec.rb +7 -0
  123. data/spec/orm/schema/table_interface_spec.rb +31 -1
  124. data/spec/shared/orm/id_factories.rb +44 -0
  125. data/spec/shared/orm/model_with_timestamps.rb +132 -0
  126. data/spec/shared/orm/persistence/a_persistence_embedded_operation_class.rb +3 -0
  127. data/spec/shared/orm/persistence/a_persistence_operation_class.rb +11 -0
  128. data/spec/shared/orm/persistence/a_persistence_table_operation_class.rb +11 -0
  129. data/spec/shared/orm/relations/proxy.rb +9 -2
  130. data/spec/spec_helper.rb +9 -0
  131. data/spec/support/mock_massive_record_connection.rb +2 -1
  132. metadata +106 -21
  133. data/spec/orm/cases/column_spec.rb +0 -49
  134. data/spec/orm/cases/id_factory_spec.rb +0 -92
  135. data/spec/orm/schema/column_interface_spec.rb +0 -136
@@ -5,9 +5,9 @@
5
5
  #
6
6
 
7
7
  module Apache
8
- module Hadoop
9
- module Hbase
10
- module Thrift
8
+ module Hadoop
9
+ module Hbase
10
+ module Thrift
11
11
  end
12
12
  end
13
13
  end
@@ -8,218 +8,218 @@ module Apache
8
8
  module Hadoop
9
9
  module Hbase
10
10
  module Thrift
11
- # TCell - Used to transport a cell value (byte[]) and the timestamp it was
12
- # stored with together as a result for get and getRow methods. This promotes
13
- # the timestamp of a cell to a first-class value, making it easy to take
14
- # note of temporal data. Cell is used all the way from HStore up to HTable.
15
- class TCell
16
- include ::Thrift::Struct, ::Thrift::Struct_Union
17
- VALUE = 1
18
- TIMESTAMP = 2
19
-
20
- FIELDS = {
21
- VALUE => {:type => ::Thrift::Types::STRING, :name => 'value', :binary => true},
22
- TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'}
23
- }
24
-
25
- def struct_fields; FIELDS; end
26
-
27
- def validate
28
- end
29
-
30
- ::Thrift::Struct.generate_accessors self
31
- end
32
-
33
- # An HColumnDescriptor contains information about a column family
34
- # such as the number of versions, compression settings, etc. It is
35
- # used as input when creating a table or adding a column.
36
- class ColumnDescriptor
37
- include ::Thrift::Struct, ::Thrift::Struct_Union
38
- NAME = 1
39
- MAXVERSIONS = 2
40
- COMPRESSION = 3
41
- INMEMORY = 4
42
- BLOOMFILTERTYPE = 5
43
- BLOOMFILTERVECTORSIZE = 6
44
- BLOOMFILTERNBHASHES = 7
45
- BLOCKCACHEENABLED = 8
46
- TIMETOLIVE = 9
47
-
48
- FIELDS = {
49
- NAME => {:type => ::Thrift::Types::STRING, :name => 'name', :binary => true},
50
- MAXVERSIONS => {:type => ::Thrift::Types::I32, :name => 'maxVersions', :default => 3},
51
- COMPRESSION => {:type => ::Thrift::Types::STRING, :name => 'compression', :default => %q"NONE"},
52
- INMEMORY => {:type => ::Thrift::Types::BOOL, :name => 'inMemory', :default => false},
53
- BLOOMFILTERTYPE => {:type => ::Thrift::Types::STRING, :name => 'bloomFilterType', :default => %q"NONE"},
54
- BLOOMFILTERVECTORSIZE => {:type => ::Thrift::Types::I32, :name => 'bloomFilterVectorSize', :default => 0},
55
- BLOOMFILTERNBHASHES => {:type => ::Thrift::Types::I32, :name => 'bloomFilterNbHashes', :default => 0},
56
- BLOCKCACHEENABLED => {:type => ::Thrift::Types::BOOL, :name => 'blockCacheEnabled', :default => false},
57
- TIMETOLIVE => {:type => ::Thrift::Types::I32, :name => 'timeToLive', :default => -1}
58
- }
59
-
60
- def struct_fields; FIELDS; end
61
-
62
- def validate
63
- end
64
-
65
- ::Thrift::Struct.generate_accessors self
66
- end
67
-
68
- # A TRegionInfo contains information about an HTable region.
69
- class TRegionInfo
70
- include ::Thrift::Struct, ::Thrift::Struct_Union
71
- STARTKEY = 1
72
- ENDKEY = 2
73
- ID = 3
74
- NAME = 4
75
- VERSION = 5
76
-
77
- FIELDS = {
78
- STARTKEY => {:type => ::Thrift::Types::STRING, :name => 'startKey', :binary => true},
79
- ENDKEY => {:type => ::Thrift::Types::STRING, :name => 'endKey', :binary => true},
80
- ID => {:type => ::Thrift::Types::I64, :name => 'id'},
81
- NAME => {:type => ::Thrift::Types::STRING, :name => 'name', :binary => true},
82
- VERSION => {:type => ::Thrift::Types::BYTE, :name => 'version'}
83
- }
84
-
85
- def struct_fields; FIELDS; end
86
-
87
- def validate
88
- end
89
-
90
- ::Thrift::Struct.generate_accessors self
91
- end
92
-
93
- # A Mutation object is used to either update or delete a column-value.
94
- class Mutation
95
- include ::Thrift::Struct, ::Thrift::Struct_Union
96
- ISDELETE = 1
97
- COLUMN = 2
98
- VALUE = 3
99
-
100
- FIELDS = {
101
- ISDELETE => {:type => ::Thrift::Types::BOOL, :name => 'isDelete', :default => false},
102
- COLUMN => {:type => ::Thrift::Types::STRING, :name => 'column', :binary => true},
103
- VALUE => {:type => ::Thrift::Types::STRING, :name => 'value', :binary => true}
104
- }
105
-
106
- def struct_fields; FIELDS; end
107
-
108
- def validate
109
- end
110
-
111
- ::Thrift::Struct.generate_accessors self
112
- end
113
-
114
- # A BatchMutation object is used to apply a number of Mutations to a single row.
115
- class BatchMutation
116
- include ::Thrift::Struct, ::Thrift::Struct_Union
117
- ROW = 1
118
- MUTATIONS = 2
119
-
120
- FIELDS = {
121
- ROW => {:type => ::Thrift::Types::STRING, :name => 'row', :binary => true},
122
- MUTATIONS => {:type => ::Thrift::Types::LIST, :name => 'mutations', :element => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::Mutation}}
123
- }
11
+ # TCell - Used to transport a cell value (byte[]) and the timestamp it was
12
+ # stored with together as a result for get and getRow methods. This promotes
13
+ # the timestamp of a cell to a first-class value, making it easy to take
14
+ # note of temporal data. Cell is used all the way from HStore up to HTable.
15
+ class TCell
16
+ include ::Thrift::Struct, ::Thrift::Struct_Union
17
+ VALUE = 1
18
+ TIMESTAMP = 2
19
+
20
+ FIELDS = {
21
+ VALUE => {:type => ::Thrift::Types::STRING, :name => 'value', :binary => true},
22
+ TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'}
23
+ }
24
+
25
+ def struct_fields; FIELDS; end
26
+
27
+ def validate
28
+ end
29
+
30
+ ::Thrift::Struct.generate_accessors self
31
+ end
32
+
33
+ # An HColumnDescriptor contains information about a column family
34
+ # such as the number of versions, compression settings, etc. It is
35
+ # used as input when creating a table or adding a column.
36
+ class ColumnDescriptor
37
+ include ::Thrift::Struct, ::Thrift::Struct_Union
38
+ NAME = 1
39
+ MAXVERSIONS = 2
40
+ COMPRESSION = 3
41
+ INMEMORY = 4
42
+ BLOOMFILTERTYPE = 5
43
+ BLOOMFILTERVECTORSIZE = 6
44
+ BLOOMFILTERNBHASHES = 7
45
+ BLOCKCACHEENABLED = 8
46
+ TIMETOLIVE = 9
47
+
48
+ FIELDS = {
49
+ NAME => {:type => ::Thrift::Types::STRING, :name => 'name', :binary => true},
50
+ MAXVERSIONS => {:type => ::Thrift::Types::I32, :name => 'maxVersions', :default => 3},
51
+ COMPRESSION => {:type => ::Thrift::Types::STRING, :name => 'compression', :default => %q"NONE"},
52
+ INMEMORY => {:type => ::Thrift::Types::BOOL, :name => 'inMemory', :default => false},
53
+ BLOOMFILTERTYPE => {:type => ::Thrift::Types::STRING, :name => 'bloomFilterType', :default => %q"NONE"},
54
+ BLOOMFILTERVECTORSIZE => {:type => ::Thrift::Types::I32, :name => 'bloomFilterVectorSize', :default => 0},
55
+ BLOOMFILTERNBHASHES => {:type => ::Thrift::Types::I32, :name => 'bloomFilterNbHashes', :default => 0},
56
+ BLOCKCACHEENABLED => {:type => ::Thrift::Types::BOOL, :name => 'blockCacheEnabled', :default => false},
57
+ TIMETOLIVE => {:type => ::Thrift::Types::I32, :name => 'timeToLive', :default => -1}
58
+ }
59
+
60
+ def struct_fields; FIELDS; end
61
+
62
+ def validate
63
+ end
64
+
65
+ ::Thrift::Struct.generate_accessors self
66
+ end
67
+
68
+ # A TRegionInfo contains information about an HTable region.
69
+ class TRegionInfo
70
+ include ::Thrift::Struct, ::Thrift::Struct_Union
71
+ STARTKEY = 1
72
+ ENDKEY = 2
73
+ ID = 3
74
+ NAME = 4
75
+ VERSION = 5
76
+
77
+ FIELDS = {
78
+ STARTKEY => {:type => ::Thrift::Types::STRING, :name => 'startKey', :binary => true},
79
+ ENDKEY => {:type => ::Thrift::Types::STRING, :name => 'endKey', :binary => true},
80
+ ID => {:type => ::Thrift::Types::I64, :name => 'id'},
81
+ NAME => {:type => ::Thrift::Types::STRING, :name => 'name', :binary => true},
82
+ VERSION => {:type => ::Thrift::Types::BYTE, :name => 'version'}
83
+ }
84
+
85
+ def struct_fields; FIELDS; end
86
+
87
+ def validate
88
+ end
89
+
90
+ ::Thrift::Struct.generate_accessors self
91
+ end
92
+
93
+ # A Mutation object is used to either update or delete a column-value.
94
+ class Mutation
95
+ include ::Thrift::Struct, ::Thrift::Struct_Union
96
+ ISDELETE = 1
97
+ COLUMN = 2
98
+ VALUE = 3
99
+
100
+ FIELDS = {
101
+ ISDELETE => {:type => ::Thrift::Types::BOOL, :name => 'isDelete', :default => false},
102
+ COLUMN => {:type => ::Thrift::Types::STRING, :name => 'column', :binary => true},
103
+ VALUE => {:type => ::Thrift::Types::STRING, :name => 'value', :binary => true}
104
+ }
105
+
106
+ def struct_fields; FIELDS; end
107
+
108
+ def validate
109
+ end
110
+
111
+ ::Thrift::Struct.generate_accessors self
112
+ end
113
+
114
+ # A BatchMutation object is used to apply a number of Mutations to a single row.
115
+ class BatchMutation
116
+ include ::Thrift::Struct, ::Thrift::Struct_Union
117
+ ROW = 1
118
+ MUTATIONS = 2
119
+
120
+ FIELDS = {
121
+ ROW => {:type => ::Thrift::Types::STRING, :name => 'row', :binary => true},
122
+ MUTATIONS => {:type => ::Thrift::Types::LIST, :name => 'mutations', :element => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::Mutation}}
123
+ }
124
+
125
+ def struct_fields; FIELDS; end
126
+
127
+ def validate
128
+ end
129
+
130
+ ::Thrift::Struct.generate_accessors self
131
+ end
132
+
133
+ # Holds row name and then a map of columns to cells.
134
+ class TRowResult
135
+ include ::Thrift::Struct, ::Thrift::Struct_Union
136
+ ROW = 1
137
+ COLUMNS = 2
138
+
139
+ FIELDS = {
140
+ ROW => {:type => ::Thrift::Types::STRING, :name => 'row', :binary => true},
141
+ COLUMNS => {:type => ::Thrift::Types::MAP, :name => 'columns', :key => {:type => ::Thrift::Types::STRING, :binary => true}, :value => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::TCell}}
142
+ }
143
+
144
+ def struct_fields; FIELDS; end
145
+
146
+ def validate
147
+ end
148
+
149
+ ::Thrift::Struct.generate_accessors self
150
+ end
151
+
152
+ # An IOError exception signals that an error occurred communicating
153
+ # to the Hbase master or an Hbase region server. Also used to return
154
+ # more general Hbase error conditions.
155
+ class IOError < ::Thrift::Exception
156
+ include ::Thrift::Struct, ::Thrift::Struct_Union
157
+ def initialize(message=nil)
158
+ super()
159
+ self.message = message
160
+ end
124
161
 
125
- def struct_fields; FIELDS; end
162
+ MESSAGE = 1
126
163
 
127
- def validate
128
- end
129
-
130
- ::Thrift::Struct.generate_accessors self
131
- end
132
-
133
- # Holds row name and then a map of columns to cells.
134
- class TRowResult
135
- include ::Thrift::Struct, ::Thrift::Struct_Union
136
- ROW = 1
137
- COLUMNS = 2
138
-
139
- FIELDS = {
140
- ROW => {:type => ::Thrift::Types::STRING, :name => 'row', :binary => true},
141
- COLUMNS => {:type => ::Thrift::Types::MAP, :name => 'columns', :key => {:type => ::Thrift::Types::STRING, :binary => true}, :value => {:type => ::Thrift::Types::STRUCT, :class => Apache::Hadoop::Hbase::Thrift::TCell}}
142
- }
143
-
144
- def struct_fields; FIELDS; end
145
-
146
- def validate
147
- end
148
-
149
- ::Thrift::Struct.generate_accessors self
150
- end
164
+ FIELDS = {
165
+ MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
166
+ }
151
167
 
152
- # An IOError exception signals that an error occurred communicating
153
- # to the Hbase master or an Hbase region server. Also used to return
154
- # more general Hbase error conditions.
155
- class IOError < ::Thrift::Exception
156
- include ::Thrift::Struct, ::Thrift::Struct_Union
157
- def initialize(message=nil)
158
- super()
159
- self.message = message
160
- end
168
+ def struct_fields; FIELDS; end
161
169
 
162
- MESSAGE = 1
170
+ def validate
171
+ end
163
172
 
164
- FIELDS = {
165
- MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
166
- }
173
+ ::Thrift::Struct.generate_accessors self
174
+ end
167
175
 
168
- def struct_fields; FIELDS; end
176
+ # An IllegalArgument exception indicates an illegal or invalid
177
+ # argument was passed into a procedure.
178
+ class IllegalArgument < ::Thrift::Exception
179
+ include ::Thrift::Struct, ::Thrift::Struct_Union
180
+ def initialize(message=nil)
181
+ super()
182
+ self.message = message
183
+ end
169
184
 
170
- def validate
171
- end
185
+ MESSAGE = 1
172
186
 
173
- ::Thrift::Struct.generate_accessors self
174
- end
175
-
176
- # An IllegalArgument exception indicates an illegal or invalid
177
- # argument was passed into a procedure.
178
- class IllegalArgument < ::Thrift::Exception
179
- include ::Thrift::Struct, ::Thrift::Struct_Union
180
- def initialize(message=nil)
181
- super()
182
- self.message = message
183
- end
187
+ FIELDS = {
188
+ MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
189
+ }
184
190
 
185
- MESSAGE = 1
191
+ def struct_fields; FIELDS; end
186
192
 
187
- FIELDS = {
188
- MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
189
- }
193
+ def validate
194
+ end
190
195
 
191
- def struct_fields; FIELDS; end
196
+ ::Thrift::Struct.generate_accessors self
197
+ end
192
198
 
193
- def validate
194
- end
199
+ # An AlreadyExists exceptions signals that a table with the specified
200
+ # name already exists
201
+ class AlreadyExists < ::Thrift::Exception
202
+ include ::Thrift::Struct, ::Thrift::Struct_Union
203
+ def initialize(message=nil)
204
+ super()
205
+ self.message = message
206
+ end
195
207
 
196
- ::Thrift::Struct.generate_accessors self
197
- end
208
+ MESSAGE = 1
198
209
 
199
- # An AlreadyExists exceptions signals that a table with the specified
200
- # name already exists
201
- class AlreadyExists < ::Thrift::Exception
202
- include ::Thrift::Struct, ::Thrift::Struct_Union
203
- def initialize(message=nil)
204
- super()
205
- self.message = message
206
- end
210
+ FIELDS = {
211
+ MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
212
+ }
207
213
 
208
- MESSAGE = 1
214
+ def struct_fields; FIELDS; end
209
215
 
210
- FIELDS = {
211
- MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
212
- }
216
+ def validate
217
+ end
213
218
 
214
- def struct_fields; FIELDS; end
219
+ ::Thrift::Struct.generate_accessors self
220
+ end
215
221
 
216
- def validate
222
+ end
223
+ end
217
224
  end
218
-
219
- ::Thrift::Struct.generate_accessors self
220
225
  end
221
-
222
- end
223
- end
224
- end
225
- end
@@ -41,6 +41,36 @@ module MassiveRecord
41
41
  @columns.inject({"id" => id}) {|h, (column_name, cell)| h[column_name] = cell.value; h}
42
42
  end
43
43
 
44
+ # Returns values as a nested hash.
45
+ #
46
+ # {
47
+ # 'family' => {
48
+ # 'attr1' => 'value'
49
+ # 'attr2' => 'value'
50
+ # },
51
+ # ...
52
+ # }
53
+ #
54
+ # I think maybe that values should return this instead, as it is what the
55
+ # values= expects to receive.
56
+ def values_hash
57
+ Hash.new { |hash, key| hash[key] = {} }.tap do |hash|
58
+ @columns.each do |key, column|
59
+ column_family, name = key.split(':')
60
+ hash[column_family][name] = column.value
61
+ end
62
+ end
63
+ end
64
+
65
+ def values_raw_data_hash
66
+ Hash.new { |hash, key| hash[key] = {} }.tap do |hash|
67
+ @columns.each do |key, column|
68
+ column_family, name = key.split(':')
69
+ hash[column_family][name] = MassiveRecord::ORM::RawData.new_with_data_from column
70
+ end
71
+ end
72
+ end
73
+
44
74
  def values=(data)
45
75
  @values = {}
46
76
  update_columns(data)
@@ -86,6 +116,10 @@ module MassiveRecord
86
116
  def atomic_increment(column_name, by = 1)
87
117
  @table.client.atomicIncrement(@table.name, id.to_s, column_name, by)
88
118
  end
119
+
120
+ def atomic_decrement(column_name, by = 1)
121
+ atomic_increment(column_name, -by)
122
+ end
89
123
 
90
124
  def read_atomic_integer_value(column_name)
91
125
  atomic_increment(column_name, 0)
@@ -99,10 +133,7 @@ module MassiveRecord
99
133
  row.column_families = column_families
100
134
 
101
135
  result.columns.each do |name, value|
102
- row.columns[name] = MassiveRecord::Wrapper::Cell.new({
103
- :value => value.value,
104
- :created_at => Time.at(value.timestamp / 1000, (value.timestamp % 1000) * 1000)
105
- })
136
+ row.columns[name] = MassiveRecord::Wrapper::Cell.populate_from_tcell(value)
106
137
  end
107
138
 
108
139
  row