aboutsummaryrefslogtreecommitdiff
path: root/evolution/soft-delete/model.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-09-06 08:59:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-09-17 12:04:03 +0200
commita204ad2d0926919fb19d4f14a2d2c0a5e98acd37 (patch)
tree2fde6cfb7e019cf39ea02fb72adb51cb094b579b /evolution/soft-delete/model.hxx
parent2c3dcfeee4fd2adb5a7dbd9af1c8ee02d4664d39 (diff)
Additional soft-delete tests
Diffstat (limited to 'evolution/soft-delete/model.hxx')
-rw-r--r--evolution/soft-delete/model.hxx174
1 files changed, 173 insertions, 1 deletions
diff --git a/evolution/soft-delete/model.hxx b/evolution/soft-delete/model.hxx
index 5defcac..5df2cee 100644
--- a/evolution/soft-delete/model.hxx
+++ b/evolution/soft-delete/model.hxx
@@ -11,6 +11,7 @@
#include <odb/core.hxx>
#include <odb/vector.hxx>
#include <odb/section.hxx>
+#include <odb/lazy-ptr.hxx>
#include <common/config.hxx> // DATABASE_XXX
@@ -51,10 +52,24 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
#pragma db namespace table("t2_")
namespace test2
{
+ struct object;
+
+ #pragma db object
+ struct object1
+ {
+ object1 (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ odb::vector<odb::lazy_ptr<object> > ptrs;
+ };
+
#pragma db object
struct object
{
- object (unsigned long id = 0): id_ (id) {}
+ object (unsigned long id = 0): id_ (id), ptr (0) {}
+ ~object () {delete ptr;}
#pragma db id
unsigned long id_;
@@ -62,11 +77,15 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
std::string str;
unsigned long num;
odb::vector<int> vec;
+
+ #pragma db inverse(ptrs)
+ object1* ptr;
};
#if MODEL_VERSION == 3
#pragma db member(object::str) deleted(3)
#pragma db member(object::vec) deleted(3)
+ #pragma db member(object::ptr) deleted(3)
#endif
}
@@ -241,6 +260,159 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
#endif
}
+ // Test basic soft-deleted member logic in polymorphic classes.
+ //
+ #pragma db namespace table("t9_")
+ namespace test9
+ {
+ #pragma db object polymorphic
+ struct base
+ {
+ virtual
+ ~base () {}
+ base (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ std::string bstr;
+ };
+
+ #pragma db object
+ struct object: base
+ {
+ object (unsigned long id = 0): base (id) {}
+
+ std::string dstr;
+ unsigned long num;
+ };
+
+#if MODEL_VERSION == 3
+ #pragma db member(base::bstr) deleted(3)
+ #pragma db member(object::dstr) deleted(3)
+#endif
+ }
+
+ // Test soft-deleted section member in polymorphic classes.
+ //
+ #pragma db namespace table("t10_")
+ namespace test10
+ {
+ #pragma db object polymorphic
+ struct base
+ {
+ virtual
+ ~base () {}
+ base (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ #pragma db load(lazy) update(change)
+ odb::section s;
+
+ #pragma db section(s)
+ std::string bstr;
+ };
+
+ #pragma db object
+ struct object: base
+ {
+ object (unsigned long id = 0): base (id) {}
+
+ #pragma db section(s)
+ std::string dstr;
+
+ unsigned long num;
+ };
+
+#if MODEL_VERSION == 3
+ #pragma db member(base::s) deleted(3)
+#endif
+ }
+
+ // Test soft-deleted members of a section in polymorphic classes.
+ //
+ #pragma db namespace table("t11_")
+ namespace test11
+ {
+ #pragma db object polymorphic
+ struct base
+ {
+ virtual
+ ~base () {}
+ base (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ #pragma db load(lazy) update(change)
+ odb::section s;
+
+ #pragma db section(s)
+ std::string bstr;
+ };
+
+ #pragma db object
+ struct object: base
+ {
+ object (unsigned long id = 0): base (id) {}
+
+ #pragma db section(s)
+ std::string dstr;
+
+ #pragma db section(s)
+ unsigned long num;
+ };
+
+#if MODEL_VERSION == 3
+ #pragma db member(base::bstr) deleted(3)
+ #pragma db member(object::dstr) deleted(3)
+#endif
+ }
+
+ // Test soft-deleted member and optimistic concurrency.
+ //
+ #pragma db namespace table("t12_")
+ namespace test12
+ {
+ #pragma db object optimistic
+ struct object
+ {
+ object (unsigned long id = 0): id_ (id) {}
+
+ #pragma db id
+ unsigned long id_;
+
+ #pragma db version mssql:type("ROWVERSION")
+ unsigned long long v_;
+
+ std::string str;
+ unsigned long num;
+ };
+
+#if MODEL_VERSION == 3
+ #pragma db member(object::str) deleted(3)
+#endif
+ }
+
+ // Test soft-deleted member in an object without id.
+ //
+ #pragma db namespace table("t13_")
+ namespace test13
+ {
+ #pragma db object no_id
+ struct object
+ {
+ std::string str;
+ unsigned long num;
+ };
+
+#if MODEL_VERSION == 3
+ #pragma db member(object::str) deleted(3)
+#endif
+ }
+
#endif // DATABASE_SQLITE
// Test soft-deleted container member in a non-versioned object.