<commit_before><?php

/**
 * File Command.php
 *
 * PHP version 5.3+
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2013 Sweelix
 * @license   http://www.sweelix.net/license license
 * @version   XXX
 * @link      http://www.sweelix.net
 * @category  nosql
 * @package   sweelix.yii2.nosql.riak
 */

namespace sweelix\yii2\nosql\riak;

use sweelix\yii2\nosql\Command as BaseCommand;
use sweelix\yii2\nosql\Query;
use sweelix\yii2\nosql\DataReader;

/**
 * Class Command
 *
 * Represents a Riak statement to be executed against database.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2013 Sweelix
 * @license   http://www.sweelix.net/license license
 * @version   XXX
 * @link      http://www.sweelix.net
 * @category  nosql
 * @package   sweelix.yii2.nosql.riak
 * @since     XXX
 */
class Command extends BaseCommand {
	
	/**
	 * Executes the query statement and returns ALL rows at once. 
	 * The Query object to checked the indexes, mapReduce, link 
	 * to determine the query will use queryMapReduce or queryIndexes or queryLink
	 *
	 * @param Query $query is query object with prepared param's query
	 * 
	 * @return array|false all rows of the query result. Each array element is an array representing a row of data.
	 * false if no request has been executed.
	 * @since XXX
	 */
	public function queryAll() {
		$this->noSqlDb->open();
		$dataReturn = array();
		// queryIndexes
		if (!empty($this->commandData['queryIndex']) && $this->mode === 'selectWithIndex') {
			$response = $this->noSqlDb->client->queryIndexes(
					$this->bucket, //BucketName 
					$this->queryIndexName, //IndexName
					$this->queryIndexValue, //Value
					$this->queryIndexEndValue,
					$this->queryParams);
			$dataReader = new DataReader();
			$body = $response->getData();
			if ($response->getStatus() == 200) {
				foreach ($body['keys'] as $key) {
					$response = $this->noSqlDb->client->getObject($this->bucket, $key);
					$dataReader->addObject($response, $key);
				}
			} else {
				$dataReader = new DataReader($response);
			}
			return $dataReader;
				
		}
		if (isset($this->queryLinks) && $this->mode === 'selectWithLink') {
			$response = $this->noSqlDb->client->queryLinks($this->bucket, $this->key, $this->queryLinks);
			return new DataReader($response);
		}
		// queryMapReduce or queryLink
		if (!empty($this->data) && $this->mode === 'selectWithMapReduce') {
			$response = $this->noSqlDb->client->queryMapReduce($this->data);
			$dataReader = new DataReader();
			$data = $response->getData();
			foreach ($data as $i => $obj) {
				$dataReader->addRawObject($obj);
			}
			return $dataReader;
		}
		return false;
	}

	/**
	 * Executes the query statement and returns the first row of the result.
	 * This method is best used when only the first row of result is needed for a query.
	 * The Query object to checked the indexes, mapReduce, link 
	 * to determine the query will use queryMapReduce or queryIndexes or queryLink
	 *
	 * @param Query $query is query object with prepare param's query
	 * 
	 * @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query
	 * results in nothing.
	 * @throws Exception execution failed
	 * @since XXX
	 */
	public function queryOne() {
		$this->noSqlDb->open();
		$dataReturn = array();
		// queryIndexes
		if (!empty($this->commandData['queryIndex']) && $this->mode === 'selectWithIndex') {
			$response = $this->noSqlDb->client->queryIndexes(
					$this->bucket, //BucketName 
					$this->queryIndexName, //IndexName
					$this->queryIndexValue, //Value
					$this->queryIndexEndValue,
					$this->queryParams);
					$dataReader = new DataReader();
			$body = $response->getData();
			foreach ($body['keys'] as $key) {
				$response = $this->noSqlDb->client->getObject($this->bucket, $key);
				$dataReader->addObject($response, $key);
				break;
			}
			return $dataReader;
		} elseif (!empty($this->queryLinks) && $this->mode == 'selectWithLink') {
			$response = $this->noSqlDb->client->queryLinks($this->bucket, $this->key, $this->queryLinks);
		} else {
			$response = $this->noSqlDb->client->getObject($this->bucket, $this->key, $this->queryParams, $this->headers);
		} 
		return new DataReader($response);
	}

