#1 2015-07-04 03:03:17

terryc
Member
Registered: 2015-07-04
Posts: 16

How to persist a complete domain?

Hello,
Imagine there are several classes in a domain:
A <- B <-C
    <- D
    <- E

Where D has a reference to C and E has a reference to D.

For example, how can one create a simple in-memory database? There are several issues i don't understand:
- TDDDRepositoryRestFactory.ComputeSQLRecord([C, D, E]) creates several duplicates (on all common ancestors). OK, i can remove the duplicates, but i would expect the operation to be able to identify the common ancestors.
- then TSQLRestStorageInMemory.Create takes only a single class as a parameter ???

How can the whole domain be persisted?

In a real application, there would be many domain classes, broken down in sub-domains.

FYI Environment : Lazarus/FPC 2.7.1. No Delphi environment.

Offline

#2 2015-07-04 04:54:11

terryc
Member
Registered: 2015-07-04
Posts: 16

Re: How to persist a complete domain?

Creating a complete model:
  SomeModel = TSQModel.Create([Set of SQL classes]) //Not domain classes, SQL classes.

Creating the client database (as in client/server):
  Client :=  TSQLRestClientDB.Create(ClientModel, ServerModel, ChangeFileExt(Application.ExeName,'.db3'), TSQLRestServerDB);

Populating the tables (if missing or needed to update):
  TSQLRestClientDB(globalClient).Server.CreateMissingTables(0);

This works in Lazarus + FPC 2.7.1

Offline

#3 2015-07-04 06:21:27

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to persist a complete domain?

Use TSQLRestServerFullMemory to create a simple TObjectList stored database.
http://synopse.info/files/html/Synopse% … l#TITL_138

Or use  SQLITE_MEMORY_DATABASE_NAME with a SQlite3 TSQLRestServerDB/TSQLRestClientDB class.

Online

#4 2015-07-04 08:04:26

terryc
Member
Registered: 2015-07-04
Posts: 16

Re: How to persist a complete domain?

Thank you very much. I will try that.

I would suggest ComputeSQLRecord does not duplicate the code for the ancestor classes, if they are common.

Best regards,
Thierry

Offline

#5 2015-07-04 09:02:11

terryc
Member
Registered: 2015-07-04
Posts: 16

Re: How to persist a complete domain?

OK, i tried with TSQLRestServerFullMemory, using the following code in initialisation and finalisation:
Without the filename in the tableclient for class A, the database is not saved,
With the filename in the table client for class A, it is stored in its particular file, not the general file for the whole database.
What am I missing?

initialization
  Database  :=  TSQLRestServerFullMemory.Create( Model, ChangeFileExt(Application.ExeName,'.json') );
  gTableA    :=  TSQLRestStorageInMemory.Create( TSQLA, Database, ChangeFileExt(Application.ExeName,'.A.json'));
  gTableB    :=  TSQLRestStorageInMemory.Create( TSQLB, Database, ChangeFileExt(Application.ExeName,'.B.json'));
finalization
 FreeAndNil(model);
  FreeAndNil(gTableA);
  FreeAndNil(gTableB);
  Database.ExportServer;
  FreeAndNil(Database); 
end.

Last edited by terryc (2015-07-04 09:03:06)

Offline

#6 2015-07-04 09:45:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: How to persist a complete domain?

If TSQLA and TSQLB are part of the main Database.Model, no need to create the TSQLRestStorageInMemory instance.

TSQLRestServerFullMemory will create the TSQLRestStorageInMemory for you.

Online

#7 2015-07-05 00:26:44

terryc
Member
Registered: 2015-07-04
Posts: 16

Re: How to persist a complete domain?

Thank you!
Indeed it is much simpler than I thought. The only object to create is the TSQLERestServerFullMemory. The TSQLRestStorageInMemory are not needed, as every operation can directly be performed on the RestServer.

initialization
  Database  :=  TSQLRestServerFullMemory.Create( Model, ChangeFileExt(Application.ExeName,'.json') );
finalization
  FreeAndNil(model);
  Database.ExportServer;
  FreeAndNil(Database); 
end.

and in the application layer:

   objectA:= TSQLRecordA.CreateAndFillPrepare(Database, ''); 
   ...
  Database.Add(objectA, true);

Last edited by terryc (2015-07-05 00:27:16)

Offline

Board footer

Powered by FluxBB