Polymorphism in one query without knowing which type the entity is?

  • Follow


Hello :)

I have a database that contains Flash clips to be played online. The clips
are polymorphic in type, in that they usually start out as live broadcasts
that are later transcoded to on-demand streamable files. This is
implemented using some join tables - for simplicity's sake, let's say that
Clip can be related to OnDemandFile and LiveStream via join tables.

I was wondering if it's possible to do a single query that will retrieve all
the info available for an arbitrary Clip, while not knowing (or specifying)
if it's either live or on-demand.

"SELECT * FROM Clip c, OnDemandFile o, LiveStream l WHERE c.id = o.id AND
c.id = l.id" would return nothing, as a Clip can't be both things at once
(well, actually it can, but not always).

I'd really like to be able to get all data about a Clip in one query,
knowing nothing more than its id.

Is this possible?

Thanks in advance,
Daniel :)
0
Reply daniel138 (30) 12/8/2008 2:46:30 PM

On 8 Dec, 14:46, Daniel Smedegaard Buus
<dan...@danielsmedegaardbuus.dk> wrote:
> Hello :)
>
> I have a database that contains Flash clips to be played online. The clips
> are polymorphic in type, in that they usually start out as live broadcasts
> that are later transcoded to on-demand streamable files. This is
> implemented using some join tables - for simplicity's sake, let's say that
> Clip can be related to OnDemandFile and LiveStream via join tables.
>
> I was wondering if it's possible to do a single query that will retrieve all
> the info available for an arbitrary Clip, while not knowing (or specifying)
> if it's either live or on-demand.
>
> "SELECT * FROM Clip c, OnDemandFile o, LiveStream l WHERE c.id = o.id AND
> c.id = l.id" would return nothing, as a Clip can't be both things at once
> (well, actually it can, but not always).
>
> I'd really like to be able to get all data about a Clip in one query,
> knowing nothing more than its id.
>
> Is this possible?
>
> Thanks in advance,
> Daniel :)

LEFT JOINs
0
Reply paul_lautman (2110) 12/8/2008 2:57:20 PM


Daniel Smedegaard Buus wrote:
> Hello :)
> 
> I have a database that contains Flash clips to be played online. The clips
> are polymorphic in type, in that they usually start out as live broadcasts
> that are later transcoded to on-demand streamable files. This is
> implemented using some join tables - for simplicity's sake, let's say that
> Clip can be related to OnDemandFile and LiveStream via join tables.
> 
> I was wondering if it's possible to do a single query that will retrieve all
> the info available for an arbitrary Clip, while not knowing (or specifying)
> if it's either live or on-demand.
> 
> "SELECT * FROM Clip c, OnDemandFile o, LiveStream l WHERE c.id = o.id AND
> c.id = l.id" would return nothing, as a Clip can't be both things at once
> (well, actually it can, but not always).
> 
> I'd really like to be able to get all data about a Clip in one query,
> knowing nothing more than its id.
> 
> Is this possible?
> 
> Thanks in advance,
> Daniel :)

It can be possible, depending on your structure.  Not knowing what that 
is, however, it's hard to tell.

You can check into LEFT JOIN; it might do what you want.  Or, you might 
want to rethink your database structure.  It's hard to say.

One other concern I might have is the amount of data returned, 
especially if the clip is both live and on-demand.  Depending on the 
sizes of your clips, you might run out of resources (i.e. memory) to 
process the request.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
Reply jstucklex (14362) 12/8/2008 3:05:40 PM

Jerry Stuckle wrote:

> Daniel Smedegaard Buus wrote:
>> Hello :)
>> 
>> I have a database that contains Flash clips to be played online. The
>> clips are polymorphic in type, in that they usually start out as live
>> broadcasts that are later transcoded to on-demand streamable files. This
>> is implemented using some join tables - for simplicity's sake, let's say
>> that Clip can be related to OnDemandFile and LiveStream via join tables.
>> 
>> I was wondering if it's possible to do a single query that will retrieve
>> all the info available for an arbitrary Clip, while not knowing (or
>> specifying) if it's either live or on-demand.
>> 
>> "SELECT * FROM Clip c, OnDemandFile o, LiveStream l WHERE c.id = o.id AND
>> c.id = l.id" would return nothing, as a Clip can't be both things at once
>> (well, actually it can, but not always).
>> 
>> I'd really like to be able to get all data about a Clip in one query,
>> knowing nothing more than its id.
>> 
>> Is this possible?
>> 
>> Thanks in advance,
>> Daniel :)
> 
> It can be possible, depending on your structure.  Not knowing what that
> is, however, it's hard to tell.
> 
> You can check into LEFT JOIN; it might do what you want.  Or, you might
> want to rethink your database structure.  It's hard to say.
> 

Thanks, I'll try that out :)

> One other concern I might have is the amount of data returned,
> especially if the clip is both live and on-demand.  Depending on the
> sizes of your clips, you might run out of resources (i.e. memory) to
> process the request.
> 

0
Reply daniel138 (30) 12/9/2008 2:40:01 PM

3 Replies
43 Views

(page loaded in 0.064 seconds)


Reply: