Re: opening multiple databases from same program

Abel Birya <[email protected]> Fri, 9 Jul 2010 19:20:34 +0300
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hi,

I had the same issue when I started using SimpleORM since I was doing a lot
of data migration scripts from one database to another. This is the strategy
that I used to achieve my goals;

For example if I have an entity _User and I need to transfer it to another
db. I would name the corresponding entity User. I would then follow the
below procedure to achieve a seamless transfer process.

SSessionJdbc ses = SSessionJdbc.open(connection1, "db1");
ses.begin;
// create a method to retrieve users eg
List<_User> users = _User.getUsers(ses);
// detach the records into a dataset
SDataSet ds = ses.commitAndDetachDataSet();
ses.close();

//retrieve the records from the dataset
users = ds.findAllRecords(_User.USER); // assuming that USER is the
SRecordMeta variable

//open the new connection
ses = SSessionJdbc.open(connection2, "db2");

for(_User _user: users) {
    ses.begin();
    //create the user on the other db and fill in the other variables such
as name etc
    User user = ses.createWithGeneratedKey();
    ses.commit();
}

ses.close();

Hope this helps.

Kind regards.
Abel

In the even

On Fri, Jul 9, 2010 at 7:02 PM, Franck Routier <[email protected]>wrote:

>
>
> Hi,
>
> well, AFAIK, you can't do that... !
>
> SSessionJdbc has built-in checks that a connection is single threaded
> using a ThreadLocal object. [I think Hibernate has some kind of best
> practice to achieve the same goal (I'm not formal here, I didn't use
> hibernate for years)]
>
> There is only one dataSource per SSessionJdbc and one SSessionJdbc per
> thread.
>
> You could implement a different strategy to handle this part. Some work
> was done along this path in a previous version of Simpleorm, for using a
> single JTA transaction per session. But it is not maintained.
> See simpleorm/extras/SConnectionEJB.java
>
> My question would be : what are you trying to achieve ?
>
> Franck
>
> Le vendredi 09 juillet 2010 à 17:11 +0200, Noel Grandin a écrit :
>
> >
> > Hi
> >
> > I'm opening multiple different databases from the same thread, which
> > is triggering this check:
> >
> > simpleorm.utils.SException$Error: Thread's SSession already open [SS
> > 1.SkyMon]
> > [0@17:08:40.976] !SE>: at
> > simpleorm.sessionjdbc.SSessionJdbc.innerOpen(SSessionJdbc.java:129)
> > [0@17:08:40.976] !SE>: at
> > simpleorm.sessionjdbc.SSessionJdbc.open(SSessionJdbc.java:88)
> > [0@17:08:40.976] !SE>: at
> > simpleorm.sessionjdbc.SSessionJdbc.open(SSessionJdbc.java:108)
> >
> >
> > What do I do?
> >
> > Thanks, Noel Grandin
> >
> >
> >
> >
> >
> >
> >
> > __________________________________________________________
> > Disclaimer: http://www.peralex.com/disclaimer.html
> >
> >
> >
> >
> >
>
>  
>