Author: david
Date: Fri Feb 11 15:54:23 2011
New Revision: 8961

Log:
Add keymap table to schema

Added:
   trunk/lib/model/QubitKeymap.php
   trunk/lib/model/map/KeymapTableMap.php
   trunk/lib/model/om/BaseKeymap.php
Modified:
   trunk/config/schema.yml
   trunk/data/sql/lib.model.schema.sql

Modified: trunk/config/schema.yml
==============================================================================
--- trunk/config/schema.yml     Fri Feb 11 00:02:25 2011        (r8960)
+++ trunk/config/schema.yml     Fri Feb 11 15:54:23 2011        (r8961)
@@ -148,6 +148,12 @@
     sources: longvarchar
     revision_history: longvarchar
 
+  keymap:
+    source_id: integer
+    target_id: integer 
+    source_name: longvarchar
+    target_name: longvarchar
+
   map:
     created_at:
     updated_at:

Modified: trunk/data/sql/lib.model.schema.sql
==============================================================================
--- trunk/data/sql/lib.model.schema.sql Fri Feb 11 00:02:25 2011        (r8960)
+++ trunk/data/sql/lib.model.schema.sql Fri Feb 11 15:54:23 2011        (r8961)
@@ -443,6 +443,24 @@
 )Type=InnoDB;
 
 #-----------------------------------------------------------------------------
+#-- keymap
+#-----------------------------------------------------------------------------
+
+DROP TABLE IF EXISTS `keymap`;
+
+
+CREATE TABLE `keymap`
+(
+       `source_id` INTEGER,
+       `target_id` INTEGER,
+       `source_name` TEXT,
+       `target_name` TEXT,
+       `id` INTEGER  NOT NULL AUTO_INCREMENT,
+       `serial_number` INTEGER default 0 NOT NULL,
+       PRIMARY KEY (`id`)
+)Type=InnoDB;
+
+#-----------------------------------------------------------------------------
 #-- map
 #-----------------------------------------------------------------------------
 

Added: trunk/lib/model/QubitKeymap.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/model/QubitKeymap.php     Fri Feb 11 15:54:23 2011        (r8961)
@@ -0,0 +1,28 @@
+<?php
+
+
+/**
+ * Skeleton subclass for representing a row from the 'keymap' table.
+ *
+ * 
+ *
+ * You should add additional methods to this class to meet the
+ * application requirements.  This class will only be generated as
+ * long as it does not already exist in the output directory.
+ *
+ * @package    lib.model
+ */
+class QubitKeymap extends BaseKeymap {
+
+       /**
+        * Initializes internal state of QubitKeymap object.
+        * @see        parent::__construct()
+        */
+       public function __construct()
+       {
+               // Make sure that parent constructor is always invoked, since 
that
+               // is where any default values for this object are set.
+               parent::__construct();
+       }
+
+} // QubitKeymap

