object will be loaded with the items in the same order as they where created per LIST.

@param Connection $dbal
@param $amazon_order_reference_id

@return AmazonReferenceIdManager|null

@throws \InvalidArgumentException
352106
public static function createFromOrderReferenceId(Connection $dbal, $amazon_order_reference_id)
    {
        $data = $dbal->fetchAll(
            'select * from '.self::PERSIST_TABLE.' WHERE `amazon_order_reference_id` = ? ORDER BY `cmsident`',
            array($amazon_order_reference_id)
        );
        $manager = self::createFromRecordList($data);

        if (null === $manager) {
            throw new \InvalidArgumentException("unable to find an an id mapper object based on the amazonOrderReferenceId [{$amazon_order_reference_id}]");
        }

        return $manager;
    }
17170
public static function createFromShopOrderId(Connection $dbal, $shop_order_id)
    {
        $data = $dbal->fetchAll(
            'select * from '.self::PERSIST_TABLE.' WHERE `shop_order_id` = ? ORDER BY `cmsident`',
            array($shop_order_id)
        );
        $manager = self::createFromRecordList($data);

        if (null === $manager) {
            throw new \InvalidArgumentException("unable to find an an id mapper object based on the shop_order_id [{$shop_order_id}]");
        }

        return $manager;
    }
640603
public function load(AbstractDbEntity $dbEntity)
    {
        // Check that the primary key is set
        if (!$dbEntity->getPrimaryDbValue()) {
            throw new \InvalidArgumentException(
                'Database entity can not be loaded because primary value is not set'
            );
        }

        // Fetch ad from db
        $row = $this->db->fetchRow(
            '
                SELECT *
                FROM `' . $dbEntity->getDbTableName() . '`
                WHERE ' . $this->getPrimaryKeyWhereSql($dbEntity) . '
            ',
            $this->getPrimaryKeyWhereParameters($dbEntity)
        );

        if (!$row) {
            throw new Exception\EntityNotFoundException("Db entity[{$dbEntity->getPrimaryDbValue()}] does not exist");
        }

        $dbEntity->setDbDataFromRow($row);
    }
1200485
public function getOrderReferenceDetails($oOrder = null, array $aParams = array(), $blReadonly = false)
    {
        $aRequestParameters = array();
        $sAmazonOrderReferenceId = ($oOrder === null) ?
            (string)$this->getSession()->getVariable('amazonOrderReferenceId') : '';

        if ($oOrder !== null) {
            $aRequestParameters['amazon_order_reference_id'] = $oOrder->getFieldData('bestitamazonorderreferenceid');
        } elseif ($sAmazonOrderReferenceId !== '') {
            $aRequestParameters['amazon_order_reference_id'] = $sAmazonOrderReferenceId;
            $sLoginToken = (string)$this->getSession()->getVariable('amazonLoginToken');

            if ($sLoginToken !== '') {
                $aRequestParameters['address_consent_token'] = $sLoginToken;
            }
        }

        //Make request
        $aRequestParameters = array_merge($aRequestParameters, $aParams);

        $oData = $this->_convertResponse($this->_getAmazonClient()->getOrderReferenceDetails($aRequestParameters));

        //Update Order info
        if ($blReadonly === false
            && $oOrder !== null
            && isset($oData->GetOrderReferenceDetailsResult->OrderReferenceDetails->OrderReferenceStatus->State)
        ) {
            $this->processOrderReference(
                $oOrder,
                $oData->GetOrderReferenceDetailsResult->OrderReferenceDetails
            );
        }

        return $oData;
    }
485501
public function addReference($ruleKey, $columns, $refTableClass, $refColumns,
                                 $onDelete = null, $onUpdate = null)
    {
        $reference = array(self::COLUMNS         => (array) $columns,
                           self::REF_TABLE_CLASS => $refTableClass,
                           self::REF_COLUMNS     => (array) $refColumns);

        if (!empty($onDelete)) {
            $reference[self::ON_DELETE] = $onDelete;
        }

        if (!empty($onUpdate)) {
            $reference[self::ON_UPDATE] = $onUpdate;
        }

        $this->_referenceMap[$ruleKey] = $reference;

        return $this;
    }
