aboutsummaryrefslogtreecommitdiff
path: root/odb/source.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-07-20 11:06:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-07-20 11:06:08 +0200
commit0e595e5d7bcc25b18027f3bda5d4508d42dacb39 (patch)
tree212b6a31c4d5e2dde1abd21a44debd879112065c /odb/source.cxx
parentbb76e9388009ed0bb2512034f8cd48a7d19aabb3 (diff)
Add failure case to tracer implementation
Also adjust object traits API to work with the new low-level API in libodb.
Diffstat (limited to 'odb/source.cxx')
-rw-r--r--odb/source.cxx40
1 files changed, 35 insertions, 5 deletions
diff --git a/odb/source.cxx b/odb/source.cxx
index 0a14354..168dfae 100644
--- a/odb/source.cxx
+++ b/odb/source.cxx
@@ -46,19 +46,25 @@ namespace
// insert ()
//
os << "void " << traits << "::" << endl
- << "insert (database&, const object_type& obj)"
+ << "insert (database&, object_type& obj)"
<< "{"
<< "std::cout << \"insert \" << type_name () << \" id \" << " <<
"id (obj) << std::endl;"
+ << endl
+ << "if (id (obj) == id_type ())" << endl
+ << "throw object_already_persistent ();"
<< "}";
// update ()
//
os << "void " << traits << "::" << endl
- << "update (database&, const object_type& obj)"
+ << "update (database&, object_type& obj)"
<< "{"
<< "std::cout << \"update \" << type_name () << \" id \" << " <<
"id (obj) << std::endl;"
+ << endl
+ << "if (id (obj) == id_type ())" << endl
+ << "throw object_not_persistent ();"
<< "}";
// erase ()
@@ -68,21 +74,41 @@ namespace
<< "{"
<< "std::cout << \"delete \" << type_name () << \" id \" << " <<
"id << std::endl;"
+ << endl
+ << "if (id == id_type ())" << endl
+ << "throw object_not_persistent ();"
<< "}";
// find ()
//
- os << traits << "::shared_ptr " << endl
+ os << traits << "::pointer_type" << endl
<< traits << "::" << endl
<< "find (database&, const id_type& id)"
<< "{"
<< "std::cout << \"select \" << type_name () << \" id \" << " <<
"id << std::endl;"
- << "shared_ptr r (access::object_factory< " << type <<
+ << endl
+ << "if (id == id_type ())" << endl
+ << "return pointer_type (0);"
+ << endl
+ << "pointer_type r (access::object_factory< " << type <<
" >::create ());"
<< "r->" << id.name () << " = id;"
<< "return r;"
<< "}";
+
+ os << "bool " << traits << "::" << endl
+ << "find (database&, const id_type& id, object_type& obj)"
+ << "{"
+ << "std::cout << \"select \" << type_name () << \" id \" << " <<
+ "id << std::endl;"
+ << endl
+ << "if (id == id_type ())" << endl
+ << "return false;"
+ << endl
+ << "obj." << id.name () << " = id;"
+ << "return true;"
+ << "}";
}
};
}
@@ -106,7 +132,11 @@ generate_source (context& ctx)
ctx.os << "#include <iostream>" << endl
<< endl;
- //ctx.os << "#include <odb/database.hxx>" << endl
+ ctx.os << "#include <odb/exceptions.hxx>" << endl
+ << endl;
+
+ //ctx.os << "#include <odb/tracer/database.hxx>" << endl
+ // << "#include <odb/tracer/exceptions.hxx>" << endl
// << endl;
ctx.os << "namespace odb"