Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TDiscriminator and TSubMap classes file.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TDiscriminator.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Data.SqlMap.Configuration
11
 */
12
 
13
/**
14
 * The TDiscriminator corresponds to the <discriminator> tag within a <resultMap>.
15
 *
16
 * TDiscriminator allows inheritance logic in SqlMap result mappings.
17
 * SqlMap compares the data found in the discriminator column to the different
18
 * <submap> values using the column value's string equivalence. When the string values
19
 * matches a particular <submap>, SqlMap will use the <resultMap> defined by
20
 * {@link resultMapping TSubMap::setResultMapping()} property for loading
21
 * the object data.
22
 *
23
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
24
 * @version $Id: TDiscriminator.php 2541 2008-10-21 15:05:13Z qiang.xue $
25
 * @package System.Data.SqlMap.Configuration
26
 * @since 3.1
27
 */
28
class TDiscriminator extends TComponent
29
{
30
	private $_column;
31
	private $_type;
32
	private $_typeHandler=null;
33
	private $_columnIndex;
34
	private $_nullValue;
35
	private $_mapping;
36
	private $_resultMaps=array();
37
	private $_subMaps=array();
38
 
39
	/**
40
	 * @return string the name of the column in the result set from which the
41
	 * value will be used to populate the property.
42
	 */
43
	public function getColumn()
44
	{
45
		return $this->_column;
46
	}
47
 
48
	/**
49
	 * @param string the name of the column in the result set from which the
50
	 * value will be used to populate the property.
51
	 */
52
	public function setColumn($value)
53
	{
54
		$this->_column = $value;
55
	}
56
 
57
	/**
58
	 * @param string property type of the parameter to be set.
59
	 */
60
	public function getType()
61
	{
62
		return $this->_type;
63
	}
64
 
65
	/**
66
	 * The type attribute is used to explicitly specify the property type of the
67
	 * parameter to be set. If the attribute type is not set and the framework
68
	 * cannot otherwise determine the type, the type is assumed from the default
69
	 * value of the property.
70
	 * @return string property type of the parameter to be set.
71
	 */
72
	public function setType($value)
73
	{
74
		$this->_type = $value;
75
	}
76
 
77
	/**
78
	 * @return string custom type handler class name (may use namespace).
79
	 */
80
	public function getTypeHandler()
81
	{
82
		return $this->_typeHandler;
83
	}
84
 
85
	/**
86
	 * @param string custom type handler class name (may use namespace).
87
	 */
88
	public function setTypeHandler($value)
89
	{
90
		$this->_typeHandler = $value;
91
	}
92
 
93
	/**
94
	 * @return int index of the column in the ResultSet
95
	 */
96
	public function getColumnIndex()
97
	{
98
		return $this->_columnIndex;
99
	}
100
 
101
	/**
102
	 * The columnIndex attribute value is the index of the column in the
103
	 * ResultSet from which the value will be used to populate the object property.
104
	 * @param int index of the column in the ResultSet
105
	 */
106
	public function setColumnIndex($value)
107
	{
108
		$this->_columnIndex = TPropertyValue::ensureInteger($value);
109
	}
110
 
111
	/**
112
	 * @return mixed outgoing null value replacement.
113
	 */
114
	public function getNullValue()
115
	{
116
		return $this->_nullValue;
117
	}
118
 
119
	/**
120
	 * @param mixed outgoing null value replacement.
121
	 */
122
	public function setNullValue($value)
123
	{
124
		$this->_nullValue = $value;
125
	}
126
 
127
	/**
128
	 * @return TResultProperty result property for the discriminator column.
129
	 */
130
	public function getMapping()
131
	{
132
		return $this->_mapping;
133
	}
134
 
135
	/**
136
	 * @param TSubMap add new sub mapping.
137
	 */
138
	public function addSubMap($subMap)
139
	{
140
		$this->_subMaps[] = $subMap;
141
	}
142
 
143
	/**
144
	 * @param string database value
145
	 * @return TResultMap result mapping.
146
	 */
147
	public function getSubMap($value)
148
	{
149
		if(isset($this->_resultMaps[$value]))
150
			return $this->_resultMaps[$value];
151
	}
152
 
153
	/**
154
	 * Copies the discriminator properties to a new TResultProperty.
155
	 * @param TResultMap result map holding the discriminator.
156
	 */
157
	public function initMapping($resultMap)
158
	{
159
		$this->_mapping = new TResultProperty($resultMap);
160
		$this->_mapping->setColumn($this->getColumn());
161
		$this->_mapping->setColumnIndex($this->getColumnIndex());
162
		$this->_mapping->setType($this->getType());
163
		$this->_mapping->setTypeHandler($this->getTypeHandler());
164
		$this->_mapping->setNullValue($this->getNullValue());
165
	}
166
 
167
	/**
168
	 * Set the result maps for particular sub-mapping values.
169
	 * @param TSqlMapManager sql map manager instance.
170
	 */
171
	public function initialize($manager)
172
	{
173
		foreach($this->_subMaps as $subMap)
174
		{
175
			$this->_resultMaps[$subMap->getValue()] =
176
				$manager->getResultMap($subMap->getResultMapping());
177
		}
178
	}
179
}
180
 
181
/**
182
 * TSubMap class defines a submapping value and the corresponding <resultMap>
183
 *
184
 * The {@link Value setValue()} property is used for comparison with the
185
 * discriminator column value. When the {@link Value setValue()} matches
186
 * that of the discriminator column value, the corresponding {@link ResultMapping setResultMapping}
187
 * is used inplace of the current result map.
188
 *
189
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
190
 * @version $Id: TDiscriminator.php 2541 2008-10-21 15:05:13Z qiang.xue $
191
 * @package System.Data.SqlMap.Configuration
192
 * @since 3.1
193
 */
194
class TSubMap extends TComponent
195
{
196
	private $_value;
197
	private $_resultMapping;
198
 
199
	/**
200
	 * @return string value for comparison with discriminator column value.
201
	 */
202
	public function getValue()
203
	{
204
		return $this->_value;
205
	}
206
 
207
	/**
208
	 * @param string value for comparison with discriminator column value.
209
	 */
210
	public function setValue($value)
211
	{
212
		$this->_value = $value;
213
	}
214
 
215
	/**
216
	 * The result map to use when the Value matches the discriminator column value.
217
	 * @return string ID of a result map
218
	 */
219
	public function getResultMapping()
220
	{
221
		return $this->_resultMapping;
222
	}
223
 
224
	/**
225
	 * @param string ID of a result map
226
	 */
227
	public function setResultMapping($value)
228
	{
229
		$this->_resultMapping = $value;
230
	}
231
}
232