@param PersistenceContext $context
@param Row[]              $rows

@return void
171303
protected function loadGroupedOrderIndexes(PersistenceContext $context, array $rows)
    {
        /** @var Row[][] $groupedRows */
        $groupedRows        = [];
        $groupingValues     = [];
        $groupingColumnName = $this->groupingColumn->getName();

        foreach ($rows as $row) {
            $groupingValue = $row->getColumn($groupingColumnName);
            $groupHash     = $groupingValue instanceof \DateTimeInterface
                    ? $groupingValue->format('Y-m-d H:i:s')
                    : $groupingValue;

            $groupingValues[$groupHash] = $groupingValue;
            $groupedRows[$groupHash][]  = $row;
        }

        $groupingColumn = Expr::column($this->table->getName(), $this->groupingColumn);
        $select         = Select::from($this->table)
                ->addColumn('order_index', Expr::max(Expr::column($this->table->getName(), $this->orderColumn)))
                ->addColumn('group', $groupingColumn)
                ->where(Expr::in(
                        $groupingColumn,
                        Expr::tupleParams($this->groupingColumn->getType(), $groupingValues)
                ))
                ->addGroupBy($groupingColumn);

        $orderIndexes        = $context->getConnection()->load($select)->asArray();
        $indexedOrderIndexes = [];

        foreach ($orderIndexes as $orderIndexRow) {
            $groupHash = $orderIndexRow['group'] instanceof \DateTimeInterface
                    ? $orderIndexRow['group']->format('Y-m-d H:i:s')
                    : $orderIndexRow['group'];

            $indexedOrderIndexes[$groupHash] = $orderIndexRow['order_index'];
        }
        
        $orderColumn = $this->orderColumn->getName();

        foreach ($groupedRows as $groupHash => $rows) {
            $orderIndex = isset($indexedOrderIndexes[$groupHash])
                    ? $indexedOrderIndexes[$groupHash] + 1
                    : 1;

            foreach ($rows as $row) {
                $row->setColumn($orderColumn, $orderIndex);
                $orderIndex++;
            }
        }
    }
363073
private function migrateRow(array $row): void
    {
        $data = ['tstamp' => time()];

        foreach (self::SIZES as $size) {
            $size       .= 'Size';
            $data[$size] = $this->migrateSize($row[$size]);
        }

        $this->connection->update('tl_bs_grid', $data, ['id' => $row['id']]);
    }
272853
public function prepareResults(&$rows)
    {
        foreach ($rows as $key => &$row) {
            $row = $this->create($row);
        }
        return $rows;
    }
341722
protected function initializeSorting(ContextInterface $context)
    {
        if (null !== $activeSort = $context->getActiveSort()) {
            $columnName = $activeSort->getColumnName();
            if ($this->table->hasColumn($columnName)) {
                $this->table->getColumn($columnName)->applySort($this, $activeSort);
            }
        }
    }
392167
public function applyLockingDataBeforeCommit(PersistenceContext $context, array $objects, array $rows)
    {
        $columnName = $this->columnName;

        foreach ($rows as $row) {
            $currentVersion = $row->getColumn($columnName);
            $row->setColumn($columnName, $currentVersion + 1);

            if ($row->hasPrimaryKey()) {
                $row->setLockingColumn($columnName, $currentVersion);
            }
        }
    }
339842
protected function _afterEntityFetch(AnCommandContext $context)
    {
        //set the persistd flag
        $this->setPersisted(true);

        //set the raw data
        $this->_data->setRowData($context['data']);

        //force setting the keys
        foreach ($context['keys'] as $key => $value) {
            $this->_data[$key] = $value;
        }
    }
542721
final protected function bulkUpdateForeignKeys(PersistenceContext $context, array $modifiedColumns, array $children) : array
    {
        $primaryKey     = $this->mapper->getPrimaryTable()->getPrimaryKeyColumn();
        $primaryKeyName = $primaryKey->getName();

        $columnsToPersist = array_merge([$primaryKey], $modifiedColumns);

        $rowSet = new RowSet($this->mapper->getPrimaryTable()->withColumnsButIgnoringConstraints($columnsToPersist));
        $rows   = [];

        foreach ($children as $key => $childId) {
            if ($childId !== null) {
                $row = $rowSet->createRow([$primaryKeyName => $childId]);
                $rowSet->add($row);
                $rows[$key] = $row;
            }
        }

        if ($modifiedColumns) {
            if ($rowSet->count() > 0) {
                $context->bulkUpdate($rowSet);
            }
        }

        return $rows;
    }
