Handling Sequence Numbers(oracle)

Posts   
 
    
saravana
User
Posts: 63
Joined: 11-Nov-2010
# Posted on: 07-Dec-2011 10:54:56   

Hi,

With reference to the following thread:

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=20420

We now have the WPF application which can connect to central database and local database. I planned to do a manual replication of data from central database to local data database. I have set the sequence number in central database starting from 1 million and it will increment by 1. In my local database instance I have set the sequence number starting from 1 to (1 million-1).

I want to insert data created/updated in the server db to local db.Here I want to preserve the PK(generated by Sequence Number through LLBLGen with Oracle) of the all the records in the local database. So what is the best way to get the data from multiple tables(related with each other) from server database to local database.

I have a entity and its related entities fetched using the prefetch path. Could please suggest a way to save the loaded data into the local database with the key values un-changed?


TemplateortpartversionCollection templateOrTpartVersionCollection = new TemplateortpartversionCollection();
                        IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.TemplateortpartversionEntity);
                        prefetchPath.Add(TemplateortpartversionEntity.PrefetchPathAbstractterm);
                        prefetchPath.Add(TemplateortpartversionEntity.PrefetchPathFormsuser);
                        prefetchPath.Add(TemplateortpartversionEntity.PrefetchPathKeywordoccurrences);
                        prefetchPath.Add(TemplateortpartversionEntity.PrefetchPathTemplateortpart);
                        prefetchPath.Add(TemplateortpartversionEntity.PrefetchPathTemplatepartversion);
                        prefetchPath.Add(TemplateortpartversionEntity.PrefetchPathTemplateversion);

IPredicateExpression filter = new PredicateExpression();
                        filter.Add(TemplateortpartversionFields.Tortpartid == documentVersionEntity.Templateid);
                        filter.AddWithAnd(TemplateortpartversionFields.Tortpartvid == documentVersionEntity.Templatevid);
                        templateOrTpartVersionCollection.GetMulti(filter, prefetchPath);

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Dec-2011 11:46:24   

What you are talking about is Database Replication, and there are database tools specific for data replication. That's much better than handling it yourself.

But if you have to do it, people fall back to some design patterns, which might not suit everyone. Like having composite PKs with one field identifying the originating server.

One last option is to use the LLBLgen Pro Designer to remap the required tables, into another entities specific for the replication task, in which you don't assign a sequence, so you can insert records without using the database sequence. I haven't tried this approach before but I guess it should work.

saravana
User
Posts: 63
Joined: 11-Nov-2010
# Posted on: 08-Dec-2011 11:37:57   

Hi,

One last option is to use the LLBLgen Pro Designer to remap the required tables, into another entities specific for the replication task, in which you don't assign a sequence, so you can insert records without using the database sequence. I haven't tried this approach before but I guess it should work.

I have added the new entities for table which has the sequence numbers. For e-g For the entity 'Artifact', I have added a new entity 'ArtifactLocal' in the designer. I didn't configure the sequence number definition for this local entity. But it is created without any relations to other tables. If I manully add the relations for this local entity, is it possible to use this entity in the prefectch paths? and also If I save a related entity first (Document), whether the AtifactLocal entity content will be saved automatically?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Dec-2011 12:07:01   

You can use these entities as normal entities. The only difference would be when inserting. These entities will let you insert PK, the original ones won't and will use the designated Sequence.