	/**
	 * Executes the query statement and returns query result.
	 *
	 * @return DataReader the reader object for fetching the query result
	 * @throws Exception execution failed
	 * @since XXX
	 */
	public function query() {<commit_msg>returning null when no object is found<commit_after><?php

/**
 * File Command.php
 *
 * PHP version 5.3+
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2013 Sweelix
 * @license   http://www.sweelix.net/license license
 * @version   XXX
 * @link      http://www.sweelix.net
 * @category  nosql
 * @package   sweelix.yii2.nosql.riak
 */

namespace sweelix\yii2\nosql\riak;

use sweelix\yii2\nosql\Command as BaseCommand;
use sweelix\yii2\nosql\Query;
use sweelix\yii2\nosql\DataReader;

/**
 * Class Command
 *
 * Represents a Riak statement to be executed against database.
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright 2010-2013 Sweelix
 * @license   http://www.sweelix.net/license license
 * @version   XXX
 * @link      http://www.sweelix.net
 * @category  nosql
 * @package   sweelix.yii2.nosql.riak
 * @since     XXX
 */
class Command extends BaseCommand {
	
	/**
	 * Executes the query statement and returns ALL rows at once. 
	 * The Query object to checked the indexes, mapReduce, link 
	 * to determine the query will use queryMapReduce or queryIndexes or queryLink
	 *
	 * @param Query $query is query object with prepared param's query
	 * 
	 * @return array|false all rows of the query result. Each array element is an array representing a row of data.
	 * false if no request has been executed.
	 * @since XXX
	 */
	public function queryAll() {
		$this->noSqlDb->open();
		$dataReturn = array();
		// queryIndexes
		if (!empty($this->commandData['queryIndex']) && $this->mode === 'selectWithIndex') {
			$response = $this->noSqlDb->client->queryIndexes(
					$this->bucket, //BucketName 
					$this->queryIndexName, //IndexName
					$this->queryIndexValue, //Value
					$this->queryIndexEndValue,
					$this->queryParams);
			$dataReader = new DataReader();
			$body = $response->getData();
			if ($response->getStatus() == 200) {
				foreach ($body['keys'] as $key) {
					$response = $this->noSqlDb->client->getObject($this->bucket, $key);
					$dataReader->addObject($response, $key);
				}
			} else {
				$dataReader = new DataReader($response);
			}
			return $dataReader;
				
		}
		if (isset($this->queryLinks) && $this->mode === 'selectWithLink') {
			$response = $this->noSqlDb->client->queryLinks($this->bucket, $this->key, $this->queryLinks);
			return new DataReader($response);
		}
		// queryMapReduce or queryLink
		if (!empty($this->data) && $this->mode === 'selectWithMapReduce') {
			$response = $this->noSqlDb->client->queryMapReduce($this->data);
			$dataReader = new DataReader();
			$data = $response->getData();
			foreach ($data as $i => $obj) {
				$dataReader->addRawObject($obj);
			}
			return $dataReader;
		}
		return false;
	}

	/**
	 * Executes the query statement and returns the first row of the result.
	 * This method is best used when only the first row of result is needed for a query.
	 * The Query object to checked the indexes, mapReduce, link 
	 * to determine the query will use queryMapReduce or queryIndexes or queryLink
	 *
	 * @param Query $query is query object with prepare param's query
	 * 
	 * @return array|boolean the first row (in terms of an array) of the query result. False is returned if the query
	 * results in nothing.
	 * @throws Exception execution failed
	 * @since XXX
	 */
	public function queryOne() {
		$this->noSqlDb->open();
		$dataReturn = array();
		// queryIndexes
		if (!empty($this->commandData['queryIndex']) && $this->mode === 'selectWithIndex') {
			$response = $this->noSqlDb->client->queryIndexes(
					$this->bucket, //BucketName 
					$this->queryIndexName, //IndexName
					$this->queryIndexValue, //Value
					$this->queryIndexEndValue,
					$this->queryParams);
			$dataReader = new DataReader();
			$body = $response->getData();
			foreach ($body['keys'] as $key) {
				$response = $this->noSqlDb->client->getObject($this->bucket, $key);
				$dataReader->addObject($response, $key);
				return $dataReader->current();
			}
			return null;
		} elseif (!empty($this->queryLinks) && $this->mode == 'selectWithLink') {
			$response = $this->noSqlDb->client->queryLinks($this->bucket, $this->key, $this->queryLinks);
		} else {
			$response = $this->noSqlDb->client->getObject($this->bucket, $this->key, $this->queryParams, $this->headers);
		} 
		return null;
	}

	/**
	 * Executes the query statement and returns query result.
	 *
	 * @return DataReader the reader object for fetching the query result
	 * @throws Exception execution failed
	 * @since XXX
	 */
	public function query() {
{'fraction_non_alphanumeric': 0.14779698828778584, 'fraction_numerical': 0.006023424428332404, 'mean_word_length': 3.5237134207870837, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 154, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5274513', 'n_tokens_mistral': 3173, 'n_tokens_neox': 2770, 'n_words': 774}