LCOV - code coverage report
Current view: top level - core/db/sql - SPSqlDriver.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 8 62.5 %
Date: 2024-05-12 00:16:13 Functions: 3 6 50.0 %

          Line data    Source code
       1             : /**
       2             : Copyright (c) 2021-2022 Roman Katuntsev <sbkarr@stappler.org>
       3             : Copyright (c) 2023-2024 Stappler LLC <admin@stappler.dev>
       4             : 
       5             : Permission is hereby granted, free of charge, to any person obtaining a copy
       6             : of this software and associated documentation files (the "Software"), to deal
       7             : in the Software without restriction, including without limitation the rights
       8             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             : copies of the Software, and to permit persons to whom the Software is
      10             : furnished to do so, subject to the following conditions:
      11             : 
      12             : The above copyright notice and this permission notice shall be included in
      13             : all copies or substantial portions of the Software.
      14             : 
      15             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             : THE SOFTWARE.
      22             : **/
      23             : 
      24             : #ifndef STAPPLER_DB_SQL_SPSQLDRIVER_H_
      25             : #define STAPPLER_DB_SQL_SPSQLDRIVER_H_
      26             : 
      27             : #include "SPDbBackendInterface.h"
      28             : #include "SPDbField.h"
      29             : 
      30             : namespace STAPPLER_VERSIONIZED stappler::db::sql {
      31             : 
      32             : class Driver;
      33             : 
      34             : struct QueryStorageHandle {
      35             :         const Driver *driver;
      36             :         StringView name;
      37             :         Map<StringView, const void *> *data;
      38             : 
      39             :         QueryStorageHandle(const Driver *d, StringView n, Map<StringView, const void *> *);
      40             :         ~QueryStorageHandle();
      41             : 
      42             :         QueryStorageHandle(const QueryStorageHandle &) = delete;
      43             :         QueryStorageHandle& operator=(const QueryStorageHandle &) = delete;
      44             : 
      45             :         QueryStorageHandle(QueryStorageHandle &&);
      46             :         QueryStorageHandle& operator=(QueryStorageHandle &&);
      47             : 
      48        3625 :         void clear() {
      49        3625 :                 data->clear();
      50        3625 :         }
      51             : };
      52             : 
      53             : class Driver : public AllocBase {
      54             : public:
      55             :         using Handle = stappler::ValueWrapper<void *, class HandleClass>;
      56             :         using Result = stappler::ValueWrapper<void *, class ResultClass>;
      57             :         using Connection = stappler::ValueWrapper<void *, class ConnectionClass>;
      58             : 
      59             :         static Driver *open(pool_t *, ApplicationInterface *, StringView path = StringView(), const void *external = nullptr);
      60             : 
      61             :         virtual ~Driver();
      62             : 
      63          50 :         StringView getDriverName() const { return _driverPath; }
      64       13048 :         ApplicationInterface *getApplicationInterface() const { return _application; }
      65             : 
      66             :         virtual bool init(Handle handle, const Vector<StringView> &) = 0;
      67             : 
      68             :         virtual void performWithStorage(Handle handle, const Callback<void(const db::Adapter &)> &cb) const = 0;
      69             :         virtual BackendInterface *acquireInterface(Handle handle, pool_t *) const = 0;
      70             : 
      71             :         virtual Handle connect(const Map<StringView, StringView> &) const = 0;
      72             :         virtual void finish(Handle) const = 0;
      73             : 
      74             :         virtual Connection getConnection(Handle h) const = 0;
      75             : 
      76             :         virtual bool isValid(Handle) const = 0;
      77             :         virtual bool isValid(Connection) const = 0;
      78             :         virtual bool isIdle(Connection) const = 0;
      79             : 
      80             :         virtual Time getConnectionTime(Handle) const = 0;
      81             : 
      82           0 :         virtual int listenForNotifications(Handle) const { return -1; }
      83           0 :         virtual bool consumeNotifications(Handle, const Callback<void(StringView)> &) const { return true; }
      84             : 
      85           0 :         virtual bool isNotificationsSupported() const { return false; }
      86             : 
      87             :         void setDbCtrl(Function<void(bool)> &&);
      88             : 
      89             :         const CustomFieldInfo *getCustomFieldInfo(StringView) const;
      90             : 
      91             :         QueryStorageHandle makeQueryStorage(StringView) const;
      92             : 
      93             :         Map<StringView, const void *> *getQueryStorage(StringView) const;
      94             :         Map<StringView, const void *> *getCurrentQueryStorage() const;
      95             : 
      96             : protected:
      97             :         friend struct QueryStorageHandle;
      98             : 
      99             :         Map<StringView, const void *> *registerQueryStorage(StringView) const;
     100             :         void unregisterQueryStorage(StringView) const;
     101             : 
     102             :         Driver(pool_t *, ApplicationInterface *);
     103             : 
     104             :         StringView _driverPath;
     105             :         Function<void(bool)> _dbCtrl = nullptr;
     106             :         pool_t *_pool = nullptr;
     107             :         ApplicationInterface *_application = nullptr;
     108             : 
     109             :         Map<StringView, CustomFieldInfo> _customFields;
     110             : };
     111             : 
     112             : }
     113             : 
     114             : #endif /* STAPPLER_DB_SQL_SPSQLDRIVER_H_ */

Generated by: LCOV version 1.14