#pragma once #include #if USE_CASSANDRA #include #include #include namespace DB { namespace Cassandra { template CassT * defaultCtor() { return nullptr; } /// RAII wrapper for raw pointers to objects from cassandra driver library template> class ObjectHolder { CassT * ptr = nullptr; public: template ObjectHolder(Args &&... args) : ptr(Ctor(std::forward(args)...)) {} /// NOLINT ObjectHolder(CassT * ptr_) : ptr(ptr_) {} /// NOLINT ObjectHolder(const ObjectHolder &) = delete; ObjectHolder & operator = (const ObjectHolder &) = delete; ObjectHolder(ObjectHolder && rhs) noexcept : ptr(rhs.ptr) { rhs.ptr = nullptr; } ObjectHolder & operator = (ObjectHolder && rhs) noexcept { if (ptr) Dtor(ptr); ptr = rhs.ptr; rhs.ptr = nullptr; return *this; } ~ObjectHolder() { if (ptr) Dtor(ptr); } /// For implicit conversion when passing object to driver library functions operator CassT * () { return ptr; } /// NOLINT operator const CassT * () const { return ptr; } /// NOLINT }; } /// These object are created on pointer construction using CassClusterPtr = Cassandra::ObjectHolder; using CassStatementPtr = Cassandra::ObjectHolder; using CassSessionPtr = Cassandra::ObjectHolder; /// Share connections between streams. Executing statements in one session object is thread-safe using CassSessionShared = std::shared_ptr; using CassSessionWeak = std::weak_ptr; /// The following objects are created inside Cassandra driver library, /// but must be freed by user code using CassFuturePtr = Cassandra::ObjectHolder; using CassResultPtr = Cassandra::ObjectHolder; using CassIteratorPtr = Cassandra::ObjectHolder; /// Checks return code, throws exception on error void cassandraCheck(CassError code); void cassandraWaitAndCheck(CassFuturePtr & future); /// By default driver library prints logs to stderr. /// It should be redirected (or, at least, disabled) before calling other functions from the library. void setupCassandraDriverLibraryLogging(CassLogLevel level); void cassandraLogCallback(const CassLogMessage * message, void * data); } #endif