1

I've been trying to start a new project using mORMOt the DDD-way and have created a few classes and begun to test one of them in an easy/simple way. I used the regression test code from your DDD-sample about TUser and modified it to suit my class .

I have tried to minimize the code and hopefully, it could contain some clues for you to help me understand what's wrong here. I found that when only using the server, everything works ok but when using client the ORMselection won't find the data. I stripped down the code as much as possible and marked with some comments where it works and where it not works.

class procedure TInfraRepoPackageFactory.RegressionTestsPackage(test: TSynTestCase);
procedure TestOne(Rest: TSQLRest);
var cmd: IDomPackageCommand;
    qry: IDomPackageQuery;
    package: TPackage;
begin
  test.Check(Rest.Services.Resolve(IDomPackageCommand,cmd));
  package := TPackage.Create;
  try
      package.articleNo := 10000;
      test.check(cmd.Add(package)=cqrsSuccess);
    end;
    test.check(cmd.Commit=cqrsSuccess);
  finally
    package.Free;
  end;
  package := TPackage.Create;
  try
    test.Check(Rest.Services.Resolve(IDompackageQuery,qry));
      test.Check(qry.SelectByArticleNo(10000,false)=cqrsSuccess);  // <<-- Debugging shows that it will not find anything when using client.
      test.Check(qry.GetCount=1);                                             // <<-- getCount returns zero when using client.
    end;
  finally
    package.Free;
  end;

end;

var RestServer: TSQLRestServerFullMemory;
    RestClient: TSQLRestClientURI;
begin
  RestServer := TSQLRestServerFullMemory.CreateWithOwnModel([TSQLRecordPackage]);
  try // first try directly on server side
    RestServer.ServiceContainer.InjectResolver([TInfraRepoPackageFactory.Create(RestServer)],true);
    TestOne(RestServer); // sub function will ensure that all I*Command are released    // <<=== Works
  finally
    RestServer.Free;
  end;
  RestServer := TSQLRestServerFullMemory.CreateWithOwnModel([TSQLRecordPackage]);
  try // then try from a client-server process
    RestServer.ServiceContainer.InjectResolver([TInfraRepoPackageFactory.Create(RestServer)],true);
    RestServer.ServiceDefine(TInfraRepoPackage,[IDomPackageCommand,IDomPackageQuery],sicClientDriven);
    test.Check(RestServer.ExportServer);
    RestClient := TSQLRestClientURIDll.Create(TSQLModel.Create([TSQLRecordPackage]),@URIRequest);
    try
      RestClient.Model.Owner := RestClient;
      RestClient.ServiceDefine([IDomPackageCommand],sicClientDriven);
      TestOne(RestServer);                                                             // <<=== Works
      RestServer.DropDatabase;
      USEFASTMM4ALLOC := true; // for slightly faster process
      TestOne(RestClient);                                                             // <<=== DO NOT Work !!!!
    finally
      RestClient.Free;
    end;
  finally
    RestServer.Free;
  end;
end;

I also tried to put this question on the mORMot forum but the mailer can not reach the site. Got this message :

An error was encountered Error: Unable to send email. Please contact the forum administrator with the following error message reported by the SMTP server: "450 4.1.2: Recipient address rejected: Domain not found ".

larand
  • 773
  • 1
  • 9
  • 26

1 Answers1

0

I finally found what's wrong. In the agregate, class TPackage, I had set the property of packageNo to "stored AS_UNIQUE" - that resulted in that the commit just stored zero in that field and then the SELECT('packageNo=?,[10001]) couldn't find anything. I didn't realize that because the package object contained just 10001 and could never think of the possibility that the commit should store a 0. But when I tested with TSQLHttpServer and TSQLHttpClient and a real database I could see all records containing zeroes in the packageNo field. Then I understood that it must be something with this field that's wrong. When I looked up TPackage I found my mistake. I should have set the "STORED AS_UNIQUE" in the TSQLRecordPackage class instead, the one that's used by ORM.

The moral of the story... "OPEN YOUR EYES.. and you will see" ;-)

larand
  • 773
  • 1
  • 9
  • 26