private function insert($statementType, RetryPolicy $policy, $key, $numberOfInserts, $consistency, $retries = self::NUMBER_OF_TIMEOUT_EXCEPTIONS)
{
try {
// Create all statement types
$batch = new BatchStatement(\Cassandra::BATCH_UNLOGGED);
$prepare = $this->session->prepare($this->insertQuery);
$simple = new SimpleStatement($this->insertQuery);
// Create the default execution options
$options = array("consistency" => $consistency, "retry_policy" => $policy);
// Create the inserts
foreach (range(1, $numberOfInserts) as $i) {
$values = array($key, $i);
if ($statementType == self::BATCH_STATEMENT) {
if ($i % 2 == 0) {
$batch->add($prepare, $values);
} else {
$batch->add($simple, $values);
}
} else {
// Execute either the prepare or simple statment
$statement = $prepare;
if ($statementType == self::SIMPLE_STATEMENT) {
$statement = $simple;
}
$options["arguments"] = $values;
$this->session->execute($statement, new ExecutionOptions($options));
}
}
// Execute the batched insert
if ($statementType == self::BATCH_STATEMENT) {
$this->session->execute($batch, new ExecutionOptions($options));
}
} catch (Exception\TimeoutException $te) {
if (Integration::isDebug()) {
fprintf(STDOUT, "Insert TimeoutException: %s (%s:%d)" . PHP_EOL, $te->getMessage(), $te->getFile(), $te->getLine());
}
if ($retries > 0) {
$this->insert($policy, $key, $numberOfInserts, $consistency, $retries - 1);
} else {
throw $te;
}
}
}