Created
March 3, 2010 23:26
-
-
Save perlDreamer/321187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub write { | |
my $self = shift; | |
$self->lastModified(time()); | |
my $db = $self->session->db; | |
my %data_by_table = (); | |
PROPERTY: foreach my $property_name ($self->meta->get_all_property_list) { | |
my $property = $self->meta->find_attribute_by_name($property_name); | |
my $tableName = $property->tableName; | |
my $value = $self->$property_name; | |
push @{ $data_by_table{$tableName}->{NAMES} }, $property_name; | |
push @{ $data_by_table{$tableName}->{VALUES} }, $value; | |
} | |
CLASS: foreach my $tableName (keys %data_by_table) { | |
my $table = $db->quoteIdentifier($tableName); | |
my @values = @{ $data_by_table{$tableName}->{VALUES} }; | |
my @columnNames = map { $db->quoteIdentifier($_).'=?' } @{ $data_by_table{$tableName}->{NAMES}}; | |
push @values, $self->getId, $self->revisionDate; | |
$db->write("update ".$table." set ".join(",",@columnNames)." where assetId=? and revisionDate=?",\@values); | |
} | |
# update the asset's size, which also purges the cache. | |
$self->setSize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment