Part 4, Convert a Program

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

This introduction consists of four parts:

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 SpaceClosed Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model. 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!