From cfd36be2e03970a836248ea7fe82eaa20c8a4e6f Mon Sep 17 00:00:00 2001
From: Marko Budiselic <mbudiselicbuda@gmail.com>
Date: Wed, 30 Nov 2016 11:05:48 +0100
Subject: [PATCH] All possible request changes from D9#146 are done

---
 include/database/db_transaction.hpp          | 14 ++++++----
 include/storage/label/labels_writer.hpp      |  8 ++++++
 include/storage/vertex_accessor.hpp          |  9 +++----
 include/utils/memory/stack_allocator.hpp     |  2 +-
 include/utils/string_buffer.hpp              | 19 ++++++++++++++
 src/database/db_transaction.cpp              | 27 ++++++++++----------
 src/storage/indexes/index_record.cpp         |  2 +-
 tests/integration/_hardcoded_query/basic.hpp |  4 +--
 tests/integration/queries.cpp                |  1 -
 9 files changed, 57 insertions(+), 29 deletions(-)

diff --git a/include/database/db_transaction.hpp b/include/database/db_transaction.hpp
index f0f7806d1..7b738bb39 100644
--- a/include/database/db_transaction.hpp
+++ b/include/database/db_transaction.hpp
@@ -19,15 +19,19 @@ class DbTransaction : public Loggable
     friend DbAccessor;
 
 public:
-    DbTransaction(Db &db);
-    DbTransaction(Db &db, tx::Transaction &trans)
-        : Loggable("DbTransaction"), db(db), trans(trans)
-    {
-    }
+    DbTransaction() = delete;
+    ~DbTransaction() = default; 
 
     DbTransaction(const DbTransaction& other) = delete;
     DbTransaction(DbTransaction&& other) = default;
 
+    DbTransaction &operator=(const DbTransaction &) = delete;
+    DbTransaction &operator=(DbTransaction &&) = default;
+
+    DbTransaction(Db &db);
+    DbTransaction(Db &db, tx::Transaction &trans)
+        : Loggable("DbTransaction"), db(db), trans(trans) {}
+
     // Global transactional algorithms,operations and general methods meant for
     // internal use should be here or should be routed through this object.
     // This should provide cleaner hierarchy of operations on database.
diff --git a/include/storage/label/labels_writer.hpp b/include/storage/label/labels_writer.hpp
index a495bae81..a075766b1 100644
--- a/include/storage/label/labels_writer.hpp
+++ b/include/storage/label/labels_writer.hpp
@@ -8,6 +8,14 @@ class LabelsWriter
 public:
     LabelsWriter(Buffer &buffer) : buffer_(buffer) {}
 
+    ~LabelsWriter() = default;
+
+    LabelsWriter(const LabelsWriter &) = delete;
+    LabelsWriter(LabelsWriter &&)      = delete;
+
+    LabelsWriter &operator=(const LabelsWriter &) = delete;
+    LabelsWriter &operator=(LabelsWriter &&) = delete;
+
     void handle(const Label& label);
     
 private:
diff --git a/include/storage/vertex_accessor.hpp b/include/storage/vertex_accessor.hpp
index 13d39380a..4d661b0cc 100644
--- a/include/storage/vertex_accessor.hpp
+++ b/include/storage/vertex_accessor.hpp
@@ -56,10 +56,9 @@ public:
     template <typename Stream>
     void stream_repr(Stream& stream) const
     {
-        if (this->record != nullptr)
-            this->record->stream_repr(stream);
-        else
-            std::cout << "TRACE: record is nullptr" << std::endl;
-            
+        if (!this->record)
+            return;
+
+        this->record->stream_repr(stream);
     }
 };
