Exemplo n.º 1
0
 /**
  * 通过表的实体类,获取表的概要描述,包括:表名、主键、自增字段、字段、默认值
  * 应该根据不同的数据库类型创建对应的TableSchema类:$dbType = $this->getDriver(false)->getDbType();
  * 这里只用到MySQL数据库,暂时不做多数据库类型
  * @param string $tableName
  * @return \tfc\db\TableSchema
  */
 public function getTableSchema($tableName)
 {
     $className = 'tfc\\db\\TableSchema::' . strtolower($tableName);
     if (Singleton::has($className)) {
         return Singleton::get($className);
     }
     $ref = $this->getRefClass($tableName);
     $attributes = $ref->getDefaultProperties();
     $tableSchema = new TableSchema();
     $tableSchema->name = $ref->hasConstant('TABLE_NAME') ? $ref->getConstant('TABLE_NAME') : $ref->getShortName();
     $tableSchema->autoIncrement = $ref->hasConstant('AUTO_INCREMENT') ? $ref->getConstant('AUTO_INCREMENT') : null;
     if (isset($attributes['primaryKey'])) {
         $tableSchema->primaryKey = $attributes['primaryKey'];
         unset($attributes['primaryKey']);
     }
     $tableSchema->columnNames = array_keys($attributes);
     if ($tableSchema->primaryKey === null) {
         $tableSchema->primaryKey = $tableSchema->columnNames[0];
     }
     foreach ($attributes as $key => $value) {
         if ($value === null) {
             unset($attributes[$key]);
         }
     }
     $tableSchema->attributeDefaults = $attributes;
     Singleton::set($className, $tableSchema);
     return $tableSchema;
 }
Exemplo n.º 2
0
 /**
  * 获取数据库代理操作类
  * @return \tfc\saf\DbProxy
  */
 public function getDbProxy()
 {
     if ($this->_dbProxy === null) {
         $clusterName = $this->getClusterName();
         $className = 'tfc\\saf\\DbProxy::' . $clusterName;
         if (($dbProxy = Singleton::get($className)) === null) {
             $dbProxy = new DbProxy($clusterName);
             Singleton::set($className, $dbProxy);
         }
         $this->_dbProxy = $dbProxy;
     }
     return $this->_dbProxy;
 }
Exemplo n.º 3
0
 /**
  * 获取DbProxy
  * @return tfc\saf\DbProxy
  */
 public function getDbProxy()
 {
     $clusterName = \builders\library\Constant::DB_CLUSTER;
     $className = 'tfc\\saf\\DbProxy::' . $clusterName;
     if (($dbProxy = Singleton::get($className)) === null) {
         $dbProxy = new DbProxy($clusterName);
         Singleton::set($className, $dbProxy);
     }
     return $dbProxy;
 }