Limia una tabla de la base de datos
@example Given a clear entity "Pandco\Bundle\AppBundle\Entity\EPR\Sales\SalesInvoice" table
@Given a clear entity :className table
@Given a clear entity :className table and where :where
979691
public function aClearEntityTable($className, $andWhere = null) {
        $doctrine = $this->getDoctrine();
        $em = $doctrine->getManager();
        if ($em->getFilters()->isEnabled('softdeleteable')) {
            $em->getFilters()->disable('softdeleteable');
        }
        if ($className === \Pandco\Bundle\AppBundle\Entity\User\DigitalAccount\TimeWithdraw::class) {
            $query = $em->createQuery("UPDATE " . \Pandco\Bundle\AppBundle\Entity\App\User\DigitalAccount\DigitalAccountConfig::class . " dac SET dac.timeWithdraw = null");
            $query->execute();
        }
        $query = $em->createQuery("DELETE FROM " . $className . " " . $andWhere);
        $query->execute();
        $em->flush();
        $em->clear();
    }
1326065
public function load(Entity $entity)
    {
        $class = $this->getRelatedEntity();
        /** @var Entity $relatedEntity */
        $relatedEntity = new $class();
        /** @var Select $sql */
        $sql = call_user_func_array(
            array($relatedEntity, 'find'),
            []
        );
        $pmk = $entity->getPrimaryKey();
        $tableName = $relatedEntity->getTableName();
        $sql->where(
            [
                "{$tableName}.{$this->getForeignKey()} = :id" => [
                    ':id' => $entity->$pmk
                ]
            ]
        );
        $sql->limit($this->getLimit());
        return $sql->all();
    }
1305819
private Object find(Class entityClass, Object key, List<String> columnsToSelect)
    {
        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass);
        MetamodelImpl metamodel = (MetamodelImpl) KunderaMetadataManager.getMetamodel(kunderaMetadata,
                entityMetadata.getPersistenceUnit());

        String idColumnName = ((AbstractAttribute) entityMetadata.getIdAttribute()).getJPAColumnName();
        Table schemaTable = tableAPI.getTable(entityMetadata.getTableName());

        PrimaryKey rowKey = schemaTable.createPrimaryKey();
        if (metamodel.isEmbeddable(entityMetadata.getIdAttribute().getBindableJavaType()))
        {
            readEmbeddable(key, columnsToSelect, entityMetadata, metamodel, schemaTable, rowKey,
                    entityMetadata.getIdAttribute());
        }
        else
        {
            if (eligibleToFetch(columnsToSelect, idColumnName))
            {
                NoSqlDBUtils.add(schemaTable.getField(idColumnName), rowKey, key, idColumnName);
            }
        }
        KunderaCoreUtils.printQuery("Fetch data from " + entityMetadata.getTableName() + " for PK " + key, showQuery);
        if (log.isDebugEnabled())
        {
            log.debug("Fetching data from " + entityMetadata.getTableName() + " for PK " + key);
        }

        // Object entity = null;
        List entities = new ArrayList();
        Map<String, Object> relationMap = initialize(entityMetadata);

        try
        {
            Iterator<Row> rowsIter = tableAPI.tableIterator(rowKey, null, null);
            // iterator and build entity
            entities = scrollAndPopulate(key, entityMetadata, metamodel, schemaTable, rowsIter, relationMap,
                    columnsToSelect);
        }
        catch (Exception e)
        {
            log.error("Error while finding data for Key " + key + ", Caused By :" + e + ".");
            throw new PersistenceException(e);
        }

        return entities.isEmpty() ? null : entities.get(0);
    }
