Bug 249610 - [DB] Support external references (Implementation)
Summary: [DB] Support external references (Implementation)
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: M1   Edit
Assignee: Stefan Winkler CLA
QA Contact:
URL:
Whiteboard: Appealing to a Broader Community
Keywords:
Depends on: 213402
Blocks:
  Show dependency tree
 
Reported: 2008-10-03 11:03 EDT by Simon Mc Duff CLA
Modified: 2010-06-29 04:40 EDT (History)
3 users (show)

See Also:
stepper: documentation+
stepper: galileo+
stepper: review+


Attachments
first implementation - incomplete (27.47 KB, patch)
2009-07-13 14:29 EDT, Stefan Winkler CLA
no flags Details | Diff
implementation finished - to be reviewed (28.31 KB, patch)
2009-07-14 10:09 EDT, Stefan Winkler CLA
no flags Details | Diff
Patch - to be committed (31.75 KB, patch)
2009-07-14 11:33 EDT, Eike Stepper CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Mc Duff CLA 2008-10-03 11:03:58 EDT
In the deltas or revision CDOIDExternal would need to be kept.

if (id.isExternal())
{
    // return a string
   ((CDOIDExternal)id).getURI();
}

When populates the CDORevision

CDOIDUtil.createExternal(string);

It is possible that 
id.isExternal() && id.isTemporary

Usually this is because applyIDMapping wasn't called and/or the end-user didn't commit in the right order. GOing in a XATransaction will help
Comment 1 Eike Stepper CLA 2008-12-17 04:50:18 EST
From a chat with Martin:

for the dbstore i have a vague idea how to implement ext-refs
dbstore's CDOIDs are long ints
all positive (zero is null)
we could introduce negative ids tha make the store look in a separate id -> uri table
Comment 2 Eike Stepper CLA 2008-12-17 04:53:27 EST
another solution would be: just add a string column to all our references tables. but i'm not sure about the overhead
Comment 3 Stefan Winkler CLA 2008-12-17 05:14:03 EST
You mean a string containing an URL if the reference is external and NULL otherwise?

A database implementation using VARCHAR as column type usually only uses those bytes which are required (+1). So a string column containing NULL should only take 1-2 bytes of additional storage per row.

On the other hand, in bug 254567 we wanted to split up CDOIDs to (cdo_class_id, cdo_instance_id) anyway. So, defining a special cdo_class_id for external references would also be an option in that context ...
Comment 4 Martin Taal CLA 2008-12-17 05:26:18 EST
Hi Stefan,
I would not directly use cdo_class_id for that. In the Teneo relational db the foreign key in the database does not require the cdo_class_id to be present as a column in the db. 
My reason for having a cdoid with both a classid and instance id is that the cdoid can be passed around in the server java code and be used to query the db (although I understand that the objectstore only needs the id).

This week I added external reference support to Teneo standalone. With Teneo you can now tag an ereference with an @External annotation to specify that it should be stored as an external reference (a string/varchar) instead of a foreign key. I am not sure if it is useful for CDO stores in general, but maybe it is interesting:
http://www.elver.org/hibernate/hibernate_relations.html#external

gr. Martin
Comment 5 Eike Stepper CLA 2008-12-17 06:48:04 EST
(In reply to comment #3)
> You mean a string containing an URL if the reference is external and NULL
> otherwise?

Yes, for the case we "embed" the external refs into our existing reference tables (additionally). I forgot to mention that we'd need to do this with single-valued references as well!

In the case that we choose the approach with a separate cdo_external_targets table, we'd need no NULL rows.


> A database implementation using VARCHAR as column type usually only uses those
> bytes which are required (+1). So a string column containing NULL should only
> take 1-2 bytes of additional storage per row.

Given that this could scale out badly in terms of size and that it clutters the schema it would be nice to make the approach extensible and configurable. What do you think?


> On the other hand, in bug 254567 we wanted to split up CDOIDs to (cdo_class_id,
> cdo_instance_id) anyway. So, defining a special cdo_class_id for external
> references would also be an option in that context ...

I don't think that this is a good idea because we'd need the concrete type of external target objects, too. Emf needs it to instantiate an appropriate proxy!

Comment 6 Stefan Winkler CLA 2009-07-13 14:29:35 EDT
Created attachment 141446 [details]
first implementation - incomplete

This patch is an untested and a bit incomplete implementation of external reference support for the DB store.

The final step of the implementation would require introducing an IDBStoreAccessor parameter in all of the TypeMappings. Since this will collide with the current effort in bug 282976, I will postpone this until the said bug is committed.
Comment 7 Stefan Winkler CLA 2009-07-14 10:09:56 EDT
Created attachment 141519 [details]
implementation finished - to be reviewed
Comment 8 Eike Stepper CLA 2009-07-14 11:33:36 EDT
Created attachment 141538 [details]
Patch - to be committed

Well done!
Comment 9 Stefan Winkler CLA 2009-07-15 06:29:14 EDT
Thanks.

Committed to HEAD.
Comment 10 Victor Roldan Betancort CLA 2009-09-11 12:34:22 EDT
Guys, has this been fixed to HEAD 3.0, right? If so, please tag accordingly.

Is there any chance to fix it in 2.0?

Cheers,
Víctor.
Comment 11 Victor Roldan Betancort CLA 2010-01-21 11:08:21 EST
Eike, the information on this bug is still wrong and misleading. This is the bug for 3.0. And this bug patch has been shipped in some 3.0 milestone, but we don't know which one :( 

I suspect this was an early bug fix in the 3.0 stream, so it has probably been included in M1.
Comment 12 Stefan Winkler CLA 2010-01-22 04:20:33 EST
External references are in 2.0 as fix of Bug 289237.
This bug refers to 3.0 and has been committed to HEAD in July 2009 as comment#9 states. I have adjusted the metadata.
Comment 13 Victor Roldan Betancort CLA 2010-01-22 05:09:41 EST
Thanks, Stefan!
Comment 14 Eike Stepper CLA 2010-06-29 04:40:51 EDT
Available in 3.0 GA:
http://download.eclipse.org/modeling/emf/cdo/updates/3.0-releases/