LCOV - code coverage report
Current view: top level - core/db - SPDbObject.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 27 18.5 %
Date: 2024-05-12 00:16:13 Functions: 2 8 25.0 %

          Line data    Source code
       1             : /**
       2             : Copyright (c) 2016-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             : #include "SPDbObject.h"
      25             : #include "SPDbScheme.h"
      26             : 
      27             : namespace STAPPLER_VERSIONIZED stappler::db {
      28             : 
      29         800 : Object::Object(Value &&data, const Scheme &scheme) : WrapperTemplate(std::move(data)), _scheme(scheme) {
      30         800 :         if (!_data.isDictionary()) {
      31           0 :                 _data = Value(Value::Type::DICTIONARY);
      32           0 :                 _oid = 0;
      33             :         } else {
      34         800 :                 _oid = _data.getInteger("__oid");
      35             :         }
      36         800 : }
      37             : 
      38           0 : const Scheme &Object::getScheme() const { return _scheme; }
      39        1400 : uint64_t Object::getObjectId() const { return _oid; }
      40             : 
      41           0 : void Object::lockProperty(const StringView &prop) {
      42           0 :         _locked.insert(prop.str<Interface>());
      43           0 : }
      44           0 : void Object::unlockProperty(const StringView &prop) {
      45           0 :         _locked.erase(prop.str<Interface>());
      46           0 : }
      47           0 : bool Object::isPropertyLocked(const StringView &prop) const {
      48           0 :         return _locked.find(prop) != _locked.end();
      49             : }
      50             : 
      51           0 : bool Object::isFieldProtected(const StringView &key) const {
      52           0 :         return _scheme.isProtected(key);
      53             : }
      54             : 
      55           0 : bool Object::save(const Adapter &a, bool force) {
      56           0 :         if (_modified || force) {
      57           0 :                 _modified = false;
      58           0 :                 bool ret = false;
      59           0 :                 if (auto t = Transaction::acquire(a)) {
      60           0 :                         ret = _scheme.save(t, this);
      61           0 :                         t.release();
      62             :                 }
      63           0 :                 return ret;
      64             :         }
      65           0 :         return true;
      66             : }
      67             : 
      68             : }

Generated by: LCOV version 1.14