/*
Copyright (c) DataStax, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "batch_request.hpp"
#include "constants.hpp"
#include "execute_request.hpp"
#include "external.hpp"
#include "protocol.hpp"
#include "request_callback.hpp"
#include "serialization.hpp"
#include "statement.hpp"
using namespace datastax;
using namespace datastax::internal::core;
extern "C" {
CassBatch* cass_batch_new(CassBatchType type) {
BatchRequest* batch = new BatchRequest(type);
batch->inc_ref();
return CassBatch::to(batch);
}
void cass_batch_free(CassBatch* batch) { batch->dec_ref(); }
CassError cass_batch_set_keyspace(CassBatch* batch, const char* keyspace) {
return cass_batch_set_keyspace_n(batch, keyspace, SAFE_STRLEN(keyspace));
}
CassError cass_batch_set_keyspace_n(CassBatch* batch, const char* keyspace,
size_t keyspace_length) {
batch->set_keyspace(String(keyspace, keyspace_length));
return CASS_OK;
}
CassError cass_batch_set_consistency(CassBatch* batch, CassConsistency consistency) {
batch->set_consistency(consistency);
return CASS_OK;
}
CassError cass_batch_set_serial_consistency(CassBatch* batch, CassConsistency serial_consistency) {
batch->set_serial_consistency(serial_consistency);
return CASS_OK;
}
CassError cass_batch_set_timestamp(CassBatch* batch, cass_int64_t timestamp) {
batch->set_timestamp(timestamp);
return CASS_OK;
}
CassError cass_batch_set_request_timeout(CassBatch* batch, cass_uint64_t timeout_ms) {
batch->set_request_timeout_ms(timeout_ms);
return CASS_OK;
}
CassError cass_batch_set_is_idempotent(CassBatch* batch, cass_bool_t is_idempotent) {
batch->set_is_idempotent(is_idempotent == cass_true);
return CASS_OK;
}
CassError cass_batch_set_retry_policy(CassBatch* batch, CassRetryPolicy* retry_policy) {
batch->set_retry_policy(retry_policy);
return CASS_OK;
}
CassError cass_batch_set_custom_payload(CassBatch* batch, const CassCustomPayload* payload) {
batch->set_custom_payload(payload);
return CASS_OK;
}
CassError cass_batch_set_tracing(CassBatch* batch, cass_bool_t enabled) {
batch->set_tracing(enabled == cass_true);
return CASS_OK;
}
CassError cass_batch_add_statement(CassBatch* batch, CassStatement* statement) {
batch->add_statement(statement);
return CASS_OK;
}
CassError cass_batch_set_execution_profile(CassBatch* batch, const char* name) {
return cass_batch_set_execution_profile_n(batch, name, SAFE_STRLEN(name));
}
CassError cass_batch_set_execution_profile_n(CassBatch* batch, const char* name,
size_t name_length) {
if (name_length > 0) {
batch->set_execution_profile_name(String(name, name_length));
} else {
batch->set_execution_profile_name(String());
}
return CASS_OK;
}
} // extern "C"
// Format: