EMS.FireDACResource Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample is a server-client EMS demo that uses FireDAC components. The sample accesses an SQLite database. The connection parameters are defined in the TFDConnection component. If you experience problems with the connection verify these parameters.

It requires InterBase to be installed on the machine or to connect to a remote server. Make sure that the server is running before you run the example. InterBase is used to store the information about the server connections. You can use the EMS Console Server to display the statistics.

Location

You can find the FireDACResource sample project at:

Description

This sample demonstrates how to use an EMS package to extend the EMS Server to connect to an SQLite database using FireDAC components.

The first part consists of creating an EMS Package with a TDataModule where the FireDAC components are placed. It uses the TFDConnection component to establish the connection to the SQLite database. Once you run the package, the resource is registered on the EMS server and can be accessed by a client application using REST.

The FireDAC client needs a TEMSFireDACClient and a TEMSProvider to connect to the EMS Server and to retrieve the JSON data.

How to Use the Sample

Run the EMS Package

When you run the SampleEMSFireDACResourcePackage project, the EMSDevServer starts automatically. If the configuration file is missing, a wizard launches.

  1. Navigate to the location given above and open:
    • Delphi: SampleEMSFireDACResourcePackage.dpk
    • C++: SampleEMSFireDACResourcePackageCpp.cbproj
  2. Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
  3. The EMS Development Server opens. If it is the first time you are using EMS on the machine, you need to run the configuration wizard in order to create the EMS server configuration file.
    1. When the Confirm dialog opens, click Yes.
    2. Leave all the parameters by default and go through the different windows clicking Next.
    3. Click Finish to close the wizard.
    4. An Information window appears. Click OK.
  4. The server starts automatically. Minimize it.

Run the FireDAC Client Application

The client expects the EMSDevServer to be running at localhost:8080. If you are running the server at a different address, modify the properties of the TEMSProvider component.

  1. On the Project Manager, right-click on ProjectGroup1.
  2. Click Add Existing Project....
  3. Navigate to:
    • Delphi: Start | Programs | Embarcadero RAD Studio 10.2 Tokyo | Samples\Object Pascal\DataBase\EMS\FireDACResource\SampleEMSFireDACClient.dproj
    • C++: Start | Programs | Embarcadero RAD Studio 10.2 Tokyo | Samples\CPP\Database\EMS\FireDACResource\SampleEMSFireDACClientCpp.cbproj
  4. Press F9 or choose Run > Run.
  5. Click Get Tables to load the data from the SQLite database.
  6. Do some changes on the records and click Post Updates to commit the changes.

Implementation

EMS Package

The Resource Module has code to register a REST API resource. The resource is called "test". The resource defines a GET and a POST method.

Once you run the package and have the EMS server running, as a test, you can invoke the GET method using the browser http://localhost:8080/test.

FireDAC Client

The client application has a TEMSProvider component. This component identifies the address of the EMS Server (<code>http://localhost:8080</code>).

The client application also has a TEMSFireDACClient . This component identifies the name of a resource (test).

  • EMSFireDACClient1.GetData accesses http://localhost:8080/test with HTTP GET. JSON is returned by the GET.
  • EMSFireDACClient1.PostUpdates accesses http://localhost:8080/test with HTTP POST. JSON is sent with the POST.

The TFDSchemaAdapter is able to load from JSON and save to JSON.

On the client side, TFDSchemaAdapter is responsible for loading JSON into TFDMemTable, and for saving delta packages into JSON.

On the server side, TFDSchemaAdapter is responsible for saving query results to JSON and for loading a JSON delta and applying inserts, updates, and deletes to the database.

Uses

See Also

Personal tools
RAD Studio 10.2 Tokyo
Assistance