Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete,
4
 * TSqlMapSelect and TSqlMapSelectKey classes file.
5
 *
6
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
7
 * @link http://www.pradosoft.com/
8
 * @copyright Copyright &copy; 2005-2008 PradoSoft
9
 * @license http://www.pradosoft.com/license/
10
 * @version $Id: TSqlMapStatement.php 2541 2008-10-21 15:05:13Z qiang.xue $
11
 * @package System.Data.SqlMap.Configuration
12
 */
13
 
14
/**
15
 * TSqlMapStatement class corresponds to <statement> element.
16
 *
17
 * Mapped Statements can hold any SQL statement and can use Parameter Maps
18
 * and Result Maps for input and output.
19
 *
20
 * The <statement> element is a general "catch all" element that can be used
21
 * for any type of SQL statement. Generally it is a good idea to use one of the
22
 * more specific statement-type elements. The more specific elements provided
23
 * better error-checking and even more functionality. (For example, the insert
24
 * statement can return a database-generated key.)
25
 *
26
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
27
 * @version $Id: TSqlMapStatement.php 2541 2008-10-21 15:05:13Z qiang.xue $
28
 * @package System.Data.SqlMap.Configuration
29
 * @since 3.1
30
 */
31
class TSqlMapStatement extends TComponent
32
{
33
	private $_parameterMapName;
34
	private $_parameterMap;
35
	private $_parameterClassName;
36
	private $_resultMapName;
37
	private $_resultMap;
38
	private $_resultClassName;
39
	private $_cacheModelName;
40
	private $_SQL;
41
	private $_listClass;
42
	private $_typeHandler;
43
	private $_extendStatement;
44
	private $_cache;
45
	private $_ID;
46
 
47
	/**
48
	 * @return string name for this statement, unique to each sql map manager.
49
	 */
50
	public function getID()
51
	{
52
		return $this->_ID;
53
	}
54
 
55
	/**
56
	 * @param string name for this statement, which must be unique for each sql map manager.
57
	 */
58
	public function setID($value)
59
	{
60
		$this->_ID=$value;
61
	}
62
 
63
	/**
64
	 * @return string name of a parameter map.
65
	 */
66
	public function getParameterMap()
67
	{
68
		return $this->_parameterMapName;
69
	}
70
 
71
	/**
72
	 * A Parameter Map defines an ordered list of values that match up with
73
	 * the "?" placeholders of a standard, parameterized query statement.
74
	 * @param string parameter map name.
75
	 */
76
	public function setParameterMap($value)
77
	{
78
		$this->_parameterMapName = $value;
79
	}
80
 
81
	/**
82
	 * @return string parameter class name.
83
	 */
84
	public function getParameterClass()
85
	{
86
		return $this->_parameterClassName;
87
	}
88
 
89
	/**
90
	 * If a {@link ParameterMap setParameterMap()} property is not specified,
91
	 * you may specify a ParameterClass instead and use inline parameters.
92
	 * The value of the parameterClass attribute can be any existing PHP class name.
93
	 * @param string parameter class name.
94
	 */
95
	public function setParameterClass($value)
96
	{
97
		$this->_parameterClassName = $value;
98
	}
99
 
100
	/**
101
	 * @return string result map name.
102
	 */
103
	public function getResultMap()
104
	{
105
		return $this->_resultMapName;
106
	}
107
 
108
	/**
109
	 * A Result Map lets you control how data is extracted from the result of a
110
	 * query, and how the columns are mapped to object properties.
111
	 * @param string result map name.
112
	 */
113
	public function setResultMap($value)
114
	{
115
		$this->_resultMapName = $value;
116
	}
117
 
118
	/**
119
	 * @return string result class name.
120
	 */
121
	public function getResultClass()
122
	{
123
		return $this->_resultClassName;
124
	}
125
 
126
	/**
127
	 * If a {@link ResultMap setResultMap()} is not specified, you may specify a
128
	 * ResultClass instead. The value of the ResultClass property can be the
129
	 * name of a PHP class or primitives like integer, string, or array. The
130
	 * class specified will be automatically mapped to the columns in the
131
	 * result, based on the result metadata.
132
	 * @param string result class name.
133
	 */
134
	public function setResultClass($value)
135
	{
136
		$this->_resultClassName = $value;
137
	}
138
 
139
	/**
140
	 * @return string cache mode name.
141
	 */
142
	public function getCacheModel()
143
	{
144
		return $this->_cacheModelName;
145
	}
146
 
147
	/**
148
	 * @param string cache mode name.
149
	 */
150
	public function setCacheModel($value)
151
	{
152
		$this->_cacheModelName = $value;
153
	}
154
 
155
	/**
156
	 * @return TSqlMapCacheModel cache implementation instance for this statement.
157
	 */
158
	public function getCache()
159
	{
160
		return $this->_cache;
161
	}
162
 
163
	/**
164
	 * @param TSqlMapCacheModel cache implementation instance for this statement.
165
	 */
166
	public function setCache($value)
167
	{
168
		$this->_cache = $value;
169
	}
170
 
171
	/**
172
	 * @return TStaticSql sql text container.
173
	 */
174
	public function getSqlText()
175
	{
176
		return $this->_SQL;
177
	}
178
 
179
	/**
180
	 * @param TStaticSql sql text container.
181
	 */
182
	public function setSqlText($value)
183
	{
184
		$this->_SQL = $value;
185
	}
186
 
187
	/**
188
	 * @return string name of a PHP class that implements ArrayAccess.
189
	 */
190
	public function getListClass()
191
	{
192
		return $this->_listClass;
193
	}
194
 
195
	/**
196
	 * An ArrayAccess class can be specified to handle the type of objects in the collection.
197
	 * @param string name of a PHP class that implements ArrayAccess.
198
	 */
199
	public function setListClass($value)
200
	{
201
		$this->_listClass = $value;
202
	}
203
 
204
	/**
205
	 * @return string another statement element name.
206
	 */
207
	public function getExtends()
208
	{
209
		return $this->_extendStatement;
210
	}
211
 
212
	/**
213
	 * @param string name of another statement element to extend.
214
	 */
215
	public function setExtends($value)
216
	{
217
		$this->_extendStatement = $value;
218
	}
219
 
220
	/**
221
	 * @return TResultMap the result map corresponding to the
222
	 * {@link ResultMap getResultMap()} property.
223
	 */
224
	public function resultMap()
225
	{
226
		return $this->_resultMap;
227
	}
228
 
229
	/**
230
	 * @return TParameterMap the parameter map corresponding to the
231
	 * {@link ParameterMap getParameterMap()} property.
232
	 */
233
	public function parameterMap()
234
	{
235
		return $this->_parameterMap;
236
	}
237
 
238
	/**
239
	 * @param TInlineParameterMap parameter extracted from the sql text.
240
	 */
241
	public function setInlineParameterMap($map)
242
	{
243
		$this->_parameterMap = $map;
244
	}
245
 
246
	/**
247
	 * @param TSqlMapManager initialize the statement, sets the result and parameter maps.
248
	 */
249
	public function initialize($manager)
250
	{
251
		if(strlen($this->_resultMapName) > 0)
252
			$this->_resultMap = $manager->getResultMap($this->_resultMapName);
253
		if(strlen($this->_parameterMapName) > 0)
254
			$this->_parameterMap = $manager->getParameterMap($this->_parameterMapName);
255
	}
256
 
257
	/**
258
	 * @param TSqlMapTypeHandlerRegistry type handler registry
259
	 * @return ArrayAccess new instance of list class.
260
	 */
261
	public function createInstanceOfListClass($registry)
262
	{
263
		if(strlen($type = $this->getListClass()) > 0)
264
			return $this->createInstanceOf($registry,$type);
265
		return array();
266
	}
267
 
268
	/**
269
	 * Create a new instance of a given type.
270
	 * @param TSqlMapTypeHandlerRegistry type handler registry
271
	 * @param string result class name.
272
	 * @param array result data.
273
	 * @return mixed result object.
274
	 */
275
	protected function createInstanceOf($registry,$type,$row=null)
276
	{
277
		$handler = $registry->getTypeHandler($type);
278
		if(!is_null($handler))
279
			return $handler->createNewInstance($row);
280
		else
281
			return $registry->createInstanceOf($type);
282
	}
283
 
284
	/**
285
	 * Create a new instance of result class.
286
	 * @param TSqlMapTypeHandlerRegistry type handler registry
287
	 * @param array result data.
288
	 * @return mixed result object.
289
	 */
290
	public function createInstanceOfResultClass($registry,$row)
291
	{
292
		if(strlen($type= $this->getResultClass()) > 0)
293
			return $this->createInstanceOf($registry,$type,$row);
294
	}
295
}
296
 
