[odb-users] Re: Self persisting objects?
Oded Arbel
oded at geek.co.il
Wed Aug 29 14:39:39 EDT 2012
Actually, NM - sorry to bother. My mistake that I didn't include the
generated employee-odb.hxx. After that fix it works fine.
On Wed, Aug 29, 2012 at 9:13 PM, Oded Arbel <oded at geek.co.il> wrote:
> Hi guys.
>
> I'm trying to write a model class that is self contained - i.e. it
> includes all business logic to manipulate the ODB API and does not
> require the application to know ODB to operate it.
>
> As part of that, I thought it will be cool (and OOish) to be able to
> create and persist objects using a simple API like this:
> Employee *e = new Employee("John","Doe");
> e->persist();
>
> The implementation of Employee::persist() could be pretty trivial
> (assuming someone knows how to initialize a database connection. I'm
> going to leave that as an exercise to the user and assume an already
> inited static field):
> void Employee::persist() {
> odb::transaction t(s_db->begin());
> s_db->persist(this);
> t.commit();
> }
>
> Unfortunately Visual Studio 10 doesn't like me much and breaks when
> trying to compile.
>
> I've seen database.hxx has a definition for persist(T* o), but the
> "this" pointer is "const Class*" which won't fit.
>
> This is what the compiler has to say (actual class names have been
> modified to protect the cryptic):
> ---8<---
> 1>------ Build started: Project: data-model, Configuration: Debug Win32 ------
> 1> employee.cpp
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(103): error C2504:
> 'odb::access::object_traits<T>' : base class undefined
> 1> with
> 1> [
> 1> T=model::Employee
> 1> ]
> 1> c:\XXX\data-model\src\employee.cpp(17) : see reference to
> class template instantiation 'odb::object_traits<T>' being compiled
> 1> with
> 1> [
> 1> T=model::Employee
> 1> ]
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2146: syntax error :
> missing ',' before identifier 'pointer_type'
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(104): error C2065: 'pointer_type'
> : undeclared identifier
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(105): error C2955:
> 'odb::access::object_factory' : use of class template requires
> template argument list
> 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(17) : see declaration
> of 'odb::access::object_factory'
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2146: syntax error :
> missing ';' before identifier 'const_pointer_type'
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C3254:
> 'odb::object_traits<T>' : class contains explicit override
> 'const_pointer_type' but does not derive from an interface that
> contains the function declaration
> 1> with
> 1> [
> 1> T=model::Employee
> 1> ]
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2838:
> 'const_pointer_type' : illegal qualified name in member declaration
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C4430: missing type
> specifier - int assumed. Note: C++ does not support default-int
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2602:
> 'odb::object_traits<T>::const_pointer_type' is not a member of a base
> class of 'odb::object_traits<T>'
> 1> with
> 1> [
> 1> T=model::Employee
> 1> ]
> 1> c:\XXX\libodb-2.0.1\odb\traits.hxx(119) : see declaration
> of 'odb::object_traits<T>::const_pointer_type'
> 1> with
> 1> [
> 1> T=model::Employee
> 1> ]
> 1>c:\XXX\libodb-2.0.1\odb\traits.hxx(119): error C2868:
> 'odb::object_traits<T>::const_pointer_type' : illegal syntax for
> using-declaration; expected qualified-name
> 1> with
> 1> [
> 1> T=model::Employee
> 1> ]
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
> ---8<---
>
> Any idea what I'm doing wrong here?
>
> --
> Oded
--
Oded
More information about the odb-users
mailing list