summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/Configuration/TConfigDeserialize.php
blob: 9a44d1ecb1fdc674287f3408f387b52189d3a423 (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
<?php

class TConfigDeserialize
{
	private $_properties;

	public function __construct($properties)
	{
		$this->_properties = $properties;
	}

	public function loadConfiguration($object, $node, $file)
	{
		foreach($node->attributes() as $k=>$v)
		{
			if($object->canSetProperty($k))
				$object->{'set'.$k}($this->replaceProperties((string)($v)));
			else 
				throw new TUndefinedAttributeException($k,$node,$object,$file);
		}	
	}

	public function replaceProperties($string)
	{
		foreach($this->_properties as $find => $replace)
			$string = str_replace('${'.$find.'}', $replace, $string);
		return $string;
	}

	public function parameterMap($node, $sqlMap, $file)
	{
		$parameterMap = new TParameterMap;
		$this->loadConfiguration($parameterMap, $node, $file);
		foreach($node->parameter as $parameter)
		{
			$property = $this->parameterProperty($parameter, $sqlMap, $file);
			$property->initialize($sqlMap);
			$parameterMap->addParameterProperty($property);
		}
		return $parameterMap;
	}

	public function parameterProperty($node, $sqlMap, $file)
	{
		$property = new TParameterProperty;
		$this->loadConfiguration($property, $node, $file);
		return $property;
	}

	public function select($node, $sqlMap, $file)
	{
		$select = new TSqlMapSelect;
		$this->loadConfiguration($select, $node, $file);
		$select->initialize($sqlMap);
		return $select;
	}

	public function update($node, $sqlMap, $file)
	{
		$update = new TSqlMapUpdate;
		$this->loadConfiguration($update, $node, $file);
		$update->initialize($sqlMap);
		return $update;
	}

	public function delete($node, $sqlMap, $file)
	{
		$delete = new TSqlMapDelete;
		$this->loadConfiguration($delete, $node, $file);
		$delete->initialize($sqlMap);
		return $delete;
	}


	public function insert($node, $sqlMap, $file)
	{
		$insert = new TSqlMapInsert;
		$this->loadConfiguration($insert, $node, $file);
		if(isset($node->selectKey))
		{
			$selectKey = new TSqlMapSelectKey;
			$this->loadConfiguration($selectKey, $node->selectKey, $file);
			$type = $selectKey->getType();
			$selectKey->setType(strtolower($type) == 'post' ? 'post' : 'pre');
			$insert->setSelectKey($selectKey);
		}
		if(isset($node->generate))
		{
			var_dump("add generate");
		}

		$insert->initialize($sqlMap);
		return $insert;
	}
	
	public function statement($node, $sqlMap, $file)
	{
		$statement = new TSqlMapStatement;
		$this->loadConfiguration($statement, $node, $file);
		$statement->initialize($sqlMap);
		return $statement;
	}
	
	public function resultMap($node, $sqlMap, $file)
	{
		$resultMap = new TResultMap;
		$this->loadConfiguration($resultMap, $node, $file);
		foreach($node->result as $result)
		{
			$property = $this->resultProperty($result, $sqlMap, $file);
			$property->initialize($sqlMap, $resultMap);
			$resultMap->addResultProperty($property);
		}
		$discriminator = null;
		if(isset($node->discriminator))
		{
			$discriminator = new TDiscriminator;
			$this->loadConfiguration($discriminator, $node->discriminator, $file);
			$discriminator->initMapping($sqlMap, $resultMap);
		}
		foreach($node->subMap as $subMapNode)
		{
			if(is_null($discriminator))
				throw new TSqlMapConfigurationException(
					'sqlmap_undefined_discriminator', $resultMap->getID(), $file);
			$subMap = new TSubMap;
			$this->loadConfiguration($subMap, $subMapNode, $file);
			$discriminator->add($subMap);
		}
		if(!is_null($discriminator))
			$resultMap->setDiscriminator($discriminator);

		return $resultMap;
	}

	public function resultProperty($node, $sqlMap, $file)
	{
		$resultProperty = new TResultProperty;
		$this->loadConfiguration($resultProperty, $node, $file);
		return $resultProperty;
	}

	public function cacheModel($node, $sqlMap, $file)
	{
		$cacheModel = new TSqlMapCacheModel;
		$this->loadConfiguration($cacheModel, $node, $file);
/*		if(isset($node->flushInterval))
		{
			$interval = $node->flushInterval;
			$span = 0; //span in seconds
			if(isset($interval['hours']))
				$span += intval($interval['hours'])*60*60;
			if(isset($interval['minutes']))
				$span += intval($interval['minutes'])*60;
			if(isset($interval['seconds']))
				$span += intval($interval['seconds']);
			if($span > 0)
				$cacheModel->setFlushInterval($span);
		}*/
		if(isset($node->property))
		{
			foreach($node->property as $property)
				$cacheModel->addProperty((string)$property['name'],
						(string)$property['value']);
		}
		return $cacheModel;
	}
}


?>