[odb-users] Polymorphism and lazy/weak pointers

Andreas Gerasch gerasch at informatik.uni-tuebingen.de
Thu Feb 9 07:56:08 EST 2012


Hi Boris,

thanks for your fast reply, we have still not decided what we will do, 
so I will come back later to this problem.

But, in the meantime we got a problem with loading of long strings (> 
265 characters) which are mapped to TEXT in MySQL.

We figured out, that it is caused by the definition of basic_buffer from 
buffer.hxx:

template <typename T>
     class basic_buffer: public basic_buffer_base
     {
     public:

       basic_buffer (std::size_t capacity = 256)
           : basic_buffer_base (capacity)
       {
       }

       T*
       data ()
       {
         return static_cast<T*> (data_);
       }

       const T*
       data () const
       {
         return static_cast<T*> (data_);
       }
     };

where you set the capacity to 256. So, if I increase the capacity (as 
shown below in my *-odb.hxx by introducing a default constructor) it 
works again. Is there a problem with the odb-compiler or do we miss some 
configuration (pragma?) options? It would be nice to set the default 
"max-length" of std::strings.

struct data_image_type
       {

     	  data_image_type() : value_value(512)
     	  {
     	  }

         // index
         //
         unsigned long long index_value;
         my_bool index_null;

         // value
         //
         details::buffer value_value;
         unsigned long value_size;
         my_bool value_null;

         std::size_t version;
       };


Thanks a lot,

Andreas





On 01/30/2012 04:15 PM, Boris Kolpackov wrote:
> Hi Andreas,
>
> Andreas Gerasch<gerasch at informatik.uni-tuebingen.de>  writes:
>
>> Do you know if polymorphism works together with lazy loading?
>
> Not out of the box. An "unloaded" lazy pointer stores the object
> id and uses the standard database::load() function to load it when
> requested. At the moment the way to handle polymorphism in lazy
> pointers would be to create your own version of a lazy pointer
> which uses your getObjectByID() function instead of standard
> load(). There is a bit of work but you can use the boost
> implementation as a guide.
>
> Also, we are planning to add support for polymorphic inheritance
> in the next release of ODB (not 1.8.0 that is coming our tomorrow;
> the version after that). So if you can wait for a few months, then
> that could be another option. I can also let you know as soon as we
> have something to try, if your are interested.
>
>
>> Second, is there a possibility to change the caching of objects in a
>> session from shared to weak without changing the pointer types of the
>> objects?
>
> No, the session uses the object pointer. Plus you cannot use a weak
> pointer as an object pointer. Though I kind of see why someone would
> want to use a weak pointer in the session. On the other hand, in the
> future, session may become more than just an object cache (e.g., we
> may use it to track dirty objects if we decide to support auto-flushing)
> in which case weak pointers won't really work. Perhaps a better approach
> would be to allow custom eviction decisions. For example, you could
> provide a callback that checks the reference count and if it is 1,
> then you could remove the object from the session. This would be
> pretty much equivalent to the lazy pointer semantics. What do you
> think?
>
> Boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gerasch.vcf
Type: text/x-vcard
Size: 435 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20120209/0c1e04a7/gerasch.vcf


More information about the odb-users mailing list