]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Data/Common/Oracle/TOracleTableInfo.php
4a2e31fd3a7ef7518a5b24286dafd8fefef8d8ae
[bacula/bacula] / gui / baculum / framework / Data / Common / Oracle / TOracleTableInfo.php
1 <?php
2
3 /**
4  * TOracleTableInfo class file.
5  *
6  * @author Marcos Nobre <marconobre[at]gmail[dot]com>
7  * @link http://www.pradosoft.com/
8  * @copyright Copyright &copy; 2005-2014 PradoSoft
9  * @license http://www.pradosoft.com/license/
10  * @package System.Data.Common
11  */
12
13 /**
14  * TDbTableInfo class describes the meta data of a database table.
15  *
16  * @author Wei Zhuo <weizho[at]gmail[dot]com>
17  * @package System.Data.Common
18  * @since 3.1
19  */
20 class TOracleTableInfo extends TComponent
21 {
22         private $_info=array();
23
24         private $_primaryKeys;
25         private $_foreignKeys;
26
27         private $_columns;
28
29         private $_lowercase;
30
31         /**
32          * Sets the database table meta data information.
33          * @param array table column information.
34          */
35         public function __construct($tableInfo=array(),$primary=array(),$foreign=array())
36         {
37                 $this->_info=$tableInfo;
38                 $this->_primaryKeys=$primary;
39                 $this->_foreignKeys=$foreign;
40                 $this->_columns=new TMap;
41         }
42
43         /**
44          * @param TDbConnection database connection.
45          * @return TDbCommandBuilder new command builder
46          */
47         public function createCommandBuilder($connection)
48         {
49                 Prado::using('System.Data.Common.Oracle.TOracleCommandBuilder');
50                 return new TOracleCommandBuilder($connection,$this);
51         }
52
53         /**
54          * @param string information array key name
55          * @param mixed default value if information array value is null
56          * @return mixed information array value.
57          */
58         public function getInfo($name,$default=null)
59         {
60                 return isset($this->_info[$name]) ? $this->_info[$name] : $default;
61         }
62
63         /**
64          * @param string information array key name
65          * @param mixed new information array value.
66          */
67         protected function setInfo($name,$value)
68         {
69                 $this->_info[$name]=$value;
70         }
71
72         /**
73          * @return string name of the table this column belongs to.
74          */
75         public function getTableName()
76         {
77                 return $this->getInfo('TableName');
78         }
79
80         /**
81          * @return string full name of the table, database dependent.
82          */
83         public function getTableFullName()
84         {
85                 return $this->_info['SchemaName'].'.'.$this->getTableName();
86         }
87
88         /**
89          * @return boolean whether the table is a view, default is false.
90          */
91         public function getIsView()
92         {
93                 return $this->getInfo('IsView',false);
94         }
95
96         /**
97          * @return TMap TDbTableColumn column meta data.
98          */
99         public function getColumns()
100         {
101                 return $this->_columns;
102         }
103
104         /**
105          * @param string column id
106          * @return TDbTableColumn column information.
107          */
108         public function getColumn($name)
109         {
110                 if(($column = $this->_columns->itemAt($name))!==null)
111                         return $column;
112                 throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
113         }
114
115         /**
116          * @param array list of column Id, empty to get all columns.
117          * @return array table column names (identifier quoted)
118          */
119         public function getColumnNames()
120         {
121                 foreach($this->getColumns() as $column)
122                         $names[] = $column->getColumnName();
123                 return $names;
124         }
125
126         /**
127          * @return string[] names of primary key columns.
128          */
129         public function getPrimaryKeys()
130         {
131                 return $this->_primaryKeys;
132         }
133
134         /**
135          * @return array tuples of foreign table and column name.
136          */
137         public function getForeignKeys()
138         {
139                 return $this->_foreignKeys;
140         }
141
142         /**
143          * @return array lowercased column key names mapped to normal column ids.
144          */
145         public function getLowerCaseColumnNames()
146         {
147                 if($this->_lowercase===null)
148                 {
149                         $this->_lowercase=array();
150                         foreach($this->getColumns()->getKeys() as $key)
151                                 $this->_lowercase[strtolower($key)] = $key;
152                 }
153                 return $this->_lowercase;
154         }
155 }
156