You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by ha...@welinux.cl on 2009/10/01 23:06:51 UTC

Model Refactor, move table from one Map to Another

Hi List,

In order to reuse some logic i'm trying to refactor an old model and i was wondering if there is a way to move a Table and its associated Entity from one map to another, i'm using just one domain.
 
I tried in the last 3.0M6 modeler, the cut & paste looks very nice, i was crossing my fingers, but after the move, all the object and db relationships gets broken, the tables i'm trying to refactor have lots of relationships. May be somebody has writen some script or knows of some guide for doing this ?

Thanks
Hans

Re: Id problem when trying to make a component decoupling a module

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 5/10/09 3:31 PM, hans@welinux.cl wrote:
> The problem is when we try to set the id in a class using the workflow it gives me the aforementioned message of temporary id. I don't want to commit in the middle like i did before in order to get the id, or to try to manually keep the keys of the workflow with a custom sequence or something, or to update the id after commit.

You'll need to write your library so that it deals with Java objects which have no knowledge of how they are to be persisted in a database. Once you write code which operates on primary keys, you'll either need to persist the objects in a database already or start using UUIDs. Either way is a step away from the promise of an ORM: to abstract the realities of database storage from the objects your code deals with.

As far as your URL problem is concerned, you are pretty much sunk if your application has to be sessionless. Which is why any application which begins to have a sophisticated workflow will need to keep objects server-side within a session. Then you have no requirement to create URLs which embed primary keys.

In short, you are finding it hard to create and manage primary keys in your component mainly because it is the wrong approach for code like this.

Ari Maniatis


-- 

-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Id problem when trying to make a component decoupling a module

Posted by ha...@welinux.cl.
Hi,

I've crashed again with the infamous message Can't get primary key from temporary id.

This has happened me constantly in the area of reusing code.

Some weeks ago, i needed to create an objet and then send its id in the url to a web control responsible to filling it. I was forced to commit between the transaction to obtain the id. The process was simple and we were able to live with it.

Now we are forcing something more complex: our company developped a very complex software and in the process we developed a very robust workflow engine to support it.
We decided to decouple the workflow component from the application where it was born. The idea is to make a jar file for using in other projects, and not resort to copy paste.

As you can see, the extraction means decoupling the workflow and associated classes from the rest of the classes of the system.

In order for workflow classes not to depend on any particular class, it was necessary to remove the relationships in cayenne and try to make a soft bind with cayenne using the id of the related workflow in the classes that wich to use it.

The problem is when we try to set the id in a class using the workflow it gives me the aforementioned message of temporary id. I don't want to commit in the middle like i did before in order to get the id, or to try to manually keep the keys of the workflow with a custom sequence or something, or to update the id after commit.

Note: Sharing of the map was very easy and worked fine.

Any help will be appreciated.

Thanks
Hans

Re: Model Refactor, move table from one Map to Another

Posted by ha...@welinux.cl.
Aristides,

Thank you. Actually i resolved it with a mix of all the advices, i made a copy of the schema for surgery, the removed all the unnecesary tables using the modeler, then fixed each relation one by one...

Hans

----- "Aristedes Maniatis" <ar...@maniatis.org> escribió:

> On 2/10/09 7:24 AM, Evgeny Ryabitskiy wrote:
> > As an instant solution I can advise you to open "*.map.xml" for
> your
> > both maps and copy-paste everything connected to your Table from
> one
> > xml file to another.
> 
> And if you use a tool which validates XML against a schema (eg Oxygen)
> then you can be fairly sure it will still work once you have edited it
> by hand.
> 
> Ari
> 
> -- 
> 
> -------------------------->
> Aristedes Maniatis
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

-- 
Hans Poo, WeLinux S.A. http://www.welinux.cl
Oficina: 697.25.42, Celular: 09-319.93.05
Bombero Ossa # 1010, Santiago


Re: Model Refactor, move table from one Map to Another

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 2/10/09 7:24 AM, Evgeny Ryabitskiy wrote:
> As an instant solution I can advise you to open "*.map.xml" for your
> both maps and copy-paste everything connected to your Table from one
> xml file to another.