diff --git a/include/utils/memory/stack_allocator.hpp b/include/utils/memory/stack_allocator.hpp
index f69f565b3..287bdad6a 100644
--- a/include/utils/memory/stack_allocator.hpp
+++ b/include/utils/memory/stack_allocator.hpp
@@ -102,7 +102,7 @@ public:
     // Relases all memory.
     void free()
     {
-        while (allocated_blocks.size() > 0)
+        while (allocated_blocks.size())
         {
             blocks.release(allocated_blocks.back());
             allocated_blocks.pop_back();
diff --git a/include/utils/string_buffer.hpp b/include/utils/string_buffer.hpp
index 90303c632..f18ad5c3d 100644
--- a/include/utils/string_buffer.hpp
+++ b/include/utils/string_buffer.hpp
@@ -8,6 +8,25 @@ namespace utils
 class StringBuffer
 {
 public:
+    StringBuffer() = default;
+    ~StringBuffer() = default;
+
+    StringBuffer(const StringBuffer &) = delete;
+    StringBuffer(StringBuffer &&)      = default;
+
+    StringBuffer &operator=(const StringBuffer &) = delete;
+    StringBuffer &operator=(StringBuffer &&) = default;
+
+    StringBuffer(std::string::size_type count)
+    {
+        resize(count);
+    }
+
+    void resize(std::string::size_type count)
+    {
+        data.resize(count);
+    }
+
     StringBuffer &operator<<(const std::string &str)
     {
         data += str;
diff --git a/src/database/db_transaction.cpp b/src/database/db_transaction.cpp
index 7c57fa1d3..2f24cd1a6 100644
--- a/src/database/db_transaction.cpp
+++ b/src/database/db_transaction.cpp
@@ -8,12 +8,6 @@
 #include "storage/label/label.hpp"
 #include "storage/vertex.hpp"
 
-#define TRY(x)                                                                 \
-    if (!x)                                                                    \
-    {                                                                          \
-        return false;                                                          \
-    }
-
 DbTransaction::DbTransaction(Db &db)
     : Loggable("DbTransaction"), db(db), trans(db.tx_engine.begin())
 {
@@ -75,11 +69,14 @@ bool DbTransaction::update_indexes()
 
             // TODO: This could be done in batch
             // NOTE: This assumes that type index is created with the database.
-            TRY(edge.record->data.edge_type->index().insert(EdgeTypeIndexRecord(
-                std::nullptr_t(), edge.record, edge.vlist)));
+            if (!edge.record->data.edge_type->index().insert(
+                    EdgeTypeIndexRecord(std::nullptr_t(), edge.record,
+                                        edge.vlist)))
+                return false;
 
-            TRY(db.indexes().update_property_indexes<TypeGroupEdge>(edge,
-                                                                    trans));
+            if (!db.indexes().update_property_indexes<TypeGroupEdge>(edge,
+                                                                     trans))
+                return false;
         }
         else
         {
@@ -90,12 +87,14 @@ bool DbTransaction::update_indexes()
                 // TODO: This could be done in batch
                 // NOTE: This assumes that label index is created with the
                 // database.
-                TRY(label.get().index().insert(LabelIndexRecord(
-                    std::nullptr_t(), vertex.record, vertex.vlist)));
+                if (!label.get().index().insert(LabelIndexRecord(
+                        std::nullptr_t(), vertex.record, vertex.vlist)))
+                    return false;
             }
 
-            TRY(db.indexes().update_property_indexes<TypeGroupVertex>(vertex,
-                                                                      trans));
+            if (!db.indexes().update_property_indexes<TypeGroupVertex>(vertex,
+                                                                       trans))
+                return false;
         }
 
         index_updates.pop_back();
diff --git a/src/storage/indexes/index_record.cpp b/src/storage/indexes/index_record.cpp
index 31cebd655..9632b5349 100644
--- a/src/storage/indexes/index_record.cpp
+++ b/src/storage/indexes/index_record.cpp
@@ -35,7 +35,7 @@ bool IndexRecord<TG, K>::is_valid(tx::Transaction &t) const
     // this index and then tries to access to the same element again through
     // the same index
     auto newest_record = vlist->find(t);
-    if (newest_record == nullptr)
+    if (!newest_record)
         return false;
     return (record == newest_record) || (newest_record->tx.cre() == t.id);
 }
diff --git a/tests/integration/_hardcoded_query/basic.hpp b/tests/integration/_hardcoded_query/basic.hpp
index 91b07e5cd..e9c71f022 100644
--- a/tests/integration/_hardcoded_query/basic.hpp
+++ b/tests/integration/_hardcoded_query/basic.hpp
@@ -299,13 +299,13 @@ auto load_basic_functions(Db &db)
                              .type(type);
 
         if (it_type.count() > it_vertex.count()) {
-            // Going through vertices wiil probably be faster
+            // TODO: Going through vertices wiil probably be faster
             it_vertex.to().for_all([&](auto m) {
                 // PRINT m
             });
 
         } else {
-            // Going through edges will probably be faster
+            // TODO: Going through edges will probably be faster
             it_type.to().for_all([&](auto m) {
                 // PRINT m
             });
diff --git a/tests/integration/queries.cpp b/tests/integration/queries.cpp
index 6876821a7..9b611c798 100644
--- a/tests/integration/queries.cpp
+++ b/tests/integration/queries.cpp
@@ -24,7 +24,6 @@ int main(int argc, char *argv[])
     logging::init_sync();
     logging::log->pipe(std::make_unique<Stdout>());
     auto log = logging::log->logger("test");
-    log.info("bla");
 
     // init db, functions and stripper
     Db db;