aboutsummaryrefslogtreecommitdiff
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
parentbb76e9388009ed0bb2512034f8cd48a7d19aabb3 (diff)
Add failure case to tracer implementation
Also adjust object traits API to work with the new low-level API in libodb.
-rw-r--r--odb/header.cxx12
-rw-r--r--odb/inline.cxx3
-rw-r--r--odb/source.cxx40
3 files changed, 45 insertions, 10 deletions
diff --git a/odb/header.cxx b/odb/header.cxx
index 5d87991..5b302af 100644
--- a/odb/header.cxx
+++ b/odb/header.cxx
@@ -100,13 +100,13 @@ namespace
// insert ()
//
os << "static void" << endl
- << "insert (database&, const object_type&);"
+ << "insert (database&, object_type&);"
<< endl;
// update ()
//
os << "static void" << endl
- << "update (database&, const object_type&);"
+ << "update (database&, object_type&);"
<< endl;
// erase ()
@@ -117,8 +117,12 @@ namespace
// find ()
//
- os << "static shared_ptr" << endl
- << "find (database&, const id_type&);";
+ os << "static pointer_type" << endl
+ << "find (database&, const id_type&);"
+ << endl;
+
+ os << "static bool" << endl
+ << "find (database&, const id_type&, object_type&);";
os << "};";
}
diff --git a/odb/inline.cxx b/odb/inline.cxx
index ee3a8e6..bf0aec9 100644
--- a/odb/inline.cxx
+++ b/odb/inline.cxx
@@ -38,7 +38,8 @@ namespace
// id ()
//
os << "inline" << endl
- << traits << "::id_type " << traits << "::" << endl
+ << traits << "::id_type" << endl
+ << traits << "::" << endl
<< "id (const object_type& obj)"
<< "{"
<< "return obj." << id.name () << ";" << endl
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"