1101446
protected function table($headers, $rows)
    {
        if($this->console instanceof Command) {
            $this->console->table($headers, $rows);
        }
    }
157978
public function persist(PersistenceContext $context, ParentChildMap $map)
    {
        /** @var Row[] $parentRows */
        $parentRows = [];
        /** @var object[] $children */
        $children = [];

        foreach ($map->getItems() as $key => $item) {
            $parentRow = $item->getParent();

            $hasChild = (bool)$item->getChild();
            if ($hasChild) {
                $parentRows[$key] = $parentRow;
                $children[$key]   = $item->getChild();
            }

            if ($this->objectIssetColumnName && !$this->isWithinValueObject) {
                $parentRow->setColumn($this->objectIssetColumnName, $hasChild);
            }
        }

        $this->disableLazyLoadingForRelations(function () use ($context, $children, $parentRows) {
            $this->mapper->persistAllToRows($context, $children, $parentRows);
        });
    }
294224
protected function processInsertFromSelect(InsertFromSelect $row, $context): InsertFromSelect
    {
        if ($row->columns === null) {
            $columns = null;
        } else {
            $columns = [];
            foreach ($row->columns as $index => $column) {
                $columns[$index] = $this->processColumnName($column, $context);
            }
        }
        $selectQuery = $this->processSubQuery($row->selectQuery, $context);

        if ($selectQuery === $row->selectQuery && $columns === $row->columns) {
            return $row;
        } else {
            return new InsertFromSelect($columns, $selectQuery);
        }
    }
298367
final protected function constructNewObjectsFromRow(LoadingContext $context, Row $row) : ITypedObject
    {
        return $this->mapping->constructNewObjectFromRow($row);
    }
605405
public function persist(PersistenceContext $context, ParentChildrenMap $map)
    {
        if ($map->hasAnyParentsWithPrimaryKeys()) {
            $this->mode->syncInvalidatedRelationsQuery(
                $context,
                $this->childrenTable,
                $this->foreignKeyToParent,
                $this->getInvalidatedRelationExpr($map)
            );
        }

        $this->insertRelated($context, $map);
    }
214919
protected function _beforeInsert(DatabaseContext $context)
    {
        $mixer = $this->getMixer();
        $table = $mixer instanceof DatabaseRowInterface ?  $mixer->getTable() : $mixer;

        if($this->hasProperty('created_by') && empty($this->created_by)) {
            $this->created_by  = (int) $this->getObject('user')->getId();
        }

        if($this->hasProperty('created_on') && (empty($this->created_on) || $this->created_on == $table->getDefault('created_on'))) {
            $this->created_on  = gmdate('Y-m-d H:i:s');
        }
    }
939978
public function buildRows(
        array $rows,
        $style = null
    ): void {
        // The row needs to start at 1 at the beginning of execution.
        // The top left corner of the sheet is actually position (col = 1, row = 1).
        $rowIndex = 1;

        // If we have a header row then we need to bump the row index down one,
        // otherwise we'll overwrite the header (not ideal).
        if ($this->builder->getActiveSheet()->cellExistsByColumnAndRow(1, $rowIndex)) {
            $rowIndex = 2;
        }

        foreach ($rows as $row) {
            $this->buildRow($row, $style, $rowIndex);

            $rowIndex++;
        }

        return;
    }
67799
public function batchInsert(array $rows): ResultInterface
    {
        $this->insert = $this->getTableName();
        foreach ($rows as $row) {
            ksort($row);
            if (!isset($this->insertValues['columns'])) {
                $this->insertValues['columns'] = array_keys($row);
            }
            $this->insertValues['values'][] = array_values($row);
        }

        return $this->execute();
    }
162880
public void setRows(int rows) {

        if (rows < 0) {
            throw new IllegalArgumentException(String.valueOf(rows));
        }
        getStateHelper().put(PropertyKeys.rows, rows);

    }
1016247
public function applyLockingDataAfterCommit(PersistenceContext $context, array $objects, array $rows)
    {
        foreach ($objects as $key => $entity) {
            $entity->hydrate([
                    $this->propertyName => $rows[$key]->getColumn($this->columnName)
            ]);
        }
    }