And if you use a tool which validates XML against a schema (eg Oxygen) then you can be fairly sure it will still work once you have edited it by hand.

Ari

-- 

-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A

Re: Model Refactor, move table from one Map to Another

Posted by ha...@welinux.cl.
Evgeny,

I'll give it a try, just being too lazy...

Thanks
Hans

----- "Evgeny Ryabitskiy" <ev...@gmail.com> escribió:

> 2009/10/2  <ha...@welinux.cl>:
> > Hi List,
> >
> > In order to reuse some logic i'm trying to refactor an old model and
> i was wondering if there is a way to move a Table and its associated
> Entity from one map to another, i'm using just one domain.
> >
> > I tried in the last 3.0M6 modeler, the cut & paste looks very nice,
> i was crossing my fingers, but after the move, all the object and db
> relationships gets broken, the tables i'm trying to refactor have lots
> of relationships. May be somebody has writen some script or knows of
> some guide for doing this ?
> >
> > Thanks
> > Hans
> >
> 
> Hello!
> 
> As an instant solution I can advise you to open "*.map.xml" for your
> both maps and copy-paste everything connected to your Table from one
> xml file to another. It's common XML, I's not so hard, believe me.
> If you wish to do it in more automatic way, write your XML-parser
> that
> is looking for all Table relations and coping them. Also not so hard.
> After it you can contribute you Table-Transporter to Cayenne modeler
> as a refactor extension ;)
> 
> Still a chance that some one else from List share with you such
> tool....
> 
> Best regards,
>  Evgeny Ryabitskiy.

-- 
Hans Poo, WeLinux S.A. http://www.welinux.cl
Oficina: 697.25.42, Celular: 09-319.93.05
Bombero Ossa # 1010, Santiago


Re: Model Refactor, move table from one Map to Another

Posted by Evgeny Ryabitskiy <ev...@gmail.com>.
2009/10/2  <ha...@welinux.cl>:
> Hi List,
>
> In order to reuse some logic i'm trying to refactor an old model and i was wondering if there is a way to move a Table and its associated Entity from one map to another, i'm using just one domain.
>
> I tried in the last 3.0M6 modeler, the cut & paste looks very nice, i was crossing my fingers, but after the move, all the object and db relationships gets broken, the tables i'm trying to refactor have lots of relationships. May be somebody has writen some script or knows of some guide for doing this ?
>
> Thanks
> Hans
>

Hello!

As an instant solution I can advise you to open "*.map.xml" for your
both maps and copy-paste everything connected to your Table from one
xml file to another. It's common XML, I's not so hard, believe me.
If you wish to do it in more automatic way, write your XML-parser that
is looking for all Table relations and coping them. Also not so hard.
After it you can contribute you Table-Transporter to Cayenne modeler
as a refactor extension ;)

Still a chance that some one else from List share with you such tool....

Best regards,
 Evgeny Ryabitskiy.

Re: Model Refactor, move table from one Map to Another

Posted by Mike Kienenberger <mk...@gmail.com>.
You can always edit the xml file by hand.
Depending on what you're doing, that sometimes is easier for really
complicated operations.

If I wanted to preserve a table and just the relationships to other
specific tables I knew were going to be in a destination map, I'd
probably delete everything but the tables containing the relationships
I wanted using the modeler, then I'd manually go into the xml file and
remove the tables (but not the relationships) I didn't want, then I'd
copy what remained into the new map's xml file.

On Thu, Oct 1, 2009 at 5:06 PM,  <ha...@welinux.cl> wrote:
> Hi List,
>
> In order to reuse some logic i'm trying to refactor an old model and i was wondering if there is a way to move a Table and its associated Entity from one map to another, i'm using just one domain.
>
> I tried in the last 3.0M6 modeler, the cut & paste looks very nice, i was crossing my fingers, but after the move, all the object and db relationships gets broken, the tables i'm trying to refactor have lots of relationships. May be somebody has writen some script or knows of some guide for doing this ?
>
> Thanks
> Hans
>