Commit d47b8dfe authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

change requests from isc

# Conflicts:
#	src/bin/admin/tests/data/pgsql.lease6_dump_test.reference.csv
parent 07b7b23d
......@@ -106,6 +106,25 @@ cql_execute() {
return $retcode
}
cql_execute_script() {
file=$1
shift
if [ $# -gt 1 ]; then
cqlsh $* -e "$file"
retcode=$?
else
cqlsh -u $db_user -p $db_password -k $db_name -f "$file"
retcode=$?
fi
if [ $retcode -ne 0 ]; then
printf "cqlsh returned with exit status $retcode\n"
exit $retcode
fi
return $retcode
}
cql_version() {
version=`cql_execute "SELECT version, minor FROM schema_version" "$@"`
version=`echo "$version" | grep -A 1 "+" | grep -v "+" | tr -d ' ' | cut -d "|" -f 1-2 --output-delimiter="."`
......
......@@ -208,7 +208,8 @@ cql_init() {
printf "Creating and initializing tables using script %s...\n" $scripts_dir/cql/dhcpdb_create.cql
cql_execute_script $scripts_dir/cql/dhcpdb_create.cql
else
printf "Tables are already created.\n"
log_error "Expected empty database $db_name, but the following tables are present \n$result. Aborting."
exit 2
fi
version=`cql_version`
......@@ -485,44 +486,38 @@ cql_dump() {
# Fetch the correct SQL text. Note this function will exit
# if it fails.
get_dump_query $version
select_where_clause=""
if [ $dump_type -eq 4 ]; then
dump_qry="SELECT address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state FROM keatest.lease4"
select_where_clause=" WHERE address = 0" # invalid address
elif [ $dump_type -eq 6 ]; then
dump_qry="SELECT address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state FROM keatest.lease6"
select_where_clause=" WHERE address = ::" # invalid address
fi
# Make sure they specified a file
if [ "$dump_file" = "" ]; then
log_error "you must specify an output file for lease-dump"
usage
exit 1
fi
# If output file exists, notify user, allow them a chance to bail
check_file_overwrite $dump_file
# Check the temp file too
tmp_file="$dump_file.tmp"
check_file_overwrite $tmp_file
# Run the sql to output tab-delimited lease data to a temp file.
# By using a temp file we can check for MySQL errors before using
# 'tr' to translate tabs to commas. We do not use MySQL's output
# to file as that requires linux superuser privileges to execute
# the select.
cql_execute "${dump_qry}" > $tmp_file
retcode=$?
if [ $retcode -ne 0 ]; then
cql_execute "${dump_qry}${select_where_clause}" | head -n 2 | tail -n 1 | sed -e 's/\s*//g' | sed -e 's/|/,/g' > $dump_file
if [ $? -ne 0 ]; then
log_error "lease-dump: cql_execute failed, exit code $retcode";
exit 1
fi
# Now translate tabs to commas.
cat $tmp_file | tr '\t' ',' >$dump_file
cql_execute "${dump_qry}" | tail -n +4 | head -n -2 | sed -e 's/\s*//g' | sed -e 's/|/,/g' | sort -r >> $dump_file
if [ $? -ne 0 ]; then
log_error "lease-dump: reformatting failed";
log_error "lease-dump: cql_execute failed, exit code $retcode";
exit 1
fi
# delete the tmp file on success
rm $tmp_file
echo lease$dump_type successfully dumped to $dump_file
exit 0
}
......
......@@ -22,7 +22,7 @@ db_name="keatest"
# Set location of the kea-admin.
keaadmin=@abs_top_builddir@/src/bin/admin/kea-admin
cql_init_test() {
cql_lease_init_test() {
test_start "cql.init"
# Wipe the database.
......@@ -56,7 +56,7 @@ cql_init_test() {
cql_execute "SELECT state, name FROM lease_state;"
assert_eq 0 $? "lease_state table check failed, expected exit code: %d, actual: %d"
# Trying to create it again should fail. This verifies the db present
# Trying to create it again should fail. This verifies the db present
# check
echo ""
echo "Making sure keyspace creation fails the second time..."
......@@ -70,18 +70,18 @@ cql_init_test() {
test_finish 0
}
cql_version_test() {
cql_lease_version_test() {
test_start "cql.version"
# Wipe the database.
cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql
assert_eq 0 $? "drop table query failed, exit code %d, expected %d"
# Create the database
# Create the database.
$keaadmin lease-init cql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
assert_eq 0 $? "kea-admin lease-init cql failed, expected exit code: %d, actual: %d"
# Verfiy that kea-admin lease-version returns the correct version
# Verfiy that kea-admin lease-version returns the correct version.
version=$($keaadmin lease-version cql -u $db_user -p $db_password -n $db_name)
assert_str_eq "1.0" $version "Expected kea-admin to return %s, returned value was %s"
......@@ -113,6 +113,154 @@ cql_upgrade_test() {
test_finish 0
}
cql_init_test
cql_version_test
cql_lease4_dump_test() {
test_start "cql.lease4_dump_test"
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
output_dir="@abs_top_builddir@/src/bin/admin/tests"
script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
output_file="$output_dir/data/cql.lease4_dump_test.output.csv"
tmp_file="$output_file.tmp"
ref_file="$test_dir/data/cql.lease4_dump_test.reference.csv"
# Wipe out any residuals from prior failed runs.
if [ -e $output_file ]
then
rm $output_file
fi
if [ -e $tmp_file ]
then
rm $tmp_file
fi
# Wipe the database.
cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql
assert_eq 0 $? "drop table query failed, exit code %d, expected %d"
# Create the database
$keaadmin lease-init cql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
assert_eq 0 $? "kea-admin lease-init cql failed, expected exit code: %d, actual: %d"
# Insert the reference record.
# -1073741302 corresponds to 192.0.2.10
# -1073741301 corresponds to 192.0.2.11
# -1073741300 corresponds to 192.0.2.12
# 1430694930 corresponds to 2015-04-04 01:15:30
# 1433464245 corresponds to 2015-05-05 02:30:45
# 1436173267 corresponds to 2015-06-06 11:01:07
insert_sql="\
insert into lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
values(-1073741302,textAsBlob('20'),textAsBlob('30'),40,1430694930,50,true,true,\
'one.example.com', 0);\
insert into lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
values(-1073741301,NULL,textAsBlob('123'),40,1433464245,50,true,true,'', 1);\
insert into lease4(address, hwaddr, client_id, valid_lifetime, expire, subnet_id,\
fqdn_fwd, fqdn_rev, hostname, state)\
values(-1073741300,textAsBlob('22'),NULL,40,1436173267,50,true,true,\
'three.example.com', 2);"
cql_execute "$insert_sql"
assert_eq 0 $? "insert into lease4 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file.
$keaadmin lease-dump cql -4 -u $db_user -p $db_password -n $db_name -d $db_scripts_dir -o $output_file
assert_eq 0 $? "kea-admin lease-dump -4 failed, expected exit code %d, actual %d"
# Compare the dump output to reference file, they should be identical.
cmp -s $output_file $ref_file
assert_eq 0 $? "dump file does not match reference file, expected exit code %d, actual %d"
# remove the output file.
rm $output_file
# Wipe the database.
cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql
assert_eq 0 $? "drop table query failed, exit code %d, expected %d"
test_finish 0
}
cql_lease6_dump_test() {
test_start "cql.lease6_dump_test"
test_dir="@abs_top_srcdir@/src/bin/admin/tests"
output_dir="@abs_top_builddir@/src/bin/admin/tests"
script_dir="@abs_top_srcdir@/src/bin/admin/scripts"
output_file="$output_dir/data/cql.lease6_dump_test.output.csv"
tmp_file="$output_file.tmp"
ref_file="$test_dir/data/cql.lease6_dump_test.reference.csv"
# Wipe out any residuals from prior failed runs.
if [ -e $output_file ]
then
rm $output_file
fi
if [ -e $tmp_file ]
then
rm $tmp_file
fi
# Wipe the database.
cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql
assert_eq 0 $? "drop table query failed, exit code %d, expected %d"
# Create the database.
$keaadmin lease-init cql -u $db_user -p $db_password -n $db_name -d $db_scripts_dir
assert_eq 0 $? "could not create database, expected exit code %d, actual %d"
# Insert the reference record.
# 1430694930 corresponds to 2015-04-04 01:15:30
# 1433464245 corresponds to 2015-05-05 02:30:45
# 1436173267 corresponds to 2015-06-06 11:01:07
insert_sql="\
insert into lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
values('2001:db8::10',textAsBlob('20'),30,1430694930,40,50,1,60,70,true,true,\
'one.example.com',textAsBlob('80'),90,16,0);\
insert into lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
values('2001:db8::11',NULL,30,1433464245,40,50,1,60,70,true,true,\
'',textAsBlob('80'),90,1,1);\
insert into lease6(address, duid, valid_lifetime, expire, subnet_id,\
pref_lifetime, lease_type, iaid, prefix_len, fqdn_fwd, fqdn_rev, hostname,\
hwaddr, hwtype, hwaddr_source, state)\
values('2001:db8::12',textAsBlob('21'),30,1436173267,40,50,1,60,70,true,true,\
'three.example.com',textAsBlob('80'),90,4,2);"
cql_execute "$insert_sql"
assert_eq 0 $? "insert into lease6 failed, expected exit code %d, actual %d"
# Dump lease4 to output_file.
$keaadmin lease-dump cql -6 -u $db_user -p $db_password -n $db_name -d $db_scripts_dir -o $output_file
assert_eq 0 $? "kea-admin lease-dump -6 failed, status code %d"
# Compare the dump output to reference file, they should be identical.
cmp -s $output_file $ref_file
assert_eq 0 $? "dump file does not match reference file, expected exit code %d, actual %d"
# remove the output file.
rm $output_file
# Wipe the database.
cql_execute_script $db_scripts_dir/cql/dhcpdb_drop.cql
assert_eq 0 $? "drop table query failed, exit code %d, expected %d"
test_finish 0
}
# Run tests.
cql_lease_init_test
cql_lease_version_test
cql_upgrade_test
cql_lease4_dump_test
cql_lease6_dump_test
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname
0.0.0.10,3230,3330,40,2015-01-01 01:15:30,50,1,1,one.example.com
0.0.0.11,,313233,40,2015-02-02 02:30:45,50,1,1,
0.0.0.12,3232,,40,2015-03-03 11:01:07,50,1,1,three.example.com
address,hwaddr,client_id,valid_lifetime,expire,subnet_id,fqdn_fwd,fqdn_rev,hostname,state
-1073741302,0x3230,0x3330,40,1430694930,50,True,True,one.example.com,0
-1073741301,null,0x313233,40,1433464245,50,True,True,,1
-1073741300,0x3232,null,40,1436173267,50,True,True,three.example.com,2
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source
10,3230,30,2015-04-04 01:15:30,40,50,IA_TA,60,70,1,1,one.example.com,3830,90,100
11,,30,2015-05-05 02:30:45,40,50,IA_TA,60,70,1,1,,3830,90,100
12,3231,30,2015-06-06 11:01:07,40,50,IA_TA,60,70,1,1,three.example.com,3830,90,100
address,duid,valid_lifetime,expire,subnet_id,pref_lifetime,lease_type,iaid,prefix_len,fqdn_fwd,fqdn_rev,hostname,hwaddr,hwtype,hwaddr_source,state
2001:db8::12,0x3231,30,1436173267,40,50,1,60,70,True,True,three.example.com,0x3830,90,4,2
2001:db8::11,null,30,1433464245,40,50,1,60,70,True,True,,0x3830,90,1,1
2001:db8::10,0x3230,30,1430694930,40,50,1,60,70,True,True,one.example.com,0x3830,90,16,0
......@@ -197,7 +197,8 @@ INSERT INTO lease_state (state, name) VALUES (2, 'expired-reclaimed');
-- This table is only modified during schema upgrades. For historical reasons
-- (related to the names of the columns in the BIND 10 DNS database file), the
-- first column is called "version" and not "major".
-- Note: This MUST be kept in step with src/share/database/scripts/cassandra/dhcpdb_create.cql,
-- which defines the schema for the unit tests.
CREATE TABLE schema_version (
version int,
minor int,
......
......@@ -36,7 +36,7 @@ CREATE TABLE lease4 (
) ENGINE = INNODB;
# Create search indexes for lease4 table
# Create search indexes for lease4 table.
# index by hwaddr and subnet_id
CREATE INDEX lease4_by_hwaddr_subnet_id ON lease4 (hwaddr, subnet_id);
......@@ -63,8 +63,8 @@ CREATE TABLE lease6 (
) ENGINE = INNODB;
# Create search indexes for lease4 table
# index by iaid, subnet_id, and duid
# Create search indexes for lease4 table.
# index by iaid, subnet_id, and duid
CREATE INDEX lease6_by_iaid_subnet_id_duid ON lease6 (iaid, subnet_id, duid);
# ... and a definition of lease6 types. This table is a convenience for
......@@ -86,11 +86,8 @@ COMMIT;
# This table is only modified during schema upgrades. For historical reasons
# (related to the names of the columns in the BIND 10 DNS database file), the
# first column is called "version" and not "major".
#
# NOTE: this MUST be kept in step with src/lib/dhcpsrv/tests/schema_copy.h,
# which defines the schema for the unit tests. If you are updating
# the version number, the schema has changed: please ensure that
# schema_copy.h has been updated as well.
# Note: This MUST be kept in step with src/share/database/scripts/mysql/dhcpdb_create.mysql,
# which defines the schema for the unit tests.
CREATE TABLE schema_version (
version INT PRIMARY KEY NOT NULL, # Major version number
minor INT # Minor version number
......
......@@ -83,11 +83,8 @@ COMMIT;
-- This table is only modified during schema upgrades. For historical reasons
-- (related to the names of the columns in the BIND 10 DNS database file), the
-- first column is called "version" and not "major".
-- NOTE: this MUST be kept in step with src/lib/dhcpsrv/tests/schema_copy.h,
-- which defines the schema for the unit tests. If you are updating
-- the version number, the schema has changed: please ensure that
-- schema_copy.h has been updated as well.
-- Note: This MUST be kept in step with src/share/database/scripts/pgsql/dhcpdb_create.pgsql,
-- which defines the schema for the unit tests.
CREATE TABLE schema_version (
version INT PRIMARY KEY NOT NULL, -- Major version number
minor INT -- Minor version number
......
......@@ -27,7 +27,7 @@ pgsql_wipe() {
printf "Wiping whole database %s\n" $db_name
export PGPASSWORD=$db_password
cat $db_scripts_dir/pgsql/dhcpdb_drop.pgsql | psql --set ON_ERROR_STOP=1 -A -t -q -U keatest -d keatest >/dev/null 2>&1
cat $db_scripts_dir/pgsql/dhcpdb_drop.pgsql | psql --set ON_ERROR_STOP=1 -A -t -h localhost -q -U keatest -d keatest >/dev/null 2>&1
assert_eq 0 $? "pgsql_wipe drop failed, expected exit code: %d, actual: %d"
}
......
......@@ -22,14 +22,16 @@ using namespace std;
namespace isc {
namespace dhcp {
CqlConnection::CqlConnection(const ParameterMap& parameters) : DatabaseConnection(parameters),
cluster_(NULL), session_(NULL), tagged_statements_(NULL) {
CqlConnection::CqlConnection(const ParameterMap& parameters) :
DatabaseConnection(parameters), cluster_(NULL), session_(NULL),
tagged_statements_(NULL) {
}
CqlConnection::~CqlConnection() {
// Free up the prepared statements, ignoring errors.
// Session and connection resources are deallocated.
CassError rc;
for (int i = 0; i < statements_.size(); i++)
{
for (int i = 0; i < statements_.size(); i++) {
if (statements_[i]) {
cass_prepared_free(statements_[i]);
}
......@@ -60,7 +62,7 @@ CqlConnection::openDatabase() {
scontact_points = getParameter("contact_points");
contact_points = scontact_points.c_str();
} catch (...) {
// No host. Fine, we'll use "localhost"
// No host. Fine, we'll use "localhost".
}
const char* port = NULL;
......@@ -69,7 +71,7 @@ CqlConnection::openDatabase() {
sport = getParameter("port");
port = sport.c_str();
} catch (...) {
// No port. Fine, we'll use "default"
// No port. Fine, we'll use "default".
}
const char* user = NULL;
......@@ -78,7 +80,7 @@ CqlConnection::openDatabase() {
suser = getParameter("user");
user = suser.c_str();
} catch (...) {
// No user. Fine, we'll use NULL
// No user. Fine, we'll use NULL.
}
const char* password = NULL;
......@@ -87,7 +89,7 @@ CqlConnection::openDatabase() {
spassword = getParameter("password");
password = spassword.c_str();
} catch (...) {
// No password. Fine, we'll use NULL
// No password. Fine, we'll use NULL.
}
const char* keyspace = "keatest";
......@@ -96,7 +98,7 @@ CqlConnection::openDatabase() {
skeyspace = getParameter("keyspace");
keyspace = skeyspace.c_str();
} catch (...) {
// No database name. Fine, we'll use default 'keatest'
// No database name. Fine, we'll use default "keatest".
}
cluster_ = cass_cluster_new();
......@@ -202,8 +204,7 @@ CqlConnection::rollback() {
void
CqlConnection::checkStatementError(std::string& error, CassFuture* future,
uint32_t stindex, const char* what) const
{
uint32_t stindex, const char* what) const {
CassError rc;
const char* errorMessage;
size_t errorMessageSize;
......@@ -215,15 +216,15 @@ CqlConnection::checkStatementError(std::string& error, CassFuture* future,
if (rc != CASS_OK) {
stream.str(std::string());
stream << what << " for: " << tagged_statements_[stindex].name_ << " reason: " <<
errorMessage << " error code: " << rc;
stream << what << " for: " << tagged_statements_[stindex].name_ <<
" reason: " << errorMessage << " error code: " << rc;
}
error = stream.str();
}
void
CqlConnection::checkStatementError(std::string& error, CassFuture* future, const char* what) const
{
CqlConnection::checkStatementError(std::string& error, CassFuture* future,
const char* what) const {
CassError rc;
const char* errorMessage;
size_t errorMessageSize;
......
......@@ -27,20 +27,19 @@ namespace isc {
namespace dhcp {
/// @brief Defines a single query
///
/// @param params_ Bind parameter names
/// @param name_ Short name of the query.
/// @param text_ Text representation of the actual query.
struct CqlTaggedStatement {
/// Param name.
const char** params_;
/// Short name of the query.
const char* name_;
/// Text representation of the actual query.
const char* text_;
};
/// Defines CQL backend version: 1.0
const uint32_t CQL_CURRENT_VERSION = 1;
const uint32_t CQL_CURRENT_MINOR = 0;
// Defines CQL backend version: 2.3
const uint32_t CQL_CURRENT_VERSION = CASS_VERSION_MAJOR;
const uint32_t CQL_CURRENT_MINOR = CASS_VERSION_MINOR;
class CqlConnection : public DatabaseConnection {
public:
......@@ -55,28 +54,26 @@ public:
/// @brief Prepare statements
///
/// Creates the prepared statements for all of the SQL statements used
/// Creates the prepared statements for all of the CQL statements used
/// by the CQL backend.
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
/// @throw isc::InvalidParameter 'index' is not valid for the vector. This
/// @throw isc::InvalidParameter 'index' is not valid for the vector. This
/// represents an internal error within the code.
void prepareStatements(CqlTaggedStatement *statements);
/// @brief Open Database
///
/// Opens the database using the information supplied in the parameters
/// passed to the constructor.
/// passed to the constructor. If no parameters are supplied, the default
/// values will be used (keyspace keatest).
///
/// @throw NoDatabaseName Mandatory database name not given
/// @throw DbOpenError Error opening the database
void openDatabase();
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
///
/// @return Type of the backend.
virtual std::string getType() const {
return (std::string("cql"));
......@@ -96,7 +93,7 @@ public:
/// @brief Returns backend version.
///
/// @return Version number as a pair of unsigned integers. "first" is the
/// @return Version number as a pair of unsigned integers. "first" is the
/// major version number, "second" the minor number.
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
......@@ -129,10 +126,18 @@ public:
void checkStatementError(std::string& error, CassFuture* future,
const char* what) const;
/// CQL connection handle
/// @brief CQL connection handle
CassCluster* cluster_;
/// @brief CQL session handle
CassSession* session_;
std::vector<const CassPrepared*> statements_; ///< Prepared statements
/// @brief CQL prepared statements - used for faster statement execution using
/// bind functionality
std::vector<const CassPrepared*> statements_;
/// @brief Pointer to external array of tagged statements containing statement
/// name, array of names of bind parameters and text query
CqlTaggedStatement* tagged_statements_;
};
......
This diff is collapsed.
......@@ -34,7 +34,7 @@ namespace dhcp {
/// CQL execute call.
///
/// Note that the data values are stored as pointers. These pointers need to
/// valid for the duration of the CQL statement execution. In other
/// valid for the duration of the CQL statement execution. In other
/// words populating them with pointers to values that go out of scope before
/// statement is executed is a bad idea.
......@@ -45,20 +45,24 @@ struct CqlDataArray {
values_.push_back(value);
}
void remove(int index) {
if (values_.size() <= index) {
isc_throw(BadValue, "Index " << index << " out of bounds: [0, " <<
(values_.size() - 1) << "]");
}
values_.erase(values_.begin() + index);
}
};
class CqlExchange;
class CqlVersionExchange;
class CqlLeaseExchange;
class CqlLease4Exchange;
class CqlLease6Exchange;
/// @brief Cassandra Lease Manager
///
/// This class provides the \ref isc::dhcp::LeaseMgr interface to the CQL - Cassandra
/// database. Use of this backend presupposes that a CQL database is
/// available and that the Kea schema has been created within it.
/// This class provides the \ref isc::dhcp::LeaseMgr interface to the Cassandra
/// database. Use of this backend presupposes that a CQL database is available
/// and that the Kea schema has been created within it.
class CqlLeaseMgr : public LeaseMgr {
public:
......@@ -314,7 +318,7 @@ public:
/// @brief Deletes a lease.
///
/// @param addr Address of the lease to be deleted. This can be an IPv4
/// @param addr Address of the lease to be deleted. This can be an IPv4
/// address or an IPv6 address.
///
/// @return true if deletion was successful, false if no such lease exists
......@@ -343,8 +347,6 @@ public:
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
///
/// @return Type of the backend.
virtual std::string getType() const {
return (std::string("cql"));
......@@ -364,7 +366,7 @@ public:
/// @brief Returns backend version.
///
/// @return Version number as a pair of unsigned integers. "first" is the
/// @return Version number as a pair of unsigned integers. "first" is the
/// major version number, "second" the minor number.
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
......@@ -373,16 +375,12 @@ public:
/// @brief Commit Transactions
///
/// Commits all pending database operations.
///
/// @throw DbOperationError If the commit failed.
/// This is a no-op for Cassandra.
virtual void commit();
/// @brief Rollback Transactions
///
/// Rolls back all pending database operations.
///
/// @throw DbOperationError If the rollback failed.
/// This is a no-op for Cassandra.
virtual void rollback();
......@@ -412,30 +410,61 @@ public:
UPDATE_LEASE6, // Update a Lease6 entry
NUM_STATEMENTS // Number of statements
};
static void bindData(CassStatement* statement, const StatementIndex stindex, CqlDataArray& data, const SqlExchange& exchange);
static void getDataType(const StatementIndex stindex, int param, const SqlExchange& exchange, ExchangeDataType& type);
/// @brief TODO
///
/// TODO
///
/// @param statement TODO
/// @param stindex Index of statement being executed
/// @param data array that has been created for the type of lease in question.
/// @param exchange Exchange object to use
static void bindData(CassStatement* statement, const StatementIndex stindex,
CqlDataArray& data, const SqlExchange& exchange);
/// @brief TODO
///
/// TODO
///
/// @param stindex Index of statement being executed
/// @param param TODO
/// @param exchange Exchange object to use
/// @param type TODO
static void getDataType(const StatementIndex stindex, int param,
const SqlExchange& exchange, ExchangeDataType& type);
static void getData(const CassRow* row, int pindex, CqlDataArray& data, CqlDataArray& size, const SqlExchange& exchange);
/// @brief TODO
///
/// TODO
///
/// @param row TODO
/// @param pindex Index of statement being executed
/// @param data array that has been created for the type of lease in question.
/// @param data size TODO
/// @param exchange Exchange object to use
static void getData(const CassRow* row, int pindex, CqlDataArray& data,
CqlDataArray& size, const SqlExchange& exchange);
private:
/// @brief Add Lease Common Code
///
/// This method performs the common actions for both flavours (V4 and V6)
/// of the addLease method. It binds the contents of the lease object to
/// of the addLease method. It binds the contents of the lease object to
/// the prepared statement and adds it to the database.
///
/// @param stindex Index of statement being executed
/// @param data array that has been created for the type
/// of lease in question.
/// @param exchange Exchange object to use
///
/// @return true if the lease was added, false if it was not added because
/// a lease with that address already exists in the database.
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
bool addLeaseCommon(StatementIndex stindex, CqlDataArray& data, CqlLeaseExchange& exchange);
bool addLeaseCommon(StatementIndex stindex, CqlDataArray& data,
CqlLeaseExchange& exchange);
/// @brief Get Lease Collection Common Code
///
......@@ -464,12 +493,12 @@ private:
/// @brief Gets Lease4 Collection
///
/// Gets a collection of Lease4 objects. This is just an interface to
/// Gets a collection of Lease4 objects. This is just an interface to
/// the get lease collection common code.
///
/// @param stindex Index of statement being executed
/// @param data array containing the where clause input parameters
/// @param lease LeaseCollection object returned. Note that any leases in
/// @param result LeaseCollection object returned. Note that any leases in
/// the collection when this method is called are not erased: the
/// new data is appended to the end.
///
......@@ -485,12 +514,12 @@ private:
/// @brief Get Lease6 Collection
///
/// Gets a collection of Lease6 objects. This is just an interface to