[odb-users] Creation of ODB cache
Boris Kolpackov
boris at codesynthesis.com
Wed May 30 10:00:30 EDT 2012
Hi Davide,
Davide Anastasia <Davide.Anastasia at qualitycapital.com> writes:
> 1. can a session object be a member of a class?
The session that is currently provided by ODB is per-thread (a pointer
to the current session is stored in the TLS). It is also not thread-
aware in the sense that a single session cannot be used safely from
multiple threads concurrently.
However, one can imagine that a shared, thread-aware implementation
could be useful for some applications so we could add something like
this in the future.
So, to answer your question, yes, you can make a session object a
member of a class though it will "attach" itself to the thread
where the class' constructor is executed, which may or may not
be what you want (you can "detach" it from the current and attach
it to another thread using the provided "current" API).
> I'm saying that because my class essentially runs into an
> std::thread and waits for "updates" to store, starting a
> transaction every time:
>
> void run()
> {
> while (1)
> {
> // wait
> Transaction t( ...) ;
>
> // load, persist, ?
>
> t.commit();
> }
> }
In this case it seems more straightforward to just do:
void run()
{
session s;
while (1)
{
..
}
}
Unless you plan to restart the thread and want to keep the
session's contents.
> 2. how many session object can my application have? Can it make sense to
> have a session at the beginning of the application as "master" session?
I think the above explanation should make this clear now. Currently,
you can have one active session per thread.
> 3. If I do a conditional search, is the retrieved object stored in the
> session?
You mean if you execute a query? In that case, yes, if you actual
instantiate the object (i.e., dereference the iterator), then yes,
the object will be cached.
> 4. Does session apply to Views?
No, views are not stored in a session (they have no object ids).
> To many questions, I know :)
No problem. It is always good to understand how people are using
(or trying to use) ODB.
Boris
More information about the odb-users
mailing list