Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » Referencing Ecore to Support ORM
Referencing Ecore to Support ORM [message #656623] Sun, 27 February 2011 16:23 Go to next message
Glenview Jeff is currently offline Glenview JeffFriend
Messages: 79
Registered: September 2010
Member
I am trying to add support to my existing meta-model for modeling an Object Relational Mapper (ORM.) I came across this very old post in the newsgroups, and first was wondering (Ed Merks) if the tutorial was ever written?

Specifically, what I'd like my meta-model to ultimately support is the creation of models that look something like this:

PersistentClass:
myName : "TestClass"
myTableName: "TestClass"
myOrmAttributes:
OrmBoolean: (Ideally extending the Ecore EBoolean, but I have read this is a bad idea.)
myName: "TestOrmBoolean"
myStoredType: "boolean"
EBoolean: (Ideally referencing the Ecore type)
Name: "TestEcoreBoolean"
...

and the meta-model would look something like this:

PersistentClass:
myName : EString
myTableName: EString
myOrmAttributes: [0..*] OrmAttribute
myEcoreAttributes: [0..*] EAttribute (I have to separate this from myOrmAttributes because I shouldn't extend Ecore, right?)

OrmAttribute:
myStoredType: EString

OrmBooleanAttribute: Extends OrmAttribute
myAttribute: EBoolean

OrmStringAttribute: Extends OrmAttribute
myAttribute: EString

...

This looks quite ugly because of being discouraged from extending ecore. Is there a better way to accomplish what I'm trying to do?

Thanks!
Jeff

[Updated on: Sun, 27 February 2011 18:05]

Report message to a moderator

Re: Referencing Ecore to Support ORM [message #656632 is a reply to message #656623] Sun, 27 February 2011 18:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030408030102000101070007
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Jeff,

Comments below.


glenviewjeff wrote:
> I am trying to add support to my existing meta-model for modeling an
> Object Relational Mapper (ORM.) I came across
> http://www.eclipse.org/forums/index.php?t=rview&goto=376 261&th=123211
> in the newsgroups, and first was wondering (Ed Merks) if the tutorial
> was ever written?
Tutorial: Generating an Extended EMF Model
< http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/slibmod/slibmod.html>

>
> Specifically, what I'd like my meta-model to ultimately support is the
> creation of models that look something like this:
>
> PersistentClass:
> myName : "TestClass"
> myTableName: "TestClass"
> myOrmAttributes:
> OrmBoolean: (Ideally extending the Ecore EBoolean, but I have
> read this is a bad idea.)
I'm not sure what it means to extend EBoolean. You mean extended
EDataType. java.lang.Boolean itself isn't extensible...
> myName: "TestOrmBoolean"
> myStoredType: "boolean"
> EBoolean: (Ideally referencing the Ecore type)
> Name: "TestEcoreBoolean"
> ...
>
> and the meta-model would look something like this:
>
> PersistentClass:
> myName : EString
> myTableName: EString
> myOrmAttributes: [0..*] OrmAttribute
> myEcoreAttributes: [0..*] EAttribute (I have to separate this from
> myOrmAttributes because I shouldn't extend Ecore, right?)
I'm not sure what it means to mix meta level things like EAttribute with
instance level things list EString...
>
> OrmAttribute:
> myStoredType: EString
>
> OrmBooleanAttribute: Extends OrmAttribute
> myAttribute: EBoolean
> OrmStringAttribute: Extends OrmAttribute
> myAttribute: EString
> ..
>
> This looks quite ugly because of not discouraged from extending ecore.
Indeed. Annotating Ecore should suffice.
> Is there a better way to accomplish what I'm trying to do?
It's not entirely clearly what you're trying to do. Teneo and CDO both
to ORM mapping already...
>
> Thanks!
> Jeff

--------------030408030102000101070007
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jeff,<br>
<br>
Comments below.<br>
<br>
<br>
glenviewjeff wrote:
<blockquote cite="mid:ikdtd6$for$1@news.eclipse.org" type="cite">I am
trying to add support to my existing meta-model for modeling an Object
Relational Mapper (ORM.)  I came across
<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/forums/index.php?t=rview&goto=376 261&th=123211">http://www.eclipse.org/forums/index.php?t=rview&amp;goto=376261&amp;th=123211</a>
in the newsgroups, and first was wondering (Ed Merks) if the tutorial
was ever written?
<br>
</blockquote>
<a
href=" http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/slibmod/slibmod.html">Tutorial:
Generating an Extended EMF Model</a>
<blockquote cite="mid:ikdtd6$for$1@news.eclipse.org" type="cite"><br>
Specifically, what I'd like my meta-model to ultimately support is the
creation of models that look something like this:
<br>
<br>
PersistentClass:
<br>
  myName : "TestClass"
<br>
  myTableName: "TestClass"
<br>
  myOrmAttributes:
<br>
     OrmBoolean: (Ideally extending the Ecore EBoolean, but I have read
this is a bad idea.)
<br>
</blockquote>
I'm not sure what it means to extend EBoolean.  You mean extended
EDataType.  java.lang.Boolean itself isn't extensible...<br>
<blockquote cite="mid:ikdtd6$for$1@news.eclipse.org" type="cite">       
myName: "TestOrmBoolean"
<br>
        myStoredType: "boolean"
<br>
      EBoolean: (Ideally referencing the Ecore type)
<br>
        Name: "TestEcoreBoolean"
<br>
        ...
<br>
<br>
and the meta-model would look something like this:
<br>
<br>
PersistentClass:
<br>
 myName : EString
<br>
 myTableName: EString
<br>
 myOrmAttributes: [0..*] OrmAttribute
<br>
 myEcoreAttributes: [0..*] EAttribute (I have to separate this from
myOrmAttributes because I shouldn't extend Ecore, right?)
<br>
</blockquote>
I'm not sure what it means to mix meta level things like EAttribute
with instance level things list EString...<br>
<blockquote cite="mid:ikdtd6$for$1@news.eclipse.org" type="cite"><br>
OrmAttribute:
<br>
 myStoredType: EString
<br>
<br>
OrmBooleanAttribute: Extends OrmAttribute
<br>
 myAttribute: EBoolean <br>
OrmStringAttribute: Extends OrmAttribute
<br>
 myAttribute: EString <br>
...
<br>
<br>
This looks quite ugly because of not discouraged from extending ecore. <br>
</blockquote>
Indeed.  Annotating Ecore should suffice.<br>
<blockquote cite="mid:ikdtd6$for$1@news.eclipse.org" type="cite"> Is
there a better way to accomplish what I'm trying to do?
<br>
</blockquote>
It's not entirely clearly what you're trying to do.  Teneo and CDO both
to ORM mapping already...<br>
<blockquote cite="mid:ikdtd6$for$1@news.eclipse.org" type="cite"><br>
Thanks!
<br>
Jeff
<br>
</blockquote>
</body>
</html>

--------------030408030102000101070007--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Referencing Ecore to Support ORM [message #656647 is a reply to message #656632] Sun, 27 February 2011 21:24 Go to previous messageGo to next message
Glenview Jeff is currently offline Glenview JeffFriend
Messages: 79
Registered: September 2010
Member
Ed:

Thanks very much for the super quick answer on a Sunday no less!

Please forgive the sloppiness of my rough sketch; I'm an EMF newbie and even an Eclipse framework novice as you can probably tell.

To give you some background, this all started with my listening to the model-driven software development podcasts on se-radio.net. I've been playing mostly with Acceleo to do M2T for Android Java development, with the ultimate goal of making generators for other platforms (web, desktop.) I've also spent a few days looking into Xpand as well as JetBrains MPS (outside Eclipse.)

During this process, I've had success in reverse-engineering/refactoring/modeling and generating of a fairly large Android application using EMF+Acceleo.

Recently, I began using an ORM that supports Android and other platforms called ORMlite (www.ormlite.com.) Hibernate doesn't support Android as far as I know. At your suggestion I just took a quick look at CDO and Teneo and at least initially, doesn't seem obvious that these have meta-models I could re-use.

Please recognize that I am not trying to use EMF's code generation to generate Android target code, as I believe this is impossible/infeasible. I'm only using the EMF generation to create the default model editor so I can create a model instance.

Ultimately, I want to to define a class in my model, define its attributes, mark some attributes as persistent, annotate some attributes to override the default persistent data types, etc. The generated Android code would look something like this:

@DatabaseTable(tableName = "accounts")
public class Account {
    
    @DatabaseField(id = true)
    private String name;
    @DatabaseField
    private String password;
   @DatabaseField(DataType = DataType.DATE_STRING)
    private Date date; 
    private Date nonPersistedDate;


I will create generators with Acceleo that annotate the generated class with the appropriate ORMlite annotations as above automatically.

I read a little about annotating the Ecore model in the EMF book at your suggestion, but it's not exactly clear to me how this would work.

If I were extending Ecore's EClass, I would do something like this (forgive the pseudocode.)

PersistentClass extends EClass {
 EString TableName
}


which would enforce that a TableName is defined for the PersistentClass. Am I right in assuming that if I were to use annotations, one could create an inconsistent class where maybe the user uses an Eclass instead and then annotates some of the fields to be persistent?

I know this sort of thing could be addressed using something like the Check language, but I'd rather rely on the built in enforcement I'd get via inheritence.

I really appreciate all of your help and guidance.

Thanks,
Jeff
Re: Referencing Ecore to Support ORM [message #656651 is a reply to message #656647] Sun, 27 February 2011 21:53 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Jeff,

Comments below.

glenviewjeff wrote:
> Ed:
>
> Thanks very much for the super quick answer on a Sunday no less!
No rest for the wicked..
>
> Please forgive the sloppiness of my rough sketch; I'm an EMF newbie
> and even an Eclipse framework novice as you can probably tell.
:-P
> To give you some background, this all started with my listening to the
> model-driven software development podcasts on se-radio.net. I've been
> playing mostly with Acceleo to do M2T for Android Java development,
> with the ultimate goal of making generators for other platforms (web,
> desktop.) I've also spent a few days looking into Xpand as well as
> JetBrains MPS (outside Eclipse.)
Outside of Eclipse! Perish the thought!!
> During this process, I've had success in
> reverse-engineering/refactoring/modeling and generating of a fairly
> large Android application using EMF+Acceleo.
That's cool.
>
> Recently, I began using an ORM that supports Android and other
> platforms called ORMlite (www.ormlite.com.) Hibernate doesn't support
> Android as far as I know. At your suggestion I just took a quick look
> at CDO and Teneo and at least initially, doesn't seem obvious that
> these have meta-models I could re-use.
> Please recognize that I am not trying to use EMF's code generation to
> generate Android target code, as I believe this is impossible/infeasible.
I'm not so sure about that:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=296770
> I'm only using the EMF generation to create the default model editor
> so I can create a model instance.
>
> Ultimately, I want to to define a class in my model, define its
> attributes, mark some attributes as persistent, annotate some
> attributes to override the default persistent data types, etc.
Not unlike Ecore...
> The generated Android code would look something like this:
>
>
> @DatabaseTable(tableName = "accounts")
> public class Account {
> @DatabaseField(id = true)
> private String name;
> @DatabaseField
> private String password;
> @DatabaseField(DataType = DataType.DATE_STRING)
> private Date date; private Date nonPersistedDate;
>
>
> I will create generators with Acceleo that annotate the generated
> class with the appropriate ORMlite annotations as above automatically.
>
> I read a little about annotating the Ecore model in the EMF book at
> your suggestion, but it's not exactly clear to me how this would work.
Look at, for example, a model created from an XML Schema (like the
library tutorial example).
> If I were extending Ecore's EClass, I would do something like this
> (forgive the pseudocode.)
>
>
> PersistentClass extends EClass {
> EString TableName
> }
Yep, that's exactly the kind of think you could do with an EAnnotation;
look at how ExtendedMetaData doesn't this for XML Schema-based Ecore
annotations.
>
>
> which would enforce that a TableName is defined for the
> PersistentClass. Am I right in assuming that if I were to use
> annotations, one could create an inconsistent class where maybe the
> user uses an Eclass instead and then annotates some of the fields to
> be persistent?
Of course, but one could create an inconsistent class with a tableName
that's empty, or uses bad characters. In either case, you'd need to
check for well formedness.
> I know this sort of thing could be addressed using something like the
> Check language, but I'd rather rely on the built in enforcement I'd
> get via inheritence.
Other types of things like duplicate table names would also need
checking... In the end, you do end up writing code of some sort in some
language...
> I really appreciate all of your help and guidance.
I suspect you could accomplish what you wanted with annotated Ecore,
though likely with a different generator...
>
> Thanks,
> Jeff


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EMF] How to persist to SQL/RDBMS/JDBC?
Next Topic:model autosave
Goto Forum:
  


Current Time: Tue Mar 19 02:08:22 GMT 2024

Powered by FUDForum. Page generated in 0.01461 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top