Show/Hide Toolbars

TMS XData Documentation

Navigation: Getting Started

Creating the Server Manually

Scroll Prev Top Next More

Here we describe the steps to create the XData server manually. You can alternatively use the XData Server Wizard:

 

1. Create an IDBConnectionFactory interface

2. Create an IDBConnectionPool interface

3. Create a TXDataServerModule object

4. Create a THttpSysServer, add the module to it and start the server

 

 

1. Create an IDBConnectionFactory interface

 

The IDBConnectionFactory interface is used to create TMS Aurelius IDBConnection interfaces which will be used by the server to connect to the desired database (in that database Aurelius objects will be persisted). You can read more details on the specific topic here: IDBConnectionFactory interface. Below we provide a code example that creates an IDBConnectionFactory interface which produces IDBConnection interfaces that connect to an MS SQL Server database, based on an existing TSQLConnection component named SQLConnection1 in a data module TMyConnectionDataModule.

 

uses 
  {...}, Aurelius.Drivers.Interfaces, Aurelius.Drivers.Base,
  Aurelius.Drivers.dbExpress;
 
var
  ConnectionFactory: IDBConnectionFactory;
begin
  ConnectionFactory := TDBConnectionFactory.Create(
      function: IDBConnection
      var
        MyDataModule: TMyConnectionDataModule;
      begin
        MyDataModule := TMyConnectionDataModule.Create(nil);

        Result := TDBExpressConnectionAdapter.Create(MyDataModule.SQLConnection1, MyDataModule);
      end
    ));
 
  // Use the ConnectionFactory interface to create an IDBConnectionPool interface
end;

 

2. Create an IDBConnectionPool interface

 

The IDBConnectionPool interface is used by the server to retrieve an IDBConnection interface when it is needed. It holds a list of such interfaces, and if there is none available, it uses the IDBConnectionFactory interface to create a new one. Example:

 

uses 
  {...}, Aurelius.Drivers.Interfaces, XData.Aurelius.ConnectionPool;
 
var
  ConnectionPool: IDBConnectionPool;
  ConnectionFactory: IDBConnectionFactory;
begin
  {...}
  ConnectionPool := TDBConnectionPool.Create(
    50// maximum of 50 connections available in the pool
        // Define a number that best fits your needs
    ConnectionFactory
  );
 
  // Use the IDBConnectionPool interface to create the XData server module
end;

 

3. Create a TXDataServerModule object

 

The TXDataServerModule is the main class of the XData server. It is a Sparkle server module that is added to the Sparkle server for a specific address. Example:

 

uses
  {...}, XData.Server.Module;
var
  XDataModule: TXDataServerModule;
  ConnectionPool: IDBConnectionPool;
begin
  {...}
  XDataModule := TXDataServerModule.Create('http://server:2001/tms/xdata', ConnectionPool);

 

4. Create a THttpSysServer, add the module to it and start the server

 

Finally, create a TMS Sparkle THttpSysServer object, add the XData module to it, and start the server. Example:

 

uses
  {...}, Sparkle.HttpSys.Server, XData.Server.Module;
var
  XDataModule: TXDataServerModule;
  Server: THttpSysServer;
begin
  Server := THttpSysServer.Create;
  Server.AddModule(XDataModule);
  Server.Start;
end;

 

Later on, do not forget to destroy the Server object instance when the application finishes.