297
/**
298
 * TSqlMapSelect class file.
299
 *
300
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
301
 * @version $Id: TSqlMapStatement.php 2541 2008-10-21 15:05:13Z qiang.xue $
302
 * @package System.Data.SqlMap.Statements
303
 * @since 3.1
304
 */
305
class TSqlMapSelect extends TSqlMapStatement
306
{
307
	private $_generate;
308
 
309
	public function getGenerate(){ return $this->_generate; }
310
	public function setGenerate($value){ $this->_generate = $value; }
311
}
312
 
313
/**
314
 * TSqlMapInsert class corresponds to the <insert> element.
315
 *
316
 * The <insert> element allows <selectKey> child elements that can be used
317
 * to generate a key to be used for the insert command.
318
 *
319
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
320
 * @version $Id: TSqlMapStatement.php 2541 2008-10-21 15:05:13Z qiang.xue $
321
 * @package System.Data.SqlMap.Configuration
322
 * @since 3.1
323
 */
324
class TSqlMapInsert extends TSqlMapStatement
325
{
326
	private $_selectKey=null;
327
 
328
	/**
329
	 * @return TSqlMapSelectKey select key element.
330
	 */
331
	public function getSelectKey()
332
	{
333
		return $this->_selectKey;
334
	}
335
 
336
	/**
337
	 * @param TSqlMapSelectKey select key.
338
	 */
339
	public function setSelectKey($value)
340
	{
341
		$this->_selectKey = $value;
342
	}
343
}
344
 
