Many databases and its interactions

hi Wagner

I have 2 databases: global and another called standard

each one with mapped exclusive entities that do not interact with each other.

However I need now to create a POS software that operates locally (sqlite) BUT can connect, if available to the remote.

So I have now the globallocal and standardlocal. 

Those databases are equal to the previous ones, exact same entities. I have mapped respectively the same entity in each one.

Now my question: I have TEntityUser on Global and I want it to be persisted on GlobalLocal. I have a connection for each one with its respective TObjectManager.

is it valid doing this: (pseudo code)

user:= global.manager.find<tentityuser>(1)

as a mean to copy from one database to the other, since the entities are identical and both mapped?

I need also that the GUID, that is the ID of the entity, keep the same. It is just a way to mirror some records of some entities only, to have it locally or vice-versa when needed.



It won't work directly because when you do "Save" it will raise an error saying that the entity already has an ID (Guid). But you can workaround this by changing the mapping of the local sqlite to use a generator None. Here is some example of code you can use (create a specific mapping for the local database).

We are actually considering implementing such replicating mechanism native in Aurelius. If you have any suggestion about how you expect this to work, what would make your life easier, let me know, we are gathering information to define how the Aurelius replication system will work.

  MapCache := TMappingSetup.Create;
    ExplorerCache := TMappingExplorer.Create(MapCache);
    ExplorerCache.GetId(TSistemaCadastroSistema).IdGenerator := TIdGenerator.None;
    ExplorerCache.GetId(TSysEstilos).IdGenerator := TIdGenerator.None;
    ExplorerCache.GetId(TSysUsersEstilos).IdGenerator := TIdGenerator.None;
    ExplorerCache.GetId(TSysLayouts).IdGenerator := TIdGenerator.None;
    ExplorerCache.GetId(TSistemaDicionario).IdGenerator := TIdGenerator.None;
    ExplorerCache.GetId(TSistemaParametros).IdGenerator := TIdGenerator.None;
    ExplorerCache.GetId(TCmsMashup).IdGenerator := TIdGenerator.None;

Thanks for the quick answer.

I will have to implement a switching mechanism, because I do need that TidGenerator.GUID working when doing save on the local database, I will set to none only when doing the copy, and I understand that this needs to happen in both directions.

About the replication I can give  you more info when I have my replication done :):):):)

However I would switch to Aurelius method as soon as it is available. 

Some Items (eventually some obvious to you, but)

- a way to select the entities that should be replicated, could be just one.
- replicate between any database supported (my case I have my remote connection can be elevatedb or remotedb, and my local is sqlite)
- automatic replication when both databases are available or assisted mode when is called to replicate. This is important since if  you in as mobile you have slow (3g) and fast (wifi) situations. If 3g is available eventually some replication can be done (software contact the remote to retrieve one record and save locally) but bulk transactions should not happen
- there is the constraints to take in account, so that will eventually means that replicating one record will force many others to be replicated together. Not sure all the consequences of this. I do have this situation but it is limited right now, since I am doing it manually

how does work SaveOrUpdate, should it work in this case? or Update only happens when the record is already in the table (so  you use sql update for that)

just one thing on the replication: it has to work over remotedb, not sure about xdata yet. 

SaveOrUpdate checks if the passed object has an id. If an id exists, it performs Update, otherwise, perform Save.

Thanks for the info about replication. The databases to be replicated would be any supported by Aurelius, since Aurelius is database agnostic. The connection check will probably be out of scope of Aurelius replicator, it will have several classes and methods to give you freedom about what to do but it will probably be up to you to check if connection exists and what operations to perform. 
Yes, I think most important is define what Aurelius features and behavior it will be, like choosing entities, what to do with associations, what to do with pending updates, conflicting objects, etc.