[odb-users] Calling the persist function passing a custom object
class
Myoungkyu Song
mksong at vt.edu
Fri Dec 17 23:56:49 EST 2010
# ODB version: 1.0.0
# OS: Linux 2.6.32-26-generic-Ubuntu
# Compiler: g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Hi,
I would like to ask about calling the persist function passing the custom
class object (e.i., SequenceModel class). For example, consider the
followings;
============================================================
*SequenceModel.h*
#include <odb/core.hxx> // (1) ODB
typedef x10aux::ref<x10::lang::String> StringRef; // (2) ODB
#pragma db value(StringRef) type("TEXT NOT NULL") // (2) ODB
#pragma db object // (3) ODB
class SequenceModel : public x10::lang::Object {
public:
RTT_H_DECLS_CLASS
void _instance_init();
StringRef FMGL(name); // (4) ODB
StringRef FMGL(sequence); // (4) ODB
...
private:
SequenceModel() {} // (5) ODB
friend class odb::access; // (6) ODB
#pragma db id auto // (7) ODB
unsigned long id_; // (7) ODB
};
============================================================
Then, I updated the "*traits.hxx and traits.cxx*" in order to re-compile
libodb-mysql library.
============================================================
** traits.hxx*
class LIBODB_MYSQL_EXPORT *x10_string_value_traits*
{
public:
typedef x10aux::ref<x10::lang::String> value_type;
typedef x10aux::ref<x10::lang::String> query_type;
typedef details::buffer image_type;
static void
set_value (x10aux::ref<x10::lang::String>& v,
const details::buffer& b,
std::size_t n,
bool is_null)
{
if (!is_null)
v = x10aux::string_utils::lit(b.data ());
else
v = x10aux::string_utils::lit("");
}
static void
set_image (details::buffer&,
std::size_t& n,
bool& is_null,
const x10aux::ref<x10::lang::String>&);
};
template <>
struct LIBODB_MYSQL_EXPORT default_value_traits<
x10aux::ref<x10::lang::String>, details::buffer,
id_string>:x10_string_value_traits
{};
template <>
struct LIBODB_MYSQL_EXPORT default_value_traits<
x10aux::ref<x10::lang::String>, details::buffer,
id_decimal>:x10_string_value_traits
{};
template <>
struct LIBODB_MYSQL_EXPORT default_value_traits<
x10aux::ref<x10::lang::String>, details::buffer,
id_enum>:x10_string_value_traits
{};
template <>
struct LIBODB_MYSQL_EXPORT default_value_traits<
x10aux::ref<x10::lang::String>, details::buffer,
id_set>:x10_string_value_traits
{};
============================================================
* *traits.cxx*
void x10_string_value_traits::
set_image (buffer& b,
size_t& n,
bool& is_null,
const x10aux::ref<x10::lang::String>& v)
{
is_null = false;
n = v->length();
if (n > b.capacity ())
b.capacity (n);
if (n != 0)
memcpy (b.data (), x10aux::string_utils::cstr(v), n);
}
}
============================================================
However, in the client code I have gotten some error messages;
============================================================
void makePersistence(x10aux::ref<SequenceModel> seqModel) {
char* argv[] = { "app", "--user", "root", "--password", "root",
"--host", "localhost", "--database", "mydb" };
int argc = 9;
try {
auto_ptr < database > db(new mysql::database(argc, argv));
transaction t(db->begin());
db->persist(seqModel);
t.commit();
cout << "makePersistence: " << endl;
} catch (const odb::exception& e) {
cerr << e.what() << endl;
}
}
============================================================
In file included from /usr/local/include/odb/database.hxx:13,
from dbtrax.cc:8:
/usr/local/include/odb/traits.hxx: At global scope:
/usr/local/include/odb/traits.hxx: In instantiation of
‘odb::object_traits<x10aux::ref<SequenceModel> >’:
dbtrax.cc:30: instantiated from here
/usr/local/include/odb/traits.hxx:81: error: invalid use of incomplete type
‘struct odb::access::object_traits<x10aux::ref<SequenceModel> >’
/usr/local/include/odb/forward.hxx:23: error: declaration of ‘struct
odb::access::object_traits<x10aux::ref<SequenceModel> >’
/usr/local/include/odb/traits.hxx:84: error: invalid use of incomplete type
‘struct odb::access::object_traits<x10aux::ref<SequenceModel> >’
/usr/local/include/odb/forward.hxx:23: error: declaration of ‘struct
odb::access::object_traits<x10aux::ref<SequenceModel> >’
dbtrax.cc: In function ‘void makePersistence(x10aux::ref<SequenceModel>)’:
dbtrax.cc:30: error: no matching function for call to
‘odb::database::persist(x10aux::ref<SequenceModel>&)’
Command exited with non-zero status 1
1.66user 0.15system 0:01.88elapsed 96%CPU (0avgtext+0avgdata
288304maxresident)k
0inputs+8outputs (0major+18350minor)pagefaults 0swaps
make: *** [dbtrax.o] Error 1
smk at smk-laptop:~/workspace/x10test1$
============================================================
Do you have any valuable experience related to this problem?
Thank you in advance.
Best regards,
Myoungkyu Song
-------------- next part --------------
A non-text attachment was scrubbed...
Name: traits.cxx
Type: text/x-c++src
Size: 1597 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20101217/137af6a7/traits.cxx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: traits.hxx
Type: text/x-c++hdr
Size: 7985 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20101217/137af6a7/traits.hxx
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SequenceModel.h
Type: text/x-chdr
Size: 2586 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20101217/137af6a7/SequenceModel.h
More information about the odb-users
mailing list