Read-Through and Write-Through Examples

  GigaSpaces 5.X

Documentation Home
Quick Start Guide
Release Notes

Previous release

  Search Here
Searching GigaSpaces Platform 5.X Documentation

                                               

This page is specific to:
GigaSpaces 5.x

If you're interested in another version, click it below:
GigaSpaces 6.0
[GigaSpaces 6.5]

Overview

You may find running examples at:

  • <GigaSpaces Root>\examples\Advanced\Data_Grid\Database-Integration\jdbcCaheStore
  • <GigaSpaces Root>\examples\Advanced\Data_Grid\Database-Integration\HibernateCaheStore

Write-Read Through Example Using JDBC

This example demonstrates loading/storing data into/from the space using CacheLoader/Store implemented that uses JDBC API to map space objects to external database tables.

The example demonstrates Space API and Map API applications:

  • Space API – write ,writeMultiple, read, take, readMultiple, takeMultiple using null templates, non-null templates and SQLQuery templates with or without transactions.
  • Map API – put, get, putAll, getAll with or without transactions.

The Person class that is used both with the Space API and the Map API, is mapped into the database using standard JDBC Calls.

When using the Space API, the relevant space schema includes the following:

space-config.persistent.enabled=true
space-config.persistent.CacheLoaderClass=com.j_spaces.examples.jdbccachestore.spaceapi.CacheStoreImpl
space-config.persistent.StorageAdapterClass=com.j_spaces.sadapter.cache.CacheAdapter
space-config.persistent.DataBaseName=jdbc:hsqldb:hsql://localhost:9003
space-config.engine.cache_policy=0

When using the Map API, the relevant space schema includes the following:

space-config.persistent.enabled=true
space-config.persistent.CacheLoaderClass=com.j_spaces.examples.jdbccachestore.mapapi.CacheStoreImpl
space-config.persistent.StorageAdapterClass=com.j_spaces.sadapter.cache.CacheAdapter
space-config.persistent.DataBaseName=jdbc:hsqldb:hsql://localhost:9003
space-config.engine.cache_policy=0

When using the space API, the Person class extends the MetaDataEntry.
The Person class constructor includes explicit generation of the Entry UID:

public Person(String firstName, String lastName, Integer id) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.id = id;
		String entryUID = ClientUIDHandler.createUIDFromName( String.valueOf(id),
		Person.class.getName() );
		EntryInfo	entryInfo = new EntryInfo( entryUID, 0 );
        __setEntryInfo( entryInfo );
	}

Running and Compiling the Example

  1. Execute bin\compile.bat/sh to compile the example or run ant from the example root folder.
  2. Running the example:
    • To run the example using the CacheLoader implementation for the Space API:
      Execute bin\startAllSpaceAPI.bat.
      This will clean existing HSQL database files, and start a space instance configured to use the Space API CacheStore.
    • To run the example using the CacheLoader implementation for the Map API:
      Execute bin\startAllMapAPI.
      This will clean existing HSQL database files, and start a space instance configured to use the Map API CacheStore.
  3. Start the application.
    • Using the Space API:
      > run_SpaceAPIApplication
    • Using the Map API:
      > run_MapAPIApplication
You may view database records by running startHSQLgui.

Write-Read Through Example Using Hibernate

This example demonstrates loading/storing data into/from the space using Hibernate CacheLoader/Store to map space objects to external database tables.

The example uses the Space API with the write, writeMultiple, read, take, readMultiple, takeMultiple using null templates, non-null templates and SQLQuery templates.

The space can be started in different topologies:

  • startAllPartitionedCentralDatabase – partitioned topology persists the data via Hibernate CacheStore in synchronized mode into one central database.
  • startAllReplicatedCentralDatabase – synchronized replicated topology persists the data via Hibernate CacheStore in synchrnized mode into one central database.
  • startAllPartitionedBackupMirrorMode – partitioned and backup topology using Mirror Service via Hibernate CacheStore to persist the data in asynchronized mode into the database.
  • startAllReplicatedMirrorMode – synchronized replicated topology using Mirror Service via Hibernate CacheStore to persist the data in asynchronous mode into the database.
  • startAllReplicatedNonCentralDatabase – synchronized replicated topology persists the data via Hibernate CacheStore in synchronized mode into different database instance.

In a clustered space that uses Hibernate CacheStore, you should start the space using the following property:

-Dcom.gs.cluster.cache-loader.external-data-source=true

When the clustered space uses a central database for the Hibernate CacheStore, you should start the space using the following property:

-Dcom.gs.cluster.cache-loader.central-data-source=true

When the clustered space uses different database instances for each space instance for the Hibernate CacheStore, you should start the space using the following property:

-Dcom.gs.cluster.cache-loader.central-data-source=false

The Person Class that is used is mapped into the database using the Hibernate Person.hbm.xml mapping file.

The space schema uses the following properties (cachestore1.properties) where the space-config.persistent.StorageAdapterURL points to the folder where the hibernate.cfg.xml is located.

space-config.persistent.enabled=true
space-config.persistent.StorageAdapterClass=com.j_spaces.sadapter.cache.CacheAdapter
space-config.persistent.CacheLoaderClass=com.gigaspaces.hibernate.HibernateCacheStoreImpl
space-config.engine.cache_policy=0
space-config.persistent.StorageAdapterURL=/config/node1/

The Person class extends the MetaDataEntry and includes also setter and getter methods.
The Person class constructor includes explicit generation of the Entry's UID:

public Person(String firstName, String lastName, Integer id) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.id = id;
		String entryUID = ClientUIDHandler.createUIDFromName( String.valueOf(id),
		Person.class.getName() );
		EntryInfo	entryInfo = new EntryInfo( entryUID, 0 );
        __setEntryInfo( entryInfo );
	}

Running and Compiling the Example

  1. Execute bin\compile.bat/sh to compile the example ot run ant from the example root folder.
  2. Select one the scripts to run your preferred topology:
    • startAllPartitionedCentralDatabase – partitioned topology persists the data via Hibernate in synchronized mode into one central database.
    • startAllReplicatedCentralDatabase – sync replicated topology persists the data via Hibernate in synchronized mode into one central database.
    • startAllPartitionedBackupMirrorMode – partitioned and backup topology using Mirror Service via Hibernate to persist the data in asynchronized mode into the database.
    • startAllReplicatedMirrorMode – synchronized replicated topology using Mirror Service via Hibernate to persist the data in asynchronous mode into the database.
    • startAllReplicatedNonCentralDatabase – sync replicated topology persists the data via Hibernate in sync mode into different database instances.
      In startAllPartitionedBackupMirrorMode or startAllReplicatedMirrorMode, make sure run the startMirror script first.
  3. Start the application – run_Application.bat.
    This will write objects with ID's 0-1000 and perform different space operations.
You may view database records by running startHSQLgui1.bat or startHSQLgui2.bat.

Wiki Content Tree


Your Feedback Needed!

We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.

Labels

 
(None)