Can xdata query parser be used with outside xdata server

use case is this
Our partner creates a custom made script (using TMS Scripter) for customers.
Some cases customer has xdataserver in infrastructure and in some cases not. (depending on customer)
If would like to provider our partner simple method for searching customer in script code like

lCustomerlist := CustomerModule.SearchCustomers('email eq ''mika@skj.fi''');
is it possible to use xdata's queryparser to transform query to aurelius criteria?
(with reasonable work)
my other option is to force local xdataserver installation.

Yes, it's possible. You can actually start from here: Service Operations | TMS XData documentation.

You can see that you can create an Aurelius criteria from a XData query. Such code is attached to XData, but if you check the actual implementation of such CreateCriteria<T> method (in unit XData.Server.Module), you will see it's relatively simple and you can copy/paste the code and adapt to your needs to create criteria from XData query:

function TXDataOperationContext.CreateCriteria<T>(Manager: TObjectManager; Query: TXDataQuery;
  Model: TXDataAureliusModel; BaseType: TXDataStructuredType): TCriteria<T>;
var
  QueryInfo: TXDataQueryInfo;
  Builder: TXDataCriteriaBuilder;
  TargetType: TXDataEntityType;
begin
  TargetType := Model.GetEntityTypeByClass(T);
  if BaseType = nil then
    BaseType := TargetType;

  QueryInfo := TXDataQueryInfo.Create(BaseType, Query);
  try
    QueryInfo.Solve;
    Builder := TXDataCriteriaBuilder.Create(Model, QueryInfo);
    try
      Result := Manager.Find<T>;
      try
        Builder.UpdateCriteria(Result);
      except
        Result.Free;
        raise;
      end;
    finally
      Builder.Free;
    end;
  finally
    QueryInfo.Free;
  end;
end;
1 Like

thanks for this.
I have tried to implement this, seem very simple.
But how to initialize Model correctly?
I have used lModel:= TXDataAureliusModel.create;
Entities are in default model.

Model.GetEntityTypeByClass(t) raises exception EXDataEntityTypeFromClassNotFound
Entity type not found for class "TCustomer"

While debugging I found than model.Schemas is empty.
My scripting application knows entities . I checked it byt calling objectmanager.find(tcustomer,1) in my script befor other operations.

So I think I'm missing something from initialization.

You can use this:

Model := TXDataAureliusModel.Default;
1 Like

ok, now its working. Thanks!

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.