683554
function with(array $relations, array $where = null, $order = null, $limit = 0, $offset = 0) {
		$qthis = $this->conn->quoteName($this->getName());
		$query = $this->getQueryWriter()->reset();
		$query->write("SELECT", "$qthis.*", "FROM", $qthis);
		foreach ($relations as $relation) {
			if (!($relation instanceof Table\Reference)) {
				$relation = static::resolve($relation)->getRelation($this->getName());
			}
			if ($this->getName() === $relation->foreignTable) {
				$query->write("JOIN", $relation->referencedTable)->write("ON");
				foreach ($relation as $key => $ref) {
					$query->criteria(
						array(
							"{$relation->referencedTable}.{$ref}=" => 
								new QueryExpr("{$relation->foreignTable}.{$key}")
						)
					);
				}
			} else {
				$query->write("JOIN", $relation->foreignTable)->write("ON");
				foreach ($relation as $key => $ref) {
					$query->criteria(
						array(
							"{$relation->referencedTable}.{$ref}=" => 
								new QueryExpr("{$relation->foreignTable}.{$key}")
						)
					);
				}
			}
		}
		if ($where) {
			$query->write("WHERE")->criteria($where);
		}
		if ($order) {
			$query->write("ORDER BY", $order);
		}
		if ($limit) {
			$query->write("LIMIT", $limit);
		}
		if ($offset) {
			$query->write("OFFSET", $offset);
		}
		return $this->execute($query);
	}
701679
public function setOrder()
    {
        // set order position if exist
        $order = [];
        foreach ($this->data['order'] as $alias => $params) {

            $order = array_flip($order);

            if (empty($params) === false) {

                foreach ($params as $field => $sort) {
                    $order[] = $alias . '.' . $field . ' ' . $sort;
                }
            }
        }

        $this->builder->orderBy($order);

        return null;
    }
204058
public function &orderBy($order_by)
    {
        if (empty($order_by)) {
            throw new InvalidArgumentException('Order by value is required');
        } elseif (!is_string($order_by) && !is_array($order_by)) {
            throw new InvalidArgumentException('Order by can be string or array');
        }

        $this->order_by = (array) $order_by;

        return $this;
    }
1047023
function getReference($table, $ref = null) {
		if (isset($this->references[$table])) {
			if (!strlen($ref)) {
				return current($this->references[$table]);
			}
			if (isset($this->references[$table][$ref])) {
				return $this->references[$table][$ref];
			}
		}
	}
747532
private function orderQueryBuilderBy(QueryBuilder $queryBuilder, TableInterface $table, $sort)
    {
        if (!is_array($sort)) {
            $sort = array($sort => $table->getOption('order', 'DESC'));
        }

        foreach ($sort as $fieldName => $order) {
            // Check field is sortable
            $field = $table->getField($fieldName);
            if (!$field->getOption('sortable')) {
                throw new InvalidArgumentException("Field $fieldName is not sortable in table " . $table->getName());
            }

            foreach ((array)$field->getOption('order_path') as $orderBy) {
                $queryBuilder->addOrderBy($this->fixQueryPath($orderBy, $field), $order);
            }
        }
    }
105843
public function createAdminAdapter(DatabaseConnection $db) {
		$driver = $db->getInfo()->getDriver();
		switch ($driver) {
			case 'mysql':
			return new MysqlAdminAdapter($db);

			case 'pgsql':
			return new PgsqlAdminAdapter($db);

			case 'sqlite':
			return new SqliteAdminAdapter($db);

			default:
			throw new InvalidArgumentException("Unsupported driver: $driver");
		}
	}
