LCOV - code coverage report
Current view: top level - core/db - SPDb.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 11 100.0 %
Date: 2024-05-12 00:16:13 Functions: 10 10 100.0 %

          Line data    Source code
       1             : /**
       2             : Copyright (c) 2019-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_SPDB_H_
      25             : #define STAPPLER_DB_SPDB_H_
      26             : 
      27             : #include "SPMemUserData.h"
      28             : #include "SPMemory.h"
      29             : #include "SPData.h"
      30             : #include "SPSql.h"
      31             : #include "SPDbConfig.h"
      32             : #include "SPSearchConfiguration.h"
      33             : 
      34             : namespace STAPPLER_VERSIONIZED stappler::db {
      35             : 
      36             : using namespace mem_pool;
      37             : using namespace stappler::sql;
      38             : 
      39             : struct InputFile;
      40             : 
      41             : class Adapter;
      42             : class Transaction;
      43             : class Worker;
      44             : 
      45             : class Query;
      46             : class BackendInterface;
      47             : class Binder;
      48             : class QueryInterface;
      49             : class ResultCursor;
      50             : 
      51             : class Scheme;
      52             : class Field;
      53             : class Object;
      54             : class User;
      55             : 
      56             : struct FieldText;
      57             : struct FieldPassword;
      58             : struct FieldExtra;
      59             : struct FieldFile;
      60             : struct FieldImage;
      61             : struct FieldObject;
      62             : struct FieldArray;
      63             : struct FieldView;
      64             : struct FieldFullTextView;
      65             : struct FieldCustom;
      66             : 
      67             : using FullTextRank = search::SearchRank;
      68             : using FullTextData = search::SearchData;
      69             : using FullTextVector = search::SearchVector;
      70             : using FullTextQuery = search::SearchQuery;
      71             : 
      72             : struct RequestData {
      73             :         bool exists = false;
      74             :         StringView address;
      75             :         StringView hostname;
      76             :         StringView uri;
      77             : 
      78          50 :         explicit operator bool() { return exists; }
      79             : };
      80             : 
      81             : struct InputConfig {
      82             :         enum class Require {
      83             :                 None = 0,
      84             :                 Data = 1,
      85             :                 Files = 2,
      86             :                 Body = 4,
      87             :                 FilesAsData = 8,
      88             :         };
      89             : 
      90             :         static bool isFileAsDataSupportedForType(StringView);
      91             : 
      92             :         void updateLimits(const Map<String, Field> &vec);
      93             : 
      94             :         Require required = Require::None;
      95             :         size_t maxRequestSize = config::INPUT_MAX_REQUEST_SIZE;
      96             :         size_t maxVarSize = config::INPUT_MAX_VAR_SIZE;
      97             :         size_t maxFileSize = config::INPUT_MAX_FILE_SIZE;
      98             : 
      99             :         TimeInterval updateTime = config::INPUT_UPDATE_TIME;
     100             :         float updateFrequency = config::INPUT_UPDATE_FREQUENCY;
     101             : };
     102             : 
     103             : SP_DEFINE_ENUM_AS_MASK(InputConfig::Require);
     104             : 
     105             : struct InputFile : public AllocBase {
     106             :         String path;
     107             :         String name;
     108             :         String type;
     109             :         String encoding;
     110             :         String original;
     111             :         filesystem::File file;
     112             : 
     113             :         bool isBinary = false;
     114             :         size_t writeSize;
     115             :         size_t headerSize;
     116             :         int64_t id;
     117             : 
     118             :         InputFile(String && name, String && type, String && enc, String && orig, size_t s, int64_t id);
     119             :         ~InputFile();
     120             : 
     121             :         bool isOpen() const;
     122             : 
     123             :         size_t write(const char *, size_t);
     124             :         void close();
     125             : 
     126             :         bool save(const StringView &) const;
     127             :         Bytes readBytes();
     128             :         String readText();
     129             : 
     130         100 :         int64_t negativeId() const { return - id - 1; }
     131             : 
     132             :         InputFile(const InputFile &) = delete;
     133         125 :         InputFile(InputFile &&) = default;
     134             : 
     135             :         InputFile &operator=(const InputFile &) = delete;
     136             :         InputFile &operator=(InputFile &&) = default;
     137             : };
     138             : 
     139             : struct InputValue {
     140             :         enum class Type {
     141             :                 None,
     142             :                 Value,
     143             :                 File,
     144             :                 TSV
     145             :         };
     146             : 
     147             :         Type type;
     148             :         union {
     149             :                 Value value;
     150             :                 InputFile *file;
     151             :                 FullTextVector tsv;
     152             :         };
     153             : 
     154         900 :         bool hasValue() const {
     155         900 :                 return type == Type::Value && !value.empty();
     156             :         }
     157             : 
     158             :         InputValue() : type(Type::None) { }
     159       36525 :         InputValue(Value &&val) : type(Type::Value), value(move(val)) { }
     160        2550 :         InputValue(FullTextVector &&val) : type(Type::TSV), tsv(move(val)) { }
     161             : 
     162             :         InputValue(InputValue &&);
     163             :         InputValue &operator=(InputValue &&);
     164             : 
     165             :         InputValue(const InputValue &);
     166             :         InputValue &operator=(const InputValue &);
     167             : 
     168             :         void clear();
     169             : 
     170             :         ~InputValue();
     171             : };
     172             : 
     173             : struct InputField {
     174             :         const Field *field = nullptr;
     175             : 
     176       25000 :         bool operator==(const InputField &other) const { return field == other.field; }
     177          50 :         bool operator!=(const InputField &other) const { return field != other.field; }
     178         125 :         bool operator<(const InputField &other) const { return field < other.field; }
     179             : };
     180             : 
     181             : struct InputRow {
     182             :         Vector<InputValue> values;
     183             : 
     184        6250 :         InputRow() = default;
     185             : };
     186             : 
     187             : }
     188             : 
     189             : #endif /* STAPPLER_DB_SPDB_H_ */

Generated by: LCOV version 1.14