/[suikacvs]/webroot/swe/lib/SWE/Object/Node.pm
Suika

Contents of /webroot/swe/lib/SWE/Object/Node.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Mon Sep 21 09:10:40 2009 UTC (15 years, 7 months ago) by wakaba
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +5 -4 lines
++ swe/lib/SWE/DB/ChangeLog	21 Sep 2009 09:05:45 -0000
2009-09-21  Wakaba  <wakaba@suika.fam.cx>

	* Lock.pm (check_lockability): Don't allow the same level of lock
	type being locked twice to avoid deadlocks caused by same level of
	locks.

++ swe/lib/SWE/Object/ChangeLog	21 Sep 2009 09:10:06 -0000
	* Document.pm (repo, prop_untainted, untainted_prop, save_prop,
	locked): New method.  Introduced the concept of "tainted" such
	that we can access to the property in the locked code fragment
	without being afraid to update the property using old values.
	(get_or_create_graph_node): Updated to utilize |prop| family of
	method with locks.

	* Graph.pm (repo, lock, unlock): New methods.
	(add_nodes, create_node, schelling_update): Locks the database
	before the modifications.

	* Repository.pm (graph, get_document_by_id): New methods.

	* Node.pm (repo): New method.

2009-09-21  Wakaba  <wakaba@suika.fam.cx>

++ swe/lib/suikawiki/ChangeLog	21 Sep 2009 09:10:27 -0000
	* main.pl: Made the graph node view to lock the database.

2009-09-21  Wakaba  <wakaba@suika.fam.cx>

1 package SWE::Object::Node;
2 use strict;
3 use warnings;
4
5 sub new ($%) {
6 my $class = shift;
7 my $self = bless {@_}, $class;
8
9 return $self;
10 } # new
11
12 sub db ($) { $_[0]->{db} }
13
14 sub repo ($) { $_[0]->{repo} }
15
16 sub create ($%) {
17 my ($self, %opt) = @_;
18 $self->{id} = $opt{id};
19 } # create
20
21 sub load ($%) {
22 my ($self, %opt) = @_;
23 $self->{id} = $opt{id};
24 } # load
25
26 sub id ($) { $_[0]->{id} }
27
28 sub prop ($) {
29 my $self = shift;
30
31 ## TODO: lock
32
33 return $self->{prop} ||= do {
34 my $graph_prop_db = $self->db->graph_prop;
35 $graph_prop_db->get_data ($self->id) || {};
36 };
37 } # prop
38
39 sub save_prop ($) {
40 my $self = shift;
41
42 return unless defined $self->{prop};
43
44 ## TODO: lock
45
46 my $graph_prop_db = $self->db->graph_prop;
47 $graph_prop_db->set_data ($self->id => $self->prop);
48 } # save_prop
49
50 sub neighbor_ids ($) {
51 my $self = shift;
52
53 return $self->prop->{neighbors} || {};
54 } # neighbor_ids
55
56 sub document_id ($) {
57 my $self = shift;
58
59 return [keys %{$self->prop->{ids} or {}}]->[0];
60 } # document_id
61
62 sub neighbor_documents ($) {
63 my $self = shift;
64
65 my $db = $self->db;
66 my $doc_id = $self->document_id;
67
68 my $graph = $self->repo->graph;
69
70 require SWE::Object::Document;
71 return [map {
72 SWE::Object::Document->new (db => $db, id => $_)
73 } grep { $_ } map {
74 $graph->get_node_by_id ($_)->document_id
75 } keys %{$self->neighbor_ids}];
76 } # neighbor_documents
77
78 1;

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24