108440
public function init()
    {
        // the table model is an object list
        if (empty($this->table_model)) {
            return false;
        }

        // get a short tag based on the table name
        if (!$this->get_table_short_tag()) return false;

        $this->tpl_replacements['where_statement']    = '';
        $this->tpl_replacements['load_row_list']      = '';
        $this->tpl_replacements['trait_list']         = "\n\nuse " . $this->namespace . "Database;\n\n";
        $this->tpl_replacements['update_insert_list'] = '';

        $i     = 0;
        $count = count($this->table_model);
        // try to fit all possibilities of generated code in here
        // otherwise it would be iterated much more often
        foreach ($this->table_model as $column) {
            // to reduce the use of the strtolower function ;) just do it once
            $property_name = strtolower($column->Field);

            // get a list of properties
            $property_list_unsorted[(string)$property_name] = (string)"\t/**" . ($column->Comment ? self::STD_INTEND_PROPERTIES . " * comment: $column->Comment" : '');
            $property_list_unsorted[(string)$property_name] .= (string)($column->Extra || strtolower($column->Null) == 'no' ? self::STD_INTEND_PROPERTIES . " * Extra: $column->Extra[Not null]" : '');
            $property_list_unsorted[(string)$property_name] .= (string)" " . self::STD_INTEND_PROPERTIES . " * @var $column->Type" . ($column->Key == 'PRI' ? " [PRIMARY KEY]" : '') . self::STD_INTEND_PROPERTIES . " */" . self::STD_INTEND_PROPERTIES . "public $" . $property_name . " = " . $this->get_type_value((($column->Null == 'NO' && !$this->with_null) ? $column->Type : '')) . ";\n\n";

            if ($column->Key == 'PRI') {

                $this->primary_key[] = $column->Field;
                if (!empty($this->where_statement)) {
                    $this->tpl_replacements['where_statement'] .= (string)' AND ';
                }
                // generate generic where statement based on the primary keys
                $this->tpl_replacements['where_statement'] .= (string)"`$column->Field` = '\$this->" . $property_name . "'";
                $this->tpl_replacements['constructor_key_list'] = '';
                $this->tpl_replacements['constructor_key_list'] .= (string)"\t\t" . '$this->' . $property_name . ' = $' . $property_name . ";\n";

            }

            if ($column->Null == 'NO') {
                $this->tpl_replacements['mandatory_fields'][] = (string)$property_name;
            }

            // mysql list for the save function
            $this->tpl_replacements['update_insert_list'] .= (string)"\t\t\$sql .= (\$this->$property_name !== " . (($column->Null == 'NO' && !$this->with_null) ? $this->get_type_value($column->Type) : 'null') . ") ? \"";
            $this->tpl_replacements['update_insert_list'] .= (string)"`$column->Field`= '\" . Database_Tool::db_sanitize(stripslashes(\$this->$property_name)) . \"'";
            $this->tpl_replacements['update_insert_list'] .= (string)($count != $i + 1 ? ', "' : '"') . " : '';\n";

            // get multi keys for assignment
            if ($column->Key == 'MUL') {
                $this->key_list = (string)$column->Field;
            }
            // get multi keys for assignment
            if ($column->Key == 'UNI') {
                $this->key_list = (string)$column->Field;
            }

            // assign the SQL field list
            $this->sql_field_list[] = (string)"`$this->table_short_tag`.`$column->Field`";

            // generates the load row property assignment list
            $this->tpl_replacements['load_row_list'] .= (string)"\t\t\$this->" . strtolower($column->Field) . " = " . (($column->Null == 'NO' && !$this->with_null) ? $this->get_type_value($column->Type, true) : '') . " isset(\$row->" . $column->Field . ") ? \$row->" . $column->Field . " : " . (($column->Null == 'NO' && !$this->with_null) ? $this->get_type_value($column->Type) : 'null') . ";\n";
            $i = $i + 1;
        }
        // remove the last coma
        // add the db to the listing of the class properties
        $property_list_unsorted['db']        = (string)"\t/**" . self::STD_INTEND_PROPERTIES . " * Database object" . self::STD_INTEND_PROPERTIES . "  * @var Object" . self::STD_INTEND_PROPERTIES . " */" . self::STD_INTEND_PROPERTIES . "public \$db = null;\n\n";
        $property_list_unsorted['mandatory'] = (string)"\t/**" . self::STD_INTEND_PROPERTIES . " * list of mandatory fields " . self::STD_INTEND_PROPERTIES . "  * @var array" . self::STD_INTEND_PROPERTIES . " */" . self::STD_INTEND_PROPERTIES . "public \$mandatory_field = array('" . implode("','", $this->tpl_replacements['mandatory_fields']) . "');\n\n";
        // sort alpabetical based on the key
        ksort($property_list_unsorted);
        $this->tpl_replacements['property_list'] = implode("\n\n", $property_list_unsorted);
        unset($property_list_unsorted);

        $this->generate_primary_key_statement();

        // implode the field list
        $this->tpl_replacements['sql_field_list'] = implode(', ', $this->sql_field_list);

        $this->tpl_replacements['constructor_param_list'] = '$' . strtolower(implode("'\n\t\t* @param ', $", $this->primary_key));

        return true;
    }
