XAP

Part 4, Convert a Program

This topic is a hands/on introduction to GigaSpaces XAP. It is designed to give you a quick, easy introduction to the GigaSpaces system.

This introduction consists of four parts:

  • Part 1 — Setting the Environment — Prepare a database that will be imported into GigaSpaces. In these examples, we will use data from the PostgreSQL database.

  • Part 2 — Launch Ops Manager — Run and view the GigaSpaces user interface.

  • Part 3 — Import a Database — Bring data from the PostgreSQL database into XAP, the GigaSpaces in-memory grid, and run some SQL operations.

  • Part 4 — Convert a Program (this topic) — Explore the tools to convert a Java program from JDBC access to the GigaSpaces Java API.

Need assistance or further information? Don't hesitate to contact us — we're here to help!

The following steps will show you how to convert a Java program that uses PostgreSQL commands, to a program using the GigaSpaces Java API. This will result in a significant boost to the program's performance, and will make the code accessible to data in the GigaSpaces in-memory data grid.

Converting Code

We are doing this for two reasons:

The essential code is shown below.

PostgreSQL Program GigaSpaces Program
 Connection conn = DriverManager.getConnection(CONNECTION_STRING,USER,PASSWORD);
 Statement stmt = conn.createStatement();
 ResultSet rs=stmt.executeQuery("SELECT * FROM Persons where personid = 1");
 rs.next();
 String PersonName = rs.getString("personname");
GigaSpace gigaSpace = new GigaSpaceConfigurer(new SpaceProxyConfigurer("demo")
          .lookupLocators("localhost").lookupGroups("xap-16.1.0")).gigaSpace();
String PersonName = gigaSpace.readById(Persons.class, 1).getPersonname();

Explanation of GigaSpaces Code

Following is a detailed breakdown of the GigaSpaces example.

SpaceProxyConfigurer("demo") — connect to a Space named "demo". The demo space must already be deployed in the GigaSpaces grid.

lookupLocators("localhost") — URL of the GigaSpaces grid. Here we are running a local instance.

lookupGroups("xap-16.1.0")).gigaSpace() — service identifier

readByIdreadById is one of the GigaSpaces methods available to access the grid data. It returns a single record property instance (record).

(Persons.class, 1) — specifies the first property (field) in the Persons object (table)

getPersonname() — run the "getter" method to obtain the Personname property

See Operations for more information about the GigaSpaces Java API.

What's Next?

More information is available in the GigaSpaces documentation, or feel free to contact us — we're here to help!