Added: trunk/lib/model/map/KeymapTableMap.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/model/map/KeymapTableMap.php      Fri Feb 11 15:54:23 2011        
(r8961)
@@ -0,0 +1,55 @@
+<?php
+
+
+/**
+ * This class defines the structure of the 'keymap' table.
+ *
+ *
+ *
+ * This map class is used by Propel to do runtime db structure discovery.
+ * For example, the createSelectSql() method checks the type of a given column 
used in an
+ * ORDER BY clause to know whether it needs to apply SQL to make the ORDER BY 
case-insensitive
+ * (i.e. if it's a text column type).
+ *
+ * @package    lib.model.map
+ */
+class KeymapTableMap extends TableMap {
+
+       /**
+        * The (dot-path) name of this class
+        */
+       const CLASS_NAME = 'lib.model.map.KeymapTableMap';
+
+       /**
+        * Initialize the table attributes, columns and validators
+        * Relations are not initialized by this method since they are lazy 
loaded
+        *
+        * @return     void
+        * @throws     PropelException
+        */
+       public function initialize()
+       {
+         // attributes
+               $this->setName('keymap');
+               $this->setPhpName('keymap');
+               $this->setClassname('QubitKeymap');
+               $this->setPackage('lib.model');
+               $this->setUseIdGenerator(true);
+               // columns
+               $this->addColumn('SOURCE_ID', 'sourceId', 'INTEGER', false, 
null, null);
+               $this->addColumn('TARGET_ID', 'targetId', 'INTEGER', false, 
null, null);
+               $this->addColumn('SOURCE_NAME', 'sourceName', 'LONGVARCHAR', 
false, null, null);
+               $this->addColumn('TARGET_NAME', 'targetName', 'LONGVARCHAR', 
false, null, null);
+               $this->addPrimaryKey('ID', 'id', 'INTEGER', true, null, null);
+               $this->addColumn('SERIAL_NUMBER', 'serialNumber', 'INTEGER', 
true, null, 0);
+               // validators
+       } // initialize()
+
+       /**
+        * Build the RelationMap objects for this table relationships
+        */
+       public function buildRelations()
+       {
+       } // buildRelations()
+
+} // KeymapTableMap

