}
method _key_cache_get_raw ($raw) {
- my $id = $self->_raw_to_id($raw);
- exists $self->_key_cache->{$id}
- ? ($self->_key_cache->{$id})
- : ()
+ $self->_key_cache_get_id($self->_raw_to_id($raw))
}
method _key_cache_get_object ($obj) {
- $self->_key_cache_get_raw($self->_deflate($obj))
+ $self->_key_cache_get_id($self->_object_to_id($obj))
}
-## loading data
+method _key_cache_get_object_spec ($spec) {
+ # see _object_spec_to_id for doc of what the difference is
+ $self->_key_cache_get_id($self->_object_spec_to_id($spec))
+}
-method _new_raw_stream {
- $self->_store->new_select_command([])->execute
+method _key_cache_get_id ($id) {
+ exists $self->_key_cache->{$id}
+ ? ($self->_key_cache->{$id})
+ : ()
}
## thunking between the store representation and the set representation
# _deflate is final repr -> raw data
# _merge takes final repr + raw data and updates the repr
# (this is used for pk-generated values and later lazy loading)
+#
+# _deflate_spec is attributes of final repr -> raw data
method _inflate ($raw) {
bless($raw, $self->_class) if $self->_has_class;
$obj
}
+method _deflate_spec ($spec) {
+ $spec
+}
+
## methods to get ids
method _raw_to_id ($raw) {
$self->_raw_to_id($self->_deflate($obj))
}
+method _object_spec_to_id ($spec) {
+ # intentionally C&P from _raw_to - this is not the same thing. If a column
+ # were mapped to an attribute of a different name, the raw would have the
+ # column name as a key but an object spec would have the attribute name
+ join ';', map $spec->{$_}, @{$self->_set_over}
+}
+
## array-ish operations - i.e. get all members
+method _new_raw_stream {
+ $self->_store->new_select_command([])->execute
+}
+
method flatten {
@{$self->_member_cache};
}
Data::Perl::Stream::Array->new(array => $self->_member_cache);
}
+## load single row
+
+method get ($spec) {
+ if (my ($got) = $self->_key_cache_get_object_spec($spec)) {
+ return $got
+ }
+ if (my ($raw) = $self->_get_from_store($self->_deflate_spec($spec))) {
+ return $self->_add_to_key_cache($self->_inflate($raw))
+ }
+ return undef # we aren't handling cache misses here yet
+}
+
+method _get_from_store ($raw) {
+ $self->_store->new_select_single_command($raw)->execute
+}
+
## add to set
method add ($new) {