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

class TResultMap extends TComponent
{
	private $_ID='';
	private $_className='';
	private $_columns='';
	private $_extendMap='';
	private $_groupBy='';
	private $_discriminator=null;
	private $_typeHandlerFactory=null;

	public function __construct()
	{
		$this->_columns = new TMap;
	}

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

	public function getClass(){ return $this->_className; }
	public function setClass($value){ $this->_className = $value; }

	public function getColumns(){ return $this->_columns; }
	public function setColumns($value){ $this->_columns = $value; }

	public function getExtends(){ return $this->_extendMap; }
	public function setExtends($value){ $this->_extendMap = $value; }

	public function getGroupBy(){ return $this->_groupBy; }
	public function setGroupBy($value){ $this->_groupBy = $value; }

	public function getDiscriminator(){ return $this->_discriminator; }
	public function setDiscriminator($value){ $this->_discriminator = $value; }

	public function initialize($sqlMap, $resultMap=null)
	{
		$this->_typeHandlerFactory = $sqlMap->getTypeHandlerFactory();
	}

	public function addResultProperty(TResultProperty $property)
	{
		$this->_columns->add($property->getProperty(), $property);
	}
	
	public function createInstanceOfResult()
	{
		$handler = $this->_typeHandlerFactory->getTypeHandler($this->getClass());

		try
		{
			if(!is_null($handler))
					return $handler->createNewInstance();		
			else
				return TTypeHandlerFactory::createInstanceOf($this->getClass());
		}
		catch (TDataMapperException $e)
		{
			throw new TSqlMapExecutionException(
				'sqlmap_unable_to_create_new_instance', 
					$this->getClass(), get_class($handler), $this->getID());
		}
	}

	public function resolveSubMap($row)
	{
		$subMap = $this;
		if(!is_null($disc = $this->getDiscriminator()))
		{
			$mapping = $disc->getMapping();
			$dataValue = $mapping->getDatabaseValue($row);
			$subMap = $disc->getSubMap((string)$dataValue);
		
			if(is_null($subMap))
				$subMap = $this;
			else if($subMap !== $this)
				$subMap = $subMap->resolveSubMap($row);
		}
		return $subMap;
	}
}

?>