Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 284680 - [DB] Provide annotation to bypass ClassMapping
Summary: [DB] Provide annotation to bypass ClassMapping
Status: CLOSED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: cdo.db (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: M1   Edit
Assignee: Stefan Winkler CLA
QA Contact:
URL:
Whiteboard: Power to the People
Keywords:
: 284481 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-07-26 13:27 EDT by Kai Schlamp CLA
Modified: 2010-06-29 04:40 EDT (History)
1 user (show)

See Also:
stepper: documentation+
stepper: helios+


Attachments
Table Mapping Annotation Patch (7.52 KB, patch)
2009-08-17 13:16 EDT, Kai Schlamp CLA
stepper: iplog+
Details | Diff
patch-v2-ready-to-be-committed (8.65 KB, patch)
2009-08-19 07:31 EDT, Stefan Winkler CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Schlamp CLA 2009-07-26 13:27:50 EDT
Build ID: 20090619-0625

Steps To Reproduce:
As I already mention on the message board CDO CVS Head due to the new type mapping mechanism works a bit other than CDO 2.0.
But it's not only the type mapping, it's also the way the complete database is created by the DB store. In CDO 2.0 a database table was created on demand (if something was commited). With CDO Head all database tables are created the first time the database is accessed.
The problem is that I mostly mix my models with classes that should be persisted to database and classes that are not intendet for persistence. Now with CDO Head many tables are created that are never used.
Maybe we should add an annotation option to suppress a table creation for a specific class.

More information:
Comment 1 Eike Stepper CLA 2009-07-26 15:10:40 EDT
Let's hear what Stefan says...
Comment 2 Stefan Winkler CLA 2009-07-27 04:45:41 EDT
I don't like the bug name ([DB] Create tables lazily) because it implies a more specific solution. 

In fact, Kai gives us room for two options:

1. Create tables lazily. This is almost impossible for the already known reasons of DDL being non-transactional. It is also not very consistent, because if a rollback happens, the table is still there, even though empty - and we can not delete it because another transaction may already have inserted to it simultaneously. In my eyes, it is far more secure to associate the table creation task to the package registering (at server) task. (This is also how OR-mappers would work, I think).

2. Prevent table creation through an annotation. I like that idea.
What about 

<eAnnotations source="http://www.eclipse.org/CDO/DBStore">
    <details key="mapping" value="none"/>
</eAnnotations>

for not mapping the table and 

<eAnnotations source="http://www.eclipse.org/CDO/DBStore">
    <details key="mapping" value="horizontal"/>
</eAnnotations>

for mapping the table using the horizontal strategy. (The latter is the default if no annotation is given).

This would also leave the option to add other mapping strategies in the future.





Comment 3 Eike Stepper CLA 2009-07-27 05:22:40 EDT
(In reply to comment #2)
> I don't like the bug name ([DB] Create tables lazily) because it implies a more
> specific solution. 

Ok, then we need one more bugzillas :P

> In fact, Kai gives us room for two options:
> 
> 1. Create tables lazily. This is almost impossible for the already known
> reasons of DDL being non-transactional. It is also not very consistent, because
> if a rollback happens, the table is still there, even though empty - and we can
> not delete it because another transaction may already have inserted to it
> simultaneously. 

That's the same with the all-or-no-tables approach, only worse. In general I think it's better to have unused empty tables in rare cases (i.e. rollback) than in all cases.

> 2. Prevent table creation through an annotation. I like that idea.

I don't. It makes the whole EPackage unusable for other scenarios.

> What about 
> 
> <eAnnotations source="http://www.eclipse.org/CDO/DBStore">
>     <details key="mapping" value="none"/>
> </eAnnotations>
> 
> for not mapping the table and 
> 
> <eAnnotations source="http://www.eclipse.org/CDO/DBStore">
>     <details key="mapping" value="horizontal"/>
> </eAnnotations>
> 
> for mapping the table using the horizontal strategy. 

That implies that the mapping strategy can be chosen per class and that's not true. We could consider that in a separate bugzilla but I foresee (solveable) challenges, e.g.:

  class C1 (vertical mapping)
  class C2 extends C1 (horizontal mapping)
  class C3 extends C2 (vertical mapping)

Where is the C2 segment table of C3?

>(The latter is the default
> if no annotation is given).
> 
> This would also leave the option to add other mapping strategies in the future.


Comment 4 Kai Schlamp CLA 2009-07-27 07:17:01 EDT
Why not then an annotation for just turning off the mapping for a specific class (just yes or no instead of the mapping type)?
Comment 5 Eike Stepper CLA 2009-07-27 07:44:00 EDT
It makes the whole EPackage unusable for other scenarios.
Comment 6 Kai Schlamp CLA 2009-07-27 07:50:09 EDT
I am sorry, but I can't follow entirely. What scenarios? Mapping scenarios?
Comment 7 Eike Stepper CLA 2009-07-27 07:53:59 EDT
An EPackage is something static and independent of any application logic. With this annotation you make this EPackage unusable for other applications. Right?
Comment 8 Kai Schlamp CLA 2009-07-30 20:19:58 EDT
I had now some days to think about your "right?" ;-), but still don't get the point.
When we annotate a class for example not to be created in the database by CDO, where do we change the EPackage (except of adding the annotation)?
But even then, I use my model in an RCP application ... I am not interested if other applications could use my model.
We even could point to such a problem (if there is really one) in the documentation.
But I still don't get why we should not implement such an annotation and refuse that flexibility.
Comment 9 Eike Stepper CLA 2009-07-31 02:31:50 EDT
(In reply to comment #8)
> I had now some days to think about your "right?" ;-), but still don't get the
> point.
> When we annotate a class for example not to be created in the database by CDO,
> where do we change the EPackage (except of adding the annotation)?

That's a change. And it belongs to the package. Nobody can ignore it.

> But even then, I use my model in an RCP application ... I am not interested if
> other applications could use my model.

The question is: Do EPackages exclusively belong to a single application or are they meant to be reusable? In general, not only in your particular application!

> We even could point to such a problem (if there is really one) in the
> documentation.
> But I still don't get why we should not implement such an annotation and refuse
> that flexibility.

Because the same can be achieved with lazy table creation, but more intelligently.
Comment 10 Kai Schlamp CLA 2009-07-31 05:14:51 EDT
(In reply to comment #9)
> (In reply to comment #8)
> > I had now some days to think about your "right?" ;-), but still don't get the
> > point.
> > When we annotate a class for example not to be created in the database by CDO,
> > where do we change the EPackage (except of adding the annotation)?
> 
> That's a change. And it belongs to the package. Nobody can ignore it.

But there is mostly a reason why a model designer says that this class shouldn't be persisted. It's like "transient" for an attribute (those are also static), but at the class level.


> > But even then, I use my model in an RCP application ... I am not interested if
> > other applications could use my model.
> 
> The question is: Do EPackages exclusively belong to a single application or are
> they meant to be reusable? In general, not only in your particular application!

I would say, let the programmer/model designer decide. In my opinion it's more a restriction to don't allow it than allowing it and making the package not re-useable anymore.

> 
> > We even could point to such a problem (if there is really one) in the
> > documentation.
> > But I still don't get why we should not implement such an annotation and refuse
> > that flexibility.
> 
> Because the same can be achieved with lazy table creation, but more
> intelligently.

Ok, thats a striking argument. But what would be a good way to do this? Simulate a table creation (maybe by creating it and deleting it again) and then later create it on lazily.
Or at first only check the types and so on and later create the table lazily?
Any other options?
Comment 11 Eike Stepper CLA 2009-07-31 05:36:17 EDT
Ok, your "transient feature" analogy convinced me. Plus the fact that lazy table creation would potentially slow down all commit operations because we need to discover unmapped classes *before* we iterate the new revisions.

I propose:

<eAnnotations source="http://www.eclipse.org/CDO/DBStore">
    <details key="tableMapping" value="NONE"/>
</eAnnotations>
Comment 12 Kai Schlamp CLA 2009-07-31 15:49:20 EDT
Good ... I see what I can do in the upcoming days.
Comment 13 Eike Stepper CLA 2009-08-03 12:57:19 EDT
*** Bug 284481 has been marked as a duplicate of this bug. ***
Comment 14 Kai Schlamp CLA 2009-08-17 13:16:31 EDT
Created attachment 144693 [details]
Table Mapping Annotation Patch

Here is the table mapping annotation implementation as promised (test included).
Comment 15 Kai Schlamp CLA 2009-08-17 13:18:04 EDT
And before you have to tell me ;-)

> 1) The number of lines that you changed (after copying from HSQLDB) is smaller
> than 250.
Confirmed.
> 
> 2) You are the only author of these changed lines.
Confirmed.
> 
> 3) You apply the EPL to these changed lines.
Confirmed.
Comment 16 Stefan Winkler CLA 2009-08-19 07:31:27 EDT
Created attachment 144943 [details]
patch-v2-ready-to-be-committed

Reviewed and tested. Looks good.
Thanks, Kai!
Comment 17 Stefan Winkler CLA 2009-08-19 07:34:42 EDT
Committed to HEAD.
Comment 18 Eike Stepper CLA 2010-06-29 04:40:04 EDT
Available in 3.0 GA:
http://download.eclipse.org/modeling/emf/cdo/updates/3.0-releases/