Should I switch to adapter?

Posts   
 
    
stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 07-Aug-2007 10:49:25   

Hello,

I'm working on a fat-client style winform application. I'm currently using the selfservicing scenario, I like its ease of use and straightforward object oriented approach. Most of the time, I'll just have to fetch entities from the database, let the user modify them and finally save them back in that same database.

But in some scenarios, I would enjoy the possibility to fetch records from distant databases and save them to another, it's by far not the biggest part of my app, it's mostly about merging/synchronizing records between databases (the database schemas are the same).

Also in the future, I'd like to offer the possibility to mix local and remote operations... I mean for example editing Orders on a remote database server by using Customers and Articles from the local db.

Considering It's not too late, is it worth switching to adapter?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 07-Aug-2007 10:54:45   

I then would switch, yes. The one thing you'll miss is lazy loading.

Frans Bouma | Lead developer LLBLGen Pro
stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 07-Aug-2007 14:17:37   

It's so hard to live without.... cry

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 07-Aug-2007 15:41:21   

To me it, having always used adapter, it seems it would be hard to live with the loss of control in self servicing, all that fetching going on without me saying when. simple_smile

stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 07-Aug-2007 17:08:39   

I understand your point of view but mine is a bit... different.

I like the lazy loading feature because it's great if you need to fetch an entity from the database but don't know in advance which properties you will need (and so, which prefetch paths you should add).

Having to write things like :


DataAccessAdapter adapter = new DataAccessAdapter(true);
OrderEntity order = new OrderEntity(10254);
adapter.FetchEntity(order);
order.Customer = (CustomerEntity)adapter.FetchNewEntity(new CustomerEntityFactory(), 
    order.GetRelationInfoCustomer());
adapter.CloseConnection();

makes me wonder if my code is still object oriented. Talking about this line :

order.Customer = (CustomerEntity)adapter.FetchNewEntity(new CustomerEntityFactory(), 
    order.GetRelationInfoCustomer());

I'm really worried about having to write such code at 500-1000 places in my application code. Worst is that I haven't found a way to know if a related collection is empty or just hasn't been fetched yet.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 07-Aug-2007 17:27:34   

IF you really want to, you could of course design a format in which you want to transfer the data between the systems to sync. then at the sending side you use projection to project the data onto the objects to send and on teh receiving side you build new entities.

If it's just for syncing, you also could opt for a more low-level approach using database sync utilities or replication mechanisms

Frans Bouma | Lead developer LLBLGen Pro
stefcl
User
Posts: 210
Joined: 23-Jun-2007
# Posted on: 07-Aug-2007 17:49:02   

Using a database replication mechanism was my first idea, but I had to give it up. I need to fully control the replication process from my code.

About selfservicing and adapter, it seems like I have to choose between ease of use and flexibility... I wonder if I could use both and just share their validation logic...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 08-Aug-2007 15:16:42   

You can share validator classes among them, to the point where you might refer to IEntity2 or IEntity somewhere, but in general it should be possible.

Frans Bouma | Lead developer LLBLGen Pro