blob: bb105d508873c7f17e758119e54aa6cfc26ba23f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
<?php
/**
* IDistributedDbConnection, TDistributedDbConnection inferface/class file.
*
* @author Yves Berkholz <godzilla80[at]gmx[dot]net>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2010 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Testing.Data.Distributed
*/
Prado::using('System.Data.TDbConnection');
Prado::using('System.Testing.Data.Analysis.TDbStatementAnalysis');
/**
* TDistributedDbConnection interface
*
* @author Yves Berkholz <godzilla80[at]gmx[dot]net>
* @version $Id$
* @package System.Testing.Data.Distributed
* @since 4.0
*/
interface IDistributedDbConnection /*extends IDbConnection*/
{
/**
* Gets the statement analyser of type given by
* {@link setStatementAnalyserClass StatementAnalyserClass }.
* @return IDbStatementAnalysis statement analyser.
*/
public function getStatementAnalyser();
/**
* The statement analyser class name to be created when {@link getStatementAnalyserClass}
* method is called. The {@link setStatementAnalyserClass StatementAnalyserClass}
* property must be set before calling {@link getStatementAnalyser} if you wish to
* create the connection using the given class name.
* @param string Statement analyser class name.
*/
public function setStatementAnalyserClass($value);
/**
* @param string Statement analyser class name to be created.
*/
public function getStatementAnalyserClass();
/**
* @return TDbConnectionServerRole
*/
public function getServerRole();
}
/**
* TDistributedDbConnection class
*
* TDistributedDbConnection represents a conditional base connection class to a database
*
* @author Yves Berkholz <godzilla80[at]gmx[dot]net>
* @version $Id$
* @package System.Testing.Data.Distributed
* @since 4.0
*/
abstract class TDistributedDbConnection extends TDbConnection implements IDistributedDbConnection
{
/**
* @var string
*/
private $_statementAnalyserClass = 'System.Testing.Data.Analysis.TDbStatementAnalysis';
/**
* @var IDbStatementAnalysis
*/
private $_statementAnalyser = null;
/**
* Gets the statement analyser of type given by
* {@link setStatementAnalyserClass StatementAnalyserClass }.
* @return IDbStatementAnalysis statement analyser.
*/
public function getStatementAnalyser()
{
if($this->_statementAnalyser === null)
{
$this->setActive(true);
$this->_statementAnalyser = Prado::createComponent($this->getStatementAnalyserClass());
if($this->getActive())
$this->_statementAnalyser->setDriverName($this->getDriverName());
}
return $this->_statementAnalyser;
}
/**
* The statement analyser class name to be created when {@link getStatementAnalyser}
* method is called. The {@link setStatementAnalyserClass StatementAnalyserClass}
* property must be set before calling {@link getStatementAnalyser} if you wish to
* create the connection using the given class name.
* @param string Statement analyser class name.
*/
public function setStatementAnalyserClass($value)
{
if($this->_statementAnalyser === null)
$this->_statementAnalyserClass = $value;
}
/**
* @param string Statement analyser class name to be created.
*/
public function getStatementAnalyserClass()
{
return $this->_statementAnalyserClass;
}
/**
* @param string The SQL statement that should be analysed
* @param TDbStatementClassification
*/
protected function getStatementClassification($statement='', $defaultClassification=null) {
return $this->getStatementAnalyser()->getClassificationAnalysis(new TDbStatementAnalysisParameter($statement, $defaultClassification));
}
}
/**
* TDistributedDbCommand
*
* @author Yves Berkholz <godzilla80[at]gmx[dot]net>
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Testing.Data.Distributed
* @since 4.0
*/
class TDistributedDbCommand extends TDbCommand
{
/**
* @var TDbStatementClassification
*/
private $_statementClassification;
/**
* Constructor.
* @param TDbConnection the database connection
* @param string the SQL statement to be executed
* @param TDbStatementClassification Defaults to 'UNKNOWN'
*/
public function __construct(TDbConnection $connection, $text, $classification=TDbStatementClassification::UNKNOWN)
{
$connection->setActive(true);
parent::__construct($connection, $text);
$this->_statementClassification = $classification;
Prado::log($classification . ', ' . $connection->getServerRole() . ': ' . preg_replace('/[\s]+/', ' ', $text), TLogger::DEBUG, 'System.Testing.Data.Distributed.TDistributedDbCommand');
}
/**
* @return TDbStatementClassification
*/
public function getStatementClassification()
{
return $this->_statementClassification;
}
}
/**
* TDbConnectionServerRole
*
* @author Yves Berkholz <godzilla80[at]gmx[dot]net>
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Testing.Data.Distributed
* @since 4.0
*/
class TDbConnectionServerRole extends TEnumerable
{
/**
* Master Server (Read/Write)
*/
const Master = 'Master';
/**
* Slave Server (Read only)
*/
const Slave = 'Slave';
/**
* Mirror Server (Read/Write) for further use
*/
//const Mirror = 'Mirror';
}
?>
|