annotate Lib/IMPL/SQL/Schema/Processor.pm @ 306:d4caf951260d

missing files
author cin
date Wed, 17 Apr 2013 19:33:07 +0400
parents 56364d0c4b4f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
271
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
1 package IMPL::SQL::Schema::Processor;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
2 use strict;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
3
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
4 use IMPL::Const qw(:prop);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
5 use IMPL::declare {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
6 require => {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
7 Exception => 'IMPL::Exception',
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
8 ArgException => '-IMPL::InvalidArgumentException'
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
9 },
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
10 base => [
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
11 'IMPL::Object' => undef
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
12 ],
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
13 props => [
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
14 dbSchema => PROP_RO,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
15 updateBatch => PROP_RO,
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
16 pendingOperations => PROP_RO
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
17 ]
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
18 };
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
19
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
20 sub CTOR {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
21 my ($this,$schema) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
22
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
23 $this->dbSchema($schema)
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
24 or die ArgException->new(schema => 'A DB schema is required');
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
25
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
26 $this->updateBatch([]);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
27 $this->pendingOperations([]);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
28 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
29
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
30 sub AddUpdateBatch {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
31 my $this = shift;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
32
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
33 push @{$this->updateBatch}, @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
34 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
35
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
36 sub AddPendingOperations {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
37 my $this = shift;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
38
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
39 push @{$this->pendingOperations}, @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
40 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
41
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
42 sub ProcessBatch {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
43 my ($this,$batch) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
44
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
45 $this->pendingOperations($batch);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
46 my $i = 1;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
47 while(@{$this->pendingOperations}) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
48 $batch = $this->pendingOperations;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
49 $this->pendingOperations([]);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
50
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
51 my $noChanges = 1;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
52
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
53 foreach my $op (@$batch) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
54 if ($this->CanApplyOperation($op,$i)) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
55 $noChanges = 0;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
56
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
57 $this->ApplyOperation($op,$i);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
58 } else {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
59 $this->AddPendingOperations($op);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
60 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
61 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
62
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
63 if ($noChanges && @{$this->pendingOperations}) {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
64 die Exception->new("No changes were made (iteration $i), but some operations are pending",@{$this->pendingOperations});
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
65 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
66
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
67 $i++;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
68 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
69 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
70
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
71 sub CanApplyOperation {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
72 my ($this,$op) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
73
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
74 return $op->CanApply($this->dbSchema);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
75 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
76
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
77 sub ApplyOperation {
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
78 my ($this,$op) = @_;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
79
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
80 $op->Apply($this->dbSchema);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
81 $this->AddUpdateBatch($op);
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
82 }
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
83
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
84 1;
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
85
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
86 __END__
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
87
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
88 =pod
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
89
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
90 =head1 NAME
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
91
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
92 =head1 SYNOPSIS
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
93
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
94 =head1 DESCRIPTION
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
95
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
96 Позволяет применит набор примитивных операций C<IMPL::SQL::Schema::Traits> к
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
97 схеме.
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
98
56364d0c4b4f +IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
diff changeset
99 =cut