879340
public function stashEntity($entity)
    {
        $className = $this->getClassName($entity);
        $entityId  = $this->getEntityId($entity);

        if (!isset($this->stashedEntities[$className])) {
            $this->stashedEntities[$className] = [];
        }

        $this->stashedEntities[$className][$entityId] = $entity;
    }
353367
protected function cacheTableNames()
    {
        if ($this->tableNames) {
            return;
        }
        $this->tableNames = [];
        foreach (ClassInfo::subclassesFor(DataObject::class) as $class) {
            if ($class === DataObject::class) {
                continue;
            }
            $table = $this->buildTableName($class);

            // Check for conflicts
            $conflict = array_search($table, $this->tableNames, true);
            if ($conflict) {
                throw new LogicException(
                    "Multiple classes (\"{$class}\", \"{$conflict}\") map to the same table: \"{$table}\""
                );
            }
            $this->tableNames[$class] = $table;
        }
    }
501520
private static function _loadDatabaseDefinition()
	{
		$db = self::getAdapter();
	
		//Get table columns
		$dbData = array();
		$tables = $db->query("SHOW TABLES")->execute();
		foreach($tables as $tableListRow)
		{
			$table = current($tableListRow);
			$columns = $db->query("DESCRIBE {$table}")->execute();
			$columnData = array();
			foreach($columns as $columnListRow)
			{
				$columnData[$columnListRow['Field']] = $columnListRow['Type'];
			}
			$dbData['tables'][$table]['columns'] = $columnData;
		}
		
		//Get relationships
		$schema = $db->getDriver()->getConnection()->getCurrentSchema();
		$relations = $db->query("
			SELECT table_name, column_name, referenced_table_name, referenced_column_name
			FROM information_schema.key_column_usage
			WHERE table_schema='{$schema}' AND referenced_table_schema IS NOT NULL;
		")->execute();
		$relationData = array();
		foreach($relations as $relation)
		{
			$table = $relation['table_name'];
			$column = $relation['column_name'];
			$otherTable = $relation['referenced_table_name'];
			
			$dbData['tables'][$table]['owners'][$column] = $otherTable;
			$dbData['tables'][$otherTable]['children'][$table][] = $column;

			$table = $relation['table_name'];
			unset($relation['table_name']);
			$relationData[$table][$relation['column_name']] = $relation['referenced_table_name'];
			
		}
		$dbData['relations'] = $relationData;
		
		self::$_databaseDef = $dbData;
	}
1332975
protected function baseQuery()
    {
        if (empty($this->baseQuery) && $this->parent->getData()) {
            $through      = $this->through;
            $alias        = Db::parseName(basename(str_replace('\\', '/', $this->model)));
            $throughTable = $through::getTable();
            $pk           = (new $through)->getPk();
            $throughKey   = $this->throughKey;
            $modelTable   = $this->parent->getTable();
            $fields       = $this->getQueryFields($alias);

            $this->query
                ->field($fields)
                ->alias($alias)
                ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey)
                ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey)
                ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey});

            $this->baseQuery = true;
        }
    }
