summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/Configuration/TSqlMapStatement.php
blob: 414ad2f1c2e0973f5f7982de617f9bbe1c91fbe1 (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
<?php

class TSqlMapStatement extends TComponent
{
	private $_ID='';
	private $_parameterMapName='';
	private $_parameterMap;
	private $_parameterClassName='';
//	private $_parameterClass;
	private $_resultMapName='';
	private $_resultMap;
	private $_resultClassName='';
//	private $_resultClass;
	private $_cacheModelName='';
	private $_remapResults=false;
	private $_SQL='';
	private $_listClass='';
	private $_typeHandler;
	private $_extendStatement='';
	private $_cache;

	public function getID(){ return $this->_ID; }
	public function setID($value){ $this->_ID = $value; }

	public function getParameterMap(){ return $this->_parameterMapName; }
	public function setParameterMap($value){ $this->_parameterMapName = $value; }

	public function getParameterClass(){ return $this->_parameterClassName; }
	public function setParameterClass($value){ $this->_parameterClassName = $value; }

	public function getResultMap(){ return $this->_resultMapName; }
	public function setResultMap($value){ $this->_resultMapName = $value; }

	public function getResultClass(){ return $this->_resultClassName; }
	public function setResultClass($value){ $this->_resultClassName = $value; }

	public function getCacheModel(){ return $this->_cacheModelName; }
	public function setCacheModel($value){ $this->_cacheModelName = $value; }

	public function getCache(){ return $this->_cache; }
	public function setCache($value){ $this->_cache = $value; }

	public function getRemapResults(){ return $this->_remapResults; }
	public function setRemapResults($value){ $this->_remapResults = TPropertyValue::ensureBoolean($value,false); }

	public function getSQL(){ return $this->_SQL; }
	public function setSQL($value){ $this->_SQL = $value; }

	public function getListClass(){ return $this->_listClass; }
	public function setListClass($value){ $this->_listClass = $value; }

	public function getExtends(){ return $this->_extendStatement; }
	public function setExtends($value){ $this->_extendStatement = $value; }
	
	public function resultMap(){ return $this->_resultMap; }
	public function parameterMap(){ return $this->_parameterMap; }

	public function setInlineParameterMap($map)
	{
		$this->_parameterMap = $map;
	}
//	public function parameterClass(){ return $this->_parameterClass; }
//	public function resultClass(){ return $this->_resultClass; }

	public function initialize($sqlMap)
	{
		$this->_typeHandler = $sqlMap->getTypeHandlerFactory();
		if(strlen($this->_resultMapName) > 0)
			$this->_resultMap = $sqlMap->getResultMap($this->_resultMapName);
		if(strlen($this->_parameterMapName) > 0)
			$this->_parameterMap = $sqlMap->getParameterMap($this->_parameterMapName);
	}


	public function createInstanceOfListClass()
	{
		if(strlen($type = $this->getListClass()) > 0)
			return $this->createInstanceOf($type);
		return array(); //new TList;
	}

	protected function createInstanceOf($type,$row=null)
	{
		$handler = $this->_typeHandler->getTypeHandler($type);
		
		try
		{
			if(!is_null($handler))
					return $handler->createNewInstance($row);		
			else
				return TTypeHandlerFactory::createInstanceOf($type);
		}
		catch (TDataMapperException $e)
		{
			throw new TSqlMapExecutionException(
				'sqlmap_unable_to_create_new_instance', 
					$type, get_class($handler), $this->getID());
		}
					
	}

	public function createInstanceOfResultClass($row)
	{
		if(strlen($type= $this->getResultClass()) > 0)
			return $this->createInstanceOf($type,$row);
	}
}

?>