Added: trunk/lib/model/om/BaseKeymap.php
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/lib/model/om/BaseKeymap.php   Fri Feb 11 15:54:23 2011        (r8961)
@@ -0,0 +1,533 @@
+<?php
+
+abstract class BaseKeymap implements ArrayAccess
+{
+  const
+    DATABASE_NAME = 'propel',
+
+    TABLE_NAME = 'keymap',
+
+    SOURCE_ID = 'keymap.SOURCE_ID',
+    TARGET_ID = 'keymap.TARGET_ID',
+    SOURCE_NAME = 'keymap.SOURCE_NAME',
+    TARGET_NAME = 'keymap.TARGET_NAME',
+    ID = 'keymap.ID',
+    SERIAL_NUMBER = 'keymap.SERIAL_NUMBER';
+
+  public static function addSelectColumns(Criteria $criteria)
+  {
+    $criteria->addSelectColumn(QubitKeymap::SOURCE_ID);
+    $criteria->addSelectColumn(QubitKeymap::TARGET_ID);
+    $criteria->addSelectColumn(QubitKeymap::SOURCE_NAME);
+    $criteria->addSelectColumn(QubitKeymap::TARGET_NAME);
+    $criteria->addSelectColumn(QubitKeymap::ID);
+    $criteria->addSelectColumn(QubitKeymap::SERIAL_NUMBER);
+
+    return $criteria;
+  }
+
+  protected static
+    $keymaps = array();
+
+  protected
+    $keys = array(),
+    $row = array();
+
+  public static function getFromRow(array $row)
+  {
+    $keys = array();
+    $keys['id'] = $row[4];
+
+    $key = serialize($keys);
+    if (!isset(self::$keymaps[$key]))
+    {
+      $keymap = new QubitKeymap;
+
+      $keymap->keys = $keys;
+      $keymap->row = $row;
+
+      $keymap->new = false;
+
+      self::$keymaps[$key] = $keymap;
+    }
+
+    return self::$keymaps[$key];
+  }
+
+  public static function get(Criteria $criteria, array $options = array())
+  {
+    if (!isset($options['connection']))
+    {
+      $options['connection'] = 
Propel::getConnection(QubitKeymap::DATABASE_NAME);
+    }
+
+    self::addSelectColumns($criteria);
+
+    return QubitQuery::createFromCriteria($criteria, 'QubitKeymap', $options);
+  }
+
+  public static function getAll(array $options = array())
+  {
+    return self::get(new Criteria, $options);
+  }
+
+  public static function getOne(Criteria $criteria, array $options = array())
+  {
+    $criteria->setLimit(1);
+
+    return self::get($criteria, $options)->__get(0, array('defaultValue' => 
null));
+  }
+
+  public static function getById($id, array $options = array())
+  {
+    $criteria = new Criteria;
+    $criteria->add(QubitKeymap::ID, $id);
+
+    if (1 == count($query = self::get($criteria, $options)))
+    {
+      return $query[0];
+    }
+  }
+
+  public static function doDelete(Criteria $criteria, $connection = null)
+  {
+    if (!isset($connection))
+    {
+      $connection = 
QubitTransactionFilter::getConnection(QubitKeymap::DATABASE_NAME);
+    }
+
+    $affectedRows = 0;
+
+    $affectedRows += BasePeer::doDelete($criteria, $connection);
+
+    return $affectedRows;
+  }
+
+  protected
+    $tables = array();
+
+  public function __construct()
+  {
+    $this->tables[] = 
Propel::getDatabaseMap(QubitKeymap::DATABASE_NAME)->getTable(QubitKeymap::TABLE_NAME);
+  }
+
+  protected
+    $values = array(),
+    $refFkValues = array();
+
+  protected function rowOffsetGet($name, $offset, $options)
+  {
+    if (empty($options['clean']) && array_key_exists($name, $this->values))
+    {
+      return $this->values[$name];
+    }
+
+    if (array_key_exists($name, $this->keys))
+    {
+      return $this->keys[$name];
+    }
+
+    if (!array_key_exists($offset, $this->row))
+    {
+      if ($this->new)
+      {
+        return;
+      }
+
+      if (!isset($options['connection']))
+      {
+        $options['connection'] = 
Propel::getConnection(QubitKeymap::DATABASE_NAME);
+      }
+
+      $criteria = new Criteria;
+      $criteria->add(QubitKeymap::ID, $this->id);
+
+      call_user_func(array(get_class($this), 'addSelectColumns'), $criteria);
+
+      $statement = BasePeer::doSelect($criteria, $options['connection']);
+      $this->row = $statement->fetch();
+    }
+
+    return $this->row[$offset];
+  }
+
+  public function __isset($name)
+  {
+    $args = func_get_args();
+
+    $options = array();
+    if (1 < count($args))
+    {
+      $options = $args[1];
+    }
+
+    $offset = 0;
+    foreach ($this->tables as $table)
+    {
+      foreach ($table->getColumns() as $column)
+      {
+        if ($name == $column->getPhpName())
+        {
+          return null !== $this->rowOffsetGet($name, $offset, $options);
+        }
+
+        if ("{$name}Id" == $column->getPhpName())
+        {
+          return null !== $this->rowOffsetGet("{$name}Id", $offset, $options);
+        }
+
+        $offset++;
+      }
+    }
+
+    throw new sfException("Unknown record property \"$name\" on 
\"".get_class($this).'"');
+  }
+
+  public function offsetExists($offset)
+  {
+    $args = func_get_args();
+
+    return call_user_func_array(array($this, '__isset'), $args);
+  }
+
+  public function __get($name)
+  {
+    $args = func_get_args();
+
+    $options = array();
+    if (1 < count($args))
+    {
+      $options = $args[1];
+    }
+
+    $offset = 0;
+    foreach ($this->tables as $table)
+    {
+      foreach ($table->getColumns() as $column)
+      {
+        if ($name == $column->getPhpName())
+        {
+          return $this->rowOffsetGet($name, $offset, $options);
+        }
+
+        if ("{$name}Id" == $column->getPhpName())
+        {
+          $relatedTable = 
$column->getTable()->getDatabaseMap()->getTable($column->getRelatedTableName());
+
+          return call_user_func(array($relatedTable->getClassName(), 
'getBy'.ucfirst($relatedTable->getColumn($column->getRelatedColumnName())->getPhpName())),
 $this->rowOffsetGet("{$name}Id", $offset, $options));
+        }
+
+        $offset++;
+      }
+    }
+
+    throw new sfException("Unknown record property \"$name\" on 
\"".get_class($this).'"');
+  }
+
+  public function offsetGet($offset)
+  {
+    $args = func_get_args();
+
+    return call_user_func_array(array($this, '__get'), $args);
+  }
+
+  public function __set($name, $value)
+  {
+    $args = func_get_args();
+
+    $options = array();
+    if (2 < count($args))
+    {
+      $options = $args[2];
+    }
+
+    $offset = 0;
+    foreach ($this->tables as $table)
+    {
+      foreach ($table->getColumns() as $column)
+      {
+        if ($name == $column->getPhpName())
+        {
+          $this->values[$name] = $value;
+        }
+
+        if ("{$name}Id" == $column->getPhpName())
+        {
+          $relatedTable = 
$column->getTable()->getDatabaseMap()->getTable($column->getRelatedTableName());
+
+          $this->values["{$name}Id"] = 
$value->__get($relatedTable->getColumn($column->getRelatedColumnName())->getPhpName(),
 $options);
+        }
+
+        $offset++;
+      }
+    }
+
+    return $this;
+  }
+
+  public function offsetSet($offset, $value)
+  {
+    $args = func_get_args();
+
+    return call_user_func_array(array($this, '__set'), $args);
+  }
+
+  public function __unset($name)
+  {
+    $offset = 0;
+    foreach ($this->tables as $table)
+    {
+      foreach ($table->getColumns() as $column)
+      {
+        if ($name == $column->getPhpName())
+        {
+          $this->values[$name] = null;
+        }
+
+        if ("{$name}Id" == $column->getPhpName())
+        {
+          $this->values["{$name}Id"] = null;
+        }
+
+        $offset++;
+      }
+    }
+
+    return $this;
+  }
+
+  public function offsetUnset($offset)
+  {
+    $args = func_get_args();
+
+    return call_user_func_array(array($this, '__unset'), $args);
+  }
+
+  public function clear()
+  {
+    $this->row = $this->values = array();
+
+    return $this;
+  }
+
+  protected
+    $new = true;
+
+  protected
+    $deleted = false;
+
+  public function save($connection = null)
+  {
+    if ($this->deleted)
+    {
+      throw new PropelException('You cannot save an object that has been 
deleted.');
+    }
+
+    if ($this->new)
+    {
+      $this->insert($connection);
+    }
+    else
+    {
+      $this->update($connection);
+    }
+
+    $offset = 0;
+    foreach ($this->tables as $table)
+    {
+      foreach ($table->getColumns() as $column)
+      {
+        if (array_key_exists($column->getPhpName(), $this->values))
+        {
+          $this->row[$offset] = $this->values[$column->getPhpName()];
+        }
+
+        $offset++;
+      }
+    }
+
+    $this->new = false;
+    $this->values = array();
+
+    return $this;
+  }
+
+  protected function param($column)
+  {
+    $value = $this->values[$column->getPhpName()];
+
+    // Convert to DateTime or SQL zero special case
+    if (isset($value) && $column->isTemporal() && !$value instanceof DateTime)
+    {
+      // Year only: one or more digits.  Convert to SQL zero special case
+      if (preg_match('/^\d+$/', $value))
+      {
+        $value .= '-0-0';
+      }
+
+      // Year and month only: one or more digits, plus separator, plus
+      // one or more digits.  Convert to SQL zero special case
+      else if (preg_match('/^\d+[-\/]\d+$/', $value))
+      {
+        $value .= '-0';
+      }
+
+      // Convert to DateTime if not SQL zero special case: year plus
+      // separator plus zero to twelve (possibly zero padded) plus
+      // separator plus one or more zeros
+      if (!preg_match('/^\d+[-\/]0*(?:1[0-2]|\d)[-\/]0+$/', $value))
+      {
+        $value = new DateTime($value);
+      }
+    }
+
+    return $value;
+  }
+
+  protected function insert($connection = null)
+  {
+    if (!isset($connection))
+    {
+      $connection = 
QubitTransactionFilter::getConnection(QubitKeymap::DATABASE_NAME);
+    }
+
+    $offset = 0;
+    foreach ($this->tables as $table)
+    {
+      $criteria = new Criteria;
+      foreach ($table->getColumns() as $column)
+      {
+        if (!array_key_exists($column->getPhpName(), $this->values))
+        {
+          if ('createdAt' == $column->getPhpName() || 'updatedAt' == 
$column->getPhpName())
+          {
+            $this->values[$column->getPhpName()] = new DateTime;
+          }
+
+          if ('sourceCulture' == $column->getPhpName())
+          {
+            $this->values['sourceCulture'] = sfPropel::getDefaultCulture();
+          }
+        }
+
+        if (array_key_exists($column->getPhpName(), $this->values))
+        {
+          $criteria->add($column->getFullyQualifiedName(), 
$this->param($column));
+        }
+
+        $offset++;
+      }
+
+      if (null !== $id = BasePeer::doInsert($criteria, $connection))
+      {
+        // Guess that the first primary key of the first table is auto
+        // incremented
+        if ($this->tables[0] == $table)
+        {
+          $columns = $table->getPrimaryKeyColumns();
+          $this->values[$columns[0]->getPhpName()] = 
$this->keys[$columns[0]->getPhpName()] = $id;
+        }
+      }
+    }
+
+    return $this;
+  }
+
+  protected function update($connection = null)
+  {
+    if (!isset($connection))
+    {
+      $connection = 
QubitTransactionFilter::getConnection(QubitKeymap::DATABASE_NAME);
+    }
+
+    $offset = 0;
+    foreach ($this->tables as $table)
+    {
+      $criteria = new Criteria;
+      $selectCriteria = new Criteria;
+      foreach ($table->getColumns() as $column)
+      {
+        if (!array_key_exists($column->getPhpName(), $this->values))
+        {
+          if ('updatedAt' == $column->getPhpName())
+          {
+            $this->values['updatedAt'] = new DateTime;
+          }
+        }
+
+        if (array_key_exists($column->getPhpName(), $this->values))
+        {
+          if ('serialNumber' == $column->getPhpName())
+          {
+            $selectCriteria->add($column->getFullyQualifiedName(), 
$this->values[$column->getPhpName()]++);
+          }
+
+          $criteria->add($column->getFullyQualifiedName(), 
$this->param($column));
+        }
+
+        if ($column->isPrimaryKey())
+        {
+          $selectCriteria->add($column->getFullyQualifiedName(), 
$this->keys[$column->getPhpName()]);
+        }
+
+        $offset++;
+      }
+
+      if (0 < $criteria->size())
+      {
+        BasePeer::doUpdate($selectCriteria, $criteria, $connection);
+      }
+    }
+
+    return $this;
+  }
+
+  public function delete($connection = null)
+  {
+    if ($this->deleted)
+    {
+      throw new PropelException('This object has already been deleted.');
+    }
+
+    $criteria = new Criteria;
+    $criteria->add(QubitKeymap::ID, $this->id);
+
+    self::doDelete($criteria, $connection);
+
+    $this->deleted = true;
+
+    return $this;
+  }
+
+       /**
+        * Returns the primary key for this object (row).
+        * @return     int
+        */
+       public function getPrimaryKey()
+       {
+               return $this->getid();
+       }
+
+       /**
+        * Generic method to set the primary key (id column).
+        *
+        * @param      int $key Primary key.
+        * @return     void
+        */
+       public function setPrimaryKey($key)
+       {
+               $this->setid($key);
+       }
+
+  public function __call($name, $args)
+  {
+    if ('get' == substr($name, 0, 3) || 'set' == substr($name, 0, 3))
+    {
+      $args = array_merge(array(strtolower(substr($name, 3, 1)).substr($name, 
4)), $args);
+
+      return call_user_func_array(array($this, '__'.substr($name, 0, 3)), 
$args);
+    }
+
+    throw new sfException('Call to undefined method 
'.get_class($this)."::$name");
+  }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to