58038
protected function scanDatabase()
	{
		if ($this->isConnected()) {
			$tables = $this->doctrine->listTableNames();

			foreach ($tables as $table) {
				$schTable = $this->doctrine->listTableDetails($table);

				$this->tables[$table] = $this->getTableFields($schTable);
			}
		}
	}
1251357
public function getTable($entity)
    {
        $tables = $this->getTables();

        if (empty($tables[$entity])) {
            throw new OutOfBoundsException("Entity $entity is not supported for translations");
        }

        return $tables[$entity];
    }
1291008
protected function getEntityTable($subject)
    {
        if (!isset($this->tableNames[$subject])) {
            $this->tableNames[$subject] = $this->resolveEntityTable($subject);
        }

        return $this->tableNames[$subject];
    }
347198
static <E> List<E> toEntities(Class<E> entityClass, Entity[] nativeEntities) {
    if (nativeEntities == null || nativeEntities.length == 0) {
      return new ArrayList<>();
    }
    return toEntities(entityClass, Arrays.asList(nativeEntities));
  }
394508
public static TableModel entity2ReadOnlyModel(Class<?> entityClass) {
		DialectException.assureNotNull(entityClass, "Entity class can not be null");
		TableModel model = globalTableModelCache.get(entityClass);
		if (model != null)
			return model;
		model = entity2ModelWithConfig(entityClass);
		model.setReadOnly(true);
		globalTableModelCache.put(entityClass, model);
		return model;
	}
863407
public function getEntityId($entity)
    {
        $className = get_class($entity);

        if (!isset($this->idAccessorFunctions[$className]["getter"])) {
            if (!$this->hasId($entity)) {
                throw new OrmException("No Id getter registered for class $className");
            }

            $this->registerReflectionIdAccessors($className, 'id');
        }

        try {
            return call_user_func($this->idAccessorFunctions[$className]["getter"], $entity);
        } catch (ReflectionException $e) {
            throw new OrmException("Failed to get entity Id\n" . $e->getMessage(), 0, $e);
        }
    }
133249
public function referencedBy( $entity )
    {

        if( !( $entity instanceof Base || $entity instanceof Container ) ) {
            throw new \InvalidArgumentException("You can only lookup references by Entity or Container");
        }

        $class = $entity instanceof Container
            ? $entity->class
            : $entity;

        $properties = $this->propertiesOfTypeGet( $class );

        // found a entity?
        if( !$properties ) {
            throw new \LogicException(
                sprintf(
                    "Can't find which entity property for repository `%s` references entity of type `%s`",
                    $this->entity,
                    $entityClass
                )
            );
        } elseif( count( $properties ) > 1 ) {
            throw new \LogicException(
                sprintf(
                    "Multiple columns [%s] reference a entity of this type [%s]. This is ambiguous. Can't help you here.",
                    implode( ",", $properties ),
                    \Bond\get_unqualified_class( $entity )
                )
            );
        }

        $property = array_pop( $properties );

        // get references to this entity
        $filterComponent = $this->getFindFilterFactory()
            ->get( $property, null, $entity );

        return $this->findByFilterComponents(
            FindFilterComponentFactory::FIND_ALL,
            array( $property => $filterComponent )
        );

    }
947586
private static function table()
    {
        if (!isset(self::$tableMap[static::class])) {
            if (isset(static::$table)) {
                self::$tableMap[static::class] = static::$table;
            } else {
                self::$tableMap[static::class] = strtolower((new \ReflectionClass(static::class))->getShortName());
            }
        }
        return self::$tableMap[static::class];
    }
1350556
static function TableHasMany($table, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
	{
		$ar = new ADODB_Active_Record($table);
		$ar->hasMany($foreignRef, $foreignKey, $foreignClass);
	}