diff options
author | Daniel <darthdaniel85@gmail.com> | 2013-12-09 02:04:04 -0500 |
---|---|---|
committer | Daniel <darthdaniel85@gmail.com> | 2013-12-09 02:04:04 -0500 |
commit | 4312f846098706c19576a4438704a5f22eb2d32d (patch) | |
tree | 012d2c682821d23c56a3804aa8eeddbc5584c694 /framework/Wsat | |
parent | e04fb5c765252593fb88fb56eaefbdc88bbeb7d1 (diff) |
Support for all PRADO DB drivers!
Diffstat (limited to 'framework/Wsat')
-rw-r--r-- | framework/Wsat/TWsatARGenerator.php | 62 | ||||
-rw-r--r-- | framework/Wsat/pages/TWsatGenerateAR.php | 2 |
2 files changed, 20 insertions, 44 deletions
diff --git a/framework/Wsat/TWsatARGenerator.php b/framework/Wsat/TWsatARGenerator.php index 2d4aeb12..7ae5e46e 100644 --- a/framework/Wsat/TWsatARGenerator.php +++ b/framework/Wsat/TWsatARGenerator.php @@ -9,23 +9,20 @@ * @since 3.3 * @package Wsat */ + +Prado::using('System.Data.Common.TDbMetaData'); + class TWsatARGenerator { /** - * Gets the current Db connection, the connection object is obtained from - * the TActiveRecordManager if connection is currently null. - * @return TDbConnection current db connection for this object. + * @return TDbMetaData for retrieving metadata information, such as + * table and columns information, from a database connection. */ - private $_conn; + private $_dbMetaData; /** - * @return TActiveRecordGateway record table gateway. - */ - private $_gateway; - - /** - * Output folder where AR classes will be generated. + * Output folder where AR classes will be saved. */ private $_opFile; @@ -55,19 +52,9 @@ class TWsatARGenerator if(!class_exists("TActiveRecordManager", false)) throw new Exception("You need to enable the ActiveRecord module in your application configuration file."); $ar_manager = TActiveRecordManager::getInstance(); - $this->_conn = $ar_manager->getDbConnection(); - $this->_conn->Active = true; - $this->_gateway = $ar_manager->getRecordGateway(); - } - - /** - * Destructor. - * Disconnect the db connection. - */ - public function __destruct() - { - if ($this->_conn !== null) - $this->_conn->Active = false; + $_conn = $ar_manager->getDbConnection(); + $_conn->Active = true; + $this->_dbMetaData = TDbMetaData::getInstance($_conn); } public function setOpFile($op_file_namespace) @@ -94,17 +81,17 @@ class TWsatARGenerator // <editor-fold defaultstate="collapsed" desc="Main APIs"> public function generate($tableName) { - $tableInfo = $this->_gateway->getTableInfo($this->_conn, $tableName); + $tableInfo = $this->_dbMetaData->getTableInfo($tableName); $this->_commonGenerate($tableName, $tableInfo); } public function generateAll() { - foreach ($this->_getAllTableNames() as $tableName) + foreach ($this->_dbMetaData->findTableNames() as $tableName) { if ($tableName == "pradocache") continue; - $tableInfo = $this->_gateway->getTableInfo($this->_conn, $tableName); + $tableInfo = $this->_dbMetaData->getTableInfo($tableName); if (!empty($this->_relations)) { // Cancel generation of M-M relationships middle table @@ -118,9 +105,9 @@ class TWsatARGenerator public function buildRelations() { $this->_relations = array(); - foreach ($this->_getAllTableNames() as $table_name) + foreach ($this->_dbMetaData->findTableNames() as $table_name) { - $tableInfo = $this->_gateway->getTableInfo($this->_conn, $table_name); + $tableInfo = $this->_dbMetaData->getTableInfo($table_name); $pks = $tableInfo->getPrimaryKeys(); $fks = $tableInfo->getForeignKeys(); @@ -174,7 +161,7 @@ class TWsatARGenerator private function _commonGenerate($tableName, $tableInfo) { if (count($tableInfo->getColumns()) === 0) - throw new Exception("Unable to find table or view $tableName in " . $this->_conn->getConnectionString() . "."); + throw new Exception("Unable to find table or view $tableName in " . $this->_dbMetaData->getDbConnection()->getConnectionString() . "."); else { $properties = array(); @@ -189,17 +176,6 @@ class TWsatARGenerator file_put_contents($output, $class); } - private function _getAllTableNames() - { - $command = $this->_conn->createCommand("Show Tables"); - $dataReader = $command->query(); - $dataReader->bindColumn(1, $table); - $tables = array(); - while ($dataReader->read()) - $tables[] = $table; - return $tables; - } - private function _getProperClassName($tableName) { $table_name_words = str_replace("_", " ", strtolower($tableName)); @@ -209,11 +185,11 @@ class TWsatARGenerator public function renderAllTablesInformation() { - foreach ($this->_getAllTableNames() as $table_name) + foreach ($this->_dbMetaData->findTableNames() as $table_name) { echo $table_name . "<br>"; - $tableInfo = $this->_gateway->getTableInfo($this->_conn, $table_name); + $tableInfo = $this->_dbMetaData->getTableInfo($table_name); echo "Table info:" . "<br>"; echo "<pre>"; var_dump($tableInfo); @@ -259,7 +235,7 @@ class TWsatARGenerator { if (isset($column->IsPrimaryKey) && $column->IsPrimaryKey) $property = str_replace($this->uqChars, "", $column->ColumnName); - elseif ($column->PHPType == "string" && $column->DBType != "date") + elseif ($column->PdoType == PDO::PARAM_STR && $column->DBType != "date") { $property = str_replace($this->uqChars, "", $column->ColumnName); break; diff --git a/framework/Wsat/pages/TWsatGenerateAR.php b/framework/Wsat/pages/TWsatGenerateAR.php index 2c85445d..f0ce8430 100644 --- a/framework/Wsat/pages/TWsatGenerateAR.php +++ b/framework/Wsat/pages/TWsatGenerateAR.php @@ -51,7 +51,7 @@ class TWsatGenerateAR extends TPage public function preview($sender) { - throw new THttpException(500, "Not implemented yet."); +// throw new THttpException(500, "Not implemented yet."); } }
\ No newline at end of file |