345
/**
346
 * TSqlMapUpdate class corresponds to <update> element.
347
 *
348
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
349
 * @version $Id: TSqlMapStatement.php 2541 2008-10-21 15:05:13Z qiang.xue $
350
 * @package System.Data.SqlMap.Configuration
351
 * @since 3.1
352
 */
353
class TSqlMapUpdate extends TSqlMapStatement
354
{
355
}
356
 
357
/**
358
 * TSqlMapDelete class corresponds to the <delete> element.
359
 *
360
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
361
 * @version $Id: TSqlMapStatement.php 2541 2008-10-21 15:05:13Z qiang.xue $
362
 * @package System.Data.SqlMap.Configuration
363
 * @since 3.1
364
 */
365
class TSqlMapDelete extends TSqlMapUpdate
366
{
367
}
368
 
369
/**
370
 * TSqlMapSelect corresponds to the <selectKey> element.
371
 *
372
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
373
 * @version $Id: TSqlMapStatement.php 2541 2008-10-21 15:05:13Z qiang.xue $
374
 * @package System.Data.SqlMap.Configuration
375
 * @since 3.1
376
 */
377
class TSqlMapSelectKey extends TSqlMapStatement
378
{
379
	private $_type = 'post';
380
	private $_property;
381
 
382
	/**
383
	 * @return string select generated key type, 'post' or 'pre'.
384
	 */
385
	public function getType()
386
	{
387
		return $this->_type;
388
	}
389
 
390
	/**
391
	 * @param string select generated key type, 'post' or 'pre'.
392
	 */
393
	public function setType($value)
394
	{
395
		$this->_type = strtolower($value) == 'post' ? 'post' : 'pre';
396
	}
397
 
398
	/**
399
	 * @return string property name for the generated key.
400
	 */
401
	public function getProperty()
402
	{
403
		return $this->_property;
404
	}
405
 
406
	/**
407
	 * @param string property name for the generated key.
408
	 */
409
	public function setProperty($value)
410
	{
411
		$this->_property = $value;
412
	}
413
 
414
	/**
415
	 * @throws TSqlMapConfigurationException extends is unsupported.
416
	 */
417
	public function setExtends($value)
418
	{
419
		throw new TSqlMapConfigurationException('sqlmap_can_not_extend_select_key');
420
	}
421
 
422
	/**
423
	 * @return boolean true if key is generated after insert command, false otherwise.
424
	 */
425
	public function getIsAfter()
426
	{
427
		return $this->_type == 'post';
428
	}
429
}
430