summaryrefslogtreecommitdiff
path: root/framework/Data/ActiveRecord/Vendor/TDbMetaDataInspector.php
diff options
context:
space:
mode:
authorwei <>2006-11-26 22:15:58 +0000
committerwei <>2006-11-26 22:15:58 +0000
commita8b3ebe8f62c3888b216d827c1c5dcba8a47d4e1 (patch)
tree5eef79dbc5e2f506047fa463cb427a40a7bd8441 /framework/Data/ActiveRecord/Vendor/TDbMetaDataInspector.php
parent6773dfe453682d2b39a26fbabef8e706bf6bb412 (diff)
Adding active record implementation.
Diffstat (limited to 'framework/Data/ActiveRecord/Vendor/TDbMetaDataInspector.php')
-rw-r--r--framework/Data/ActiveRecord/Vendor/TDbMetaDataInspector.php79
1 files changed, 79 insertions, 0 deletions
diff --git a/framework/Data/ActiveRecord/Vendor/TDbMetaDataInspector.php b/framework/Data/ActiveRecord/Vendor/TDbMetaDataInspector.php
new file mode 100644
index 00000000..ee7f339e
--- /dev/null
+++ b/framework/Data/ActiveRecord/Vendor/TDbMetaDataInspector.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * TDbMetaDataInspector class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Vendor
+ */
+
+/**
+ * Base class for database meta data inspectors.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord.Vendor
+ * @since 3.1
+ */
+abstract class TDbMetaDataInspector
+{
+ private $_connection;
+
+ public function __construct($conn)
+ {
+ $this->setDbConnection($conn);
+ }
+
+ /**
+ * @param TDbConnection database connection.
+ */
+ public function setDbConnection($conn)
+ {
+ $this->_connection=$conn;
+ }
+
+ /**
+ * @return TDbConnection database connection.
+ */
+ public function getDbConnection()
+ {
+ return $this->_connection;
+ }
+
+ /**
+ * @param string table name
+ * @return TDbMetaData table meta data.
+ */
+ public function getTableMetaData($table)
+ {
+ $keys = $this->getConstraintKeys($table);
+ $columns = $this->getColumnDefinitions($table);
+ return $this->createMetaData($table,$columns,$keys['primary'], $keys['foreign']);
+ }
+
+ /**
+ * Get the column definitions for given table.
+ * @param string table name.
+ * @return array column name value pairs of column meta data.
+ */
+ abstract protected function getColumnDefinitions($table);
+
+ /**
+ * Gets the primary and foreign key details for the given table.
+ * @param string table name.
+ * @return array key value pairs with keys 'primary' and 'foreign'.
+ */
+ abstract protected function getConstraintKeys($table);
+
+ /**
+ * Create a new instance of meta data.
+ * @param string table name
+ * @param array column meta data
+ * @param array primary key meta data
+ * @param array foreign key meta data.
+ * @return TDbMetaData table meta data.
+ */
+ abstract protected function createMetaData($table, $columns, $primary, $foreign);
+}
+
+?> \ No newline at end of file