/// string if no limits are exceeded
virtual std::string checkLimits6(isc::data::ConstElementPtr const& user_context) const = 0;
+ /// @brief Checks if JSON support is enabled in the database.
+ /// Abstract method.
+ ///
+ /// @return true if there is JSON support, false otherwise
+ virtual bool isJsonSupported() const = 0;
+
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
isc_throw(NotImplemented, "Memfile_LeaseMgr::checkLimits4() not implemented");
}
+bool
+Memfile_LeaseMgr::isJsonSupported() const {
+ return true;
+}
+
} // namespace dhcp
} // namespace isc
-
/// string if no limits are exceeded
std::string checkLimits6(isc::data::ConstElementPtr const& user_context) const override;
+ /// @brief Checks if JSON support is enabled in the database.
+ /// Memfile implementation assumes JSON support is always enabled.
+ ///
+ /// @return true if there is JSON support, false otherwise
+ bool isJsonSupported() const override;
+
private:
/// @name Internal methods called while holding the mutex in multi threading
// TODO: remove single quotes from the following two SELECTs when the functions are implemented
{MySqlLeaseMgr::CHECK_LEASE4_LIMITS, "SELECT 'checkLease4Limits(?)'"},
{MySqlLeaseMgr::CHECK_LEASE6_LIMITS, "SELECT 'checkLease6Limits(?)'"},
+ {MySqlLeaseMgr::IS_JSON_SUPPORTED, "SELECT isJsonSupported()"},
} }; // tagged_statements
} // namespace
isc_throw(NotImplemented, "wipeLeases6 is not implemented for MySQL backend");
}
+bool
+MySqlLeaseMgr::isJsonSupported() const {
+ // Get a context.
+ MySqlLeaseContextAlloc get_context(*this);
+ MySqlLeaseContextPtr ctx = get_context.ctx_;
+
+ // Create bindings.
+ MySqlBindingCollection in_bindings;
+ MySqlBindingCollection out_bindings({
+ MySqlBinding::createBool()
+ });
+
+ // Execute the select.
+ bool json_supported(false);
+ ctx->conn_.selectQuery(IS_JSON_SUPPORTED, in_bindings, out_bindings,
+ [&json_supported] (MySqlBindingCollection const& result) {
+ json_supported = result[0]->getBool();
+ });
+
+ return json_supported;
+}
+
// Miscellaneous database methods.
std::string
/// @return number of leases removed.
virtual size_t wipeLeases6(const SubnetID& subnet_id);
+ /// @brief Checks if JSON support is enabled in the database.
+ /// MySQL implementation.
+ ///
+ /// @return true if there is JSON support, false otherwise
+ bool isJsonSupported() const override;
+
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
SUBNET_RANGE_LEASE6_STATS, // Fetched IPv6 lease stats for a subnet range.
CHECK_LEASE4_LIMITS, // Check if allocated IPv4 leases are inside the set limits.
CHECK_LEASE6_LIMITS, // Check if allocated IPv6 leases are inside the set limits.
+ IS_JSON_SUPPORTED, // Checks if JSON support is enabled in the database.
NUM_STATEMENTS // Number of statements
};
isc_throw(NotImplemented, "wipeLeases6 is not implemented for PostgreSQL backend");
}
+bool
+PgSqlLeaseMgr::isJsonSupported() const {
+ isc_throw(NotImplemented, "PgSqlLeaseMgr::isJsonSupported() not implemented");
+}
+
std::string
PgSqlLeaseMgr::getName() const {
// Get a context
/// @return number of leases removed.
virtual size_t wipeLeases6(const SubnetID& subnet_id);
+ /// @brief Checks if JSON support is enabled in the database.
+ /// PostgreSQL implementation.
+ ///
+ /// @return true if there is JSON support, false otherwise
+ bool isJsonSupported() const override;
+
/// @brief Return backend type
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
isc_throw(NotImplemented, "ConcreteLeaseMgr::checkLimits6() not implemented");
}
+ /// @brief Checks if JSON support is enabled in the database.
+ ///
+ /// @return true if there is JSON support, false otherwise
+ bool isJsonSupported() const override {
+ isc_throw(NotImplemented, "ConcreteLeaseMgr::isJsonSupported() not implemented");
+ }
+
/// @brief Returns backend type.
///
/// Returns the type of the backend (e.g. "mysql", "memfile" etc.)
testLeaseStatsQueryAttribution6();
}
+/// @brief Checks that no exceptions are thrown when inquiring about JSON
+/// support and prints an informative message.
+TEST_F(MySqlLeaseMgrTest, isJsonSupported) {
+ bool json_supported;
+ ASSERT_NO_THROW(json_supported = LeaseMgrFactory::instance().isJsonSupported());
+ std::cout << "JSON support is " << (json_supported ? "" : "not ") <<
+ "enabled in the database." << std::endl;
+}
+
} // namespace
return (createInteger<float>(value));
}
+MySqlBindingPtr
+MySqlBinding::createBool() {
+ return (createInteger<uint8_t>(static_cast<uint8_t>(false)));
+}
+
MySqlBindingPtr
MySqlBinding::createBool(const bool value) {
return (createInteger<uint8_t>(static_cast<uint8_t>(value)));
createInteger<float> (static_cast<float>(value.get())));
}
+ /// @brief Creates binding having a bool type for receiving data.
+ ///
+ /// @return Pointer to the created binding holding an @c uint8_t
+ /// value representing the boolean value.
+ static MySqlBindingPtr createBool();
+
/// @brief Creates binding having a bool type for sending data.
///
/// @param value Boolean value to be sent to the database.