848750
public function getOrderByIdentifier($orderBy)
    {
        $objectManager = $this->getObjectManager();
        $classMetadata = $objectManager->getClassMetadata($this->getEntityClass());

        if (strpos($orderBy, '::') === false) {

            if (!$classMetadata->hasField($orderBy)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid order by column: Entity "%s" has no field "%s"',
                    $this->getEntityClass(),
                    $orderBy
                ));
            }

            $orderByIdentifier = $this->getEntityClassAlias()
                               . '.'
                               . $orderBy;
        } else {
            list($association, $assocProperty) = explode('::', $orderBy);

            if (!$classMetadata->hasAssociation($association)) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid order by column: Entity "%s" has no association "%s"',
                    $this->getEntityClass(),
                    $association
                ));
            }

            if (in_array($assocProperty, array('count'))) {
                //@FIXME
                $orderByIdentifier = $this->getEntityClassAlias()
                                   . '.id';

            } else {
                $assocTargetClass = $classMetadata->getAssociationTargetClass($association);

                if (!$objectManager->getClassMetadata($assocTargetClass)->hasField($assocProperty)) {
                    throw new \InvalidArgumentException(sprintf(
                        'Invalid order by column: Entity "%s" has no field "%s"',
                        $assocTargetClass,
                        $assocProperty
                    ));
                }

                $joinAlias         = self::JOIN_ALIAS_PREFIX . $association;
                $orderByIdentifier = $joinAlias . '.' . $assocProperty;
            }
        }

        return $orderByIdentifier;
    }
165092
protected function _orderReferenceUpdate($oData)
    {
        $sId = $oData->OrderReference->AmazonOrderReferenceId;
        $oOrder = $this->_loadOrderById('BESTITAMAZONORDERREFERENCEID', $sId);

        if ($oOrder !== false && isset($oData->OrderReference->OrderReferenceStatus->State)) {
            $this->getClient()->processOrderReference($oOrder, $oData->OrderReference);
            $this->logIPNResponse(Logger::INFO, 'OK', $oData);
            return true;
        }

        $this->logIPNResponse(Logger::ERROR, "Order with Order Reference ID: {$sId} not found", $oData);
        return false;
    }
675054
public static function getQueryBuilder(String $connectionId=null)
	{
		if ($connectionId == null) {
			$connectionId = Repository::$staticConnectionId;
		}

		return self::getInstance($connectionId)->provider->queryBuilder(new ConnectionManager(), $connectionId);
	}
234745
protected function createRedirectContainer($orderReference)
    {
        $redirectContainer = new RedirectContainer();

        $sig = $this->getUrlHmacGenerator()->hash($orderReference, $this->getStandardParameter()->getKey());
        $params = '?orderReference=' . $orderReference . '&sig=' . $sig;

        $redirectContainer->setSuccessUrl($this->getStandardParameter()->getRedirectSuccessUrl() . $params);
        $redirectContainer->setBackUrl($this->getStandardParameter()->getRedirectBackUrl() . $params);
        $redirectContainer->setErrorUrl($this->getStandardParameter()->getRedirectErrorUrl() . $params);

        return $redirectContainer;
    }
32440
public function getDealerAdmin(ConnectionInterface $con = null)
    {
        if ($this->aDealerAdmin === null && ($this->id !== null)) {
            $this->aDealerAdmin = ChildDealerAdminQuery::create()->findPk($this->id, $con);
            /* The following can be used additionally to
                guarantee the related object contains a reference
                to this object.  This level of coupling may, however, be
                undesirable since it could result in an only partially populated collection
                in the referenced object.
                $this->aDealerAdmin->addDealerAdminVersions($this);
             */
        }

        return $this->aDealerAdmin;
    }
329121
public function createCommand($db = null)
    {
        if ($this->primaryModel !== null) {
            // lazy loading
            if (is_array($this->via)) {
                // via relation
                /** @var $viaQuery ActiveQuery */
                list($viaName, $viaQuery) = $this->via;
                if ($viaQuery->multiple) {
                    $viaModels = $viaQuery->all();
                    $this->primaryModel->populateRelation($viaName, $viaModels);
                } else {
                    $model = $viaQuery->one();
                    $this->primaryModel->populateRelation($viaName, $model);
                    $viaModels = $model === null ? [] : [$model];
                }
                $this->filterByModels($viaModels);
            } else {
                $this->filterByModels([$this->primaryModel]);
            }
        }

        /* @var $modelClass ActiveRecord */
        $modelClass = $this->modelClass;

        if ($db === null) {
            $db = $modelClass::getDb();
        }
        if ($this->from === null) {
            $this->from = $modelClass::tableName();
        }

        return parent::createCommand($db);
    }