/*##########################################################################
- # Object factory
- ##########################################################################*/
-
- /**
- * Delegate calls to the schema object.
- *
- * @param string $method
- * @param array $args
- *
- * @return TODO
- */
- public function componentFactory($component, $args)
- {
- $class = str_replace('_Schema', '', $this->_schemaClass) . '_' . $component;
- $class = new ReflectionClass(class_exists($class) ? $class : __CLASS__ . '_' . $component);
-
- return $class->newInstanceArgs($args);
- }
-
-
- /*##########################################################################
# Object composition
##########################################################################*/
/*##########################################################################
+ # Object factories
+ ##########################################################################*/
+
+ /**
+ * Factory for Column objects
+ */
+ public function makeColumn($name, $default, $sqlType = null, $null = true)
+ {
+ return new Horde_Db_Adapter_Base_Column($name, $default, $sqlType, $null);
+ }
+
+ /**
+ * Factory for ColumnDefinition objects
+ */
+ public function makeColumnDefinition($base, $name, $type, $limit = null,
+ $precision = null, $scale = null, $unsigned = null,
+ $default = null, $null = null, $autoincrement = null)
+ {
+ return new Horde_Db_Adapter_Base_ColumnDefinition($base, $name, $type, $limit, $precision, $scale, $unsigned, $default, $null, $autoincrement);
+ }
+
+ /**
+ * Factory for Index objects
+ */
+ public function makeIndex($table, $name, $primary, $unique, $columns)
+ {
+ return new Horde_Db_Adapter_Base_Index($table, $name, $primary, $unique, $columns);
+ }
+
+ /**
+ * Factory for Table objects
+ */
+ public function makeTable($name, $primaryKey, $columns, $indexes)
+ {
+ return new Horde_Db_Adapter_Base_Table($name, $primaryKey, $columns, $indexes);
+ }
+
+ /**
+ * Factory for TableDefinition objects
+ */
+ public function makeTableDefinition($name, $base, $options = array())
+ {
+ return new Horde_Db_Adapter_Base_TableDefinition($name, $base, $options);
+ }
+
+
+ /*##########################################################################
# Object composition
##########################################################################*/
*/
public function table($tableName, $name = null)
{
- return $this->componentFactory('Table', array(
+ return $this->makeTable(
$tableName,
$this->primaryKey($tableName),
$this->columns($tableName, $name),
- $this->indexes($tableName, $name),
- ));
+ $this->indexes($tableName, $name)
+ );
}
/**
*/
public function createTable($name, $options=array())
{
- $tableDefinition =
- $this->componentFactory('TableDefinition', array($name, $this, $options));
+ $tableDefinition = $this->makeTableDefinition($name, $this, $options);
if (isset($options['primaryKey'])) {
if ($options['primaryKey'] === false) {
if ($this[$name]) {
$column = $this[$name];
} else {
- $column = $this->_base->componentFactory('ColumnDefinition', array(
- $this->_base, $name, $type));
+ $column = $this->_base->makeColumnDefinition($this->_base, $name, $type);
}
$column->setLimit(isset($options['limit']) ? $options['limit'] : null);
class Horde_Db_Adapter_Mysql_Schema extends Horde_Db_Adapter_Base_Schema
{
/*##########################################################################
+ # Object factories
+ ##########################################################################*/
+
+ /**
+ * Factory for Column objects
+ */
+ public function makeColumn($name, $default, $sqlType = null, $null = true)
+ {
+ return new Horde_Db_Adapter_Mysql_Column($name, $default, $sqlType, $null);
+ }
+
+
+ /*##########################################################################
# Quoting
##########################################################################*/
$this->_cache->set("tables/columns/$tableName", serialize($rows));
}
- $pk = $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, array()));
+ $pk = $this->makeIndex($tableName, 'PRIMARY', true, true, array());
foreach ($rows as $row) {
if ($row['Key'] == 'PRI') {
$pk->columns[] = $row['Field'];
continue;
}
$currentIndex = $row['Key_name'];
- $indexes[] = $this->componentFactory('Index', array(
- $tableName, $row['Key_name'], false, $row['Non_unique'] == '0', array()));
+ $indexes[] = $this->makeIndex(
+ $tableName, $row['Key_name'], false, $row['Non_unique'] == '0', array());
}
$indexes[count($indexes) - 1]->columns[] = $row['Column_name'];
}
// create columns from rows
$columns = array();
foreach ($rows as $row) {
- $columns[$row['Field']] = $this->componentFactory('Column', array(
- $row['Field'], $row['Default'], $row['Type'], $row['Null'] == 'YES'));
+ $columns[$row['Field']] = $this->makeColumn(
+ $row['Field'], $row['Default'], $row['Type'], $row['Null'] == 'YES');
}
return $columns;
/*##########################################################################
+ # Object factories
+ ##########################################################################*/
+
+ /**
+ * Factory for Column objects
+ */
+ public function makeColumn($name, $default, $sqlType = null, $null = true)
+ {
+ return new Horde_Db_Adapter_Postgresql_Column($name, $default, $sqlType, $null);
+ }
+
+
+ /*##########################################################################
# Quoting
##########################################################################*/
' AND constraint_name = ' . $this->quoteString($tableName . '_pkey');
$pk = $this->selectValues($sql, $name);
- return $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, $pk));
+ return $this->makeIndex($tableName, 'PRIMARY', true, true, $pk);
}
/**
foreach ($result as $row) {
if ($currentIndex != $row[0]) {
$currentIndex = $row[0];
- $indexes[] = $this->componentFactory('Index', array(
- $tableName, $row[0], false, $row[1] == 't', array()));
+ $indexes[] = $this->makeIndex(
+ $tableName, $row[0], false, $row[1] == 't', array());
}
$indexes[count($indexes) - 1]->columns[] = $row[2];
}
// create columns from rows
$columns = array();
foreach ($rows as $row) {
- $columns[$row[0]] = $this->componentFactory('Column', array(
- $row[0], $row[2], $row[1], !(boolean)$row[3]));
+ $columns[$row[0]] = $this->makeColumn(
+ $row[0], $row[2], $row[1], !(boolean)$row[3]);
}
return $columns;
}
class Horde_Db_Adapter_Sqlite_Schema extends Horde_Db_Adapter_Base_Schema
{
/*##########################################################################
+ # Object factories
+ ##########################################################################*/
+
+ /**
+ * Factory for Column objects
+ */
+ public function makeColumn($name, $default, $sqlType = null, $null = true)
+ {
+ return new Horde_Db_Adapter_Sqlite_Column($name, $default, $sqlType, $null);
+ }
+
+
+ /*##########################################################################
# Quoting
##########################################################################*/
$this->_cache->set("tables/columns/$tableName", serialize($rows));
}
- $pk = $this->componentFactory('Index', array($tableName, 'PRIMARY', true, true, array()));
+ $pk = $this->makeIndex($tableName, 'PRIMARY', true, true, array());
foreach ($rows as $row) {
if ($row['pk'] == 1) {
$pk->columns[] = $row['name'];
if (!$indexes) {
$indexes = array();
foreach ($this->select('PRAGMA index_list(' . $this->quoteTableName($tableName) . ')') as $row) {
- $index = $this->componentFactory('Index', array(
- $tableName, $row['name'], false, (bool)$row['unique'], array()));
+ $index = $this->makeIndex(
+ $tableName, $row['name'], false, (bool)$row['unique'], array());
foreach ($this->select('PRAGMA index_info(' . $this->quoteColumnName($index->name) . ')') as $field) {
$index->columns[] = $field['name'];
}
// create columns from rows
$columns = array();
foreach ($rows as $row) {
- $columns[$row[1]] = $this->componentFactory('Column', array(
- $row[1], $row[4], $row[2], !(bool)$row[3]));
+ $columns[$row[1]] = $this->makeColumn(
+ $row[1], $row[4], $row[2], !(bool)$row[3]);
}
return $columns;