Project

General

Profile

Wt::Dbo question

Added by Remi Vieux over 13 years ago

Hi!

First, thanks for the good work on Wt! I have used it for building a basic web-based image search engine and found it very useful.

I am now looking into deeper usage of Wt, particularly in the DBo module. However, I found myself stuck with what may looks like a basic issue:

Assume that I want to store some object instances in a a DB, for example image histograms. Let's say that there is a class Histogram that computes and stores the values of the histogram (typically as an array of integers). However, I can have several kinds of histograms, depending on the color space in which the image is encoded. Typically, pixels have Red,Gree,Blue values, but the image can be transformed into a gray level image, where each pixel is associated with only 1 gray level value. The same code can be used in the histogram class, but the values computed and stored in the objects will depend on the color space, which is a parameter of my histogram class.

Now, I would like to store in different tables the RGB histograms and the Gray Lavel histograms. I dont see how this is possible with the session.mapClass function since T is template parameter while I rely on instanciated parameters to be able to differentiate the different types of histograms. Is there a way to do so? This is an issue I frequently come into, having the same code (same class) computing very different informations depending on the parameters of the algorithm, and I want to be able to store and retrieve the computed values according to a fixed set of parameters.

Hope my question is clear enough and that I can get some help!

Thanks again

R.V.


Replies (1)

RE: Wt::Dbo question - Added by Koen Deforche over 13 years ago

Hey,

Wt::Dbo persistence classes map directly on tables, and it's collection/ptr on relations. Since you have want to store something in two different tables, you will need to map two different classes. This means that you may want to have two persistence classes that are separate from the Histogram type which you have now --- and your Histogram uses one or the other for its storage depending on how it is configured.

This is indeed a limitation of Wt::Dbo but it is not clear to me how it can be avoided unless we let go the one-on-one mapping of prepared statements (which rigidly define the fields and table for a 'type') and a mapped class. And even then, it would be pretty complicated to use, it seems to me.

I hope this helps.

Regards,

koen

    (1-1/1)