Summary: Using the GigaSpaces External Data Source interface to persist data stored in the space

Overview

GigaSpaces Space Persistency interface is the key middleware connection link for loading and storing data to and from persistent data sources.

.NET persistency is a GigaSpaces implementation on top of Java SpaceDataSource and SpaceSynchronizationEndpoint classes.

Before you begin, it is recommended to read the Space Persistency section.

For a fully running example using the Mirror Service see GigaSpaces Root\XAP.NET\NET vX\Examples\StockSba folder.

.NET Specific Settings

Creating a Space with ExternalDataSource

You can either use GigaSpaces NHibernate implementation, or create a custom implementation:

GigaSpaces NHibernate SQL Data Source Implementation

The following code demonstrates how to start an embedded space with GigaSpaces NHibernate SqlDataSource implementation as its External Data Source.

//Create a new space configuration object that is used to start a space
SpaceConfig spaceConfig = new SpaceConfig();
//Start a new ExternalDataSource config object
spaceConfig.ExternalDataSourceConfig = new ExternalDataSourceConfig();
//Start a new instance of NHibernateExternalDataSource and attach it to the config
spaceConfig.ExternalDataSourceConfig.Instance = new NHibernateExternalDataSource();
//Create custom properties that are required to build NHibernate session factory
spaceConfig.ExternalDataSourceConfig.CustomProperties = new Dictionary<string, string>();
//Point to NHibernate session factory config file
spaceConfig.ExternalDataSourceConfig.CustomProperties.Add(NHibernateExternalDataSource.NHibernateConfigProperty, 
"[NHibernate config file]");
//Optional - points to a directory that contains the NHibernate mapping files (hbm)
spaceConfig.ExternalDataSourceConfig.CustomProperties.Add(NHibernateExternalDataSource.NHibernateHbmDirectory,
 "[NHibernate hbm files location]");

//Starts the space with the External Data Source
ISpaceProxy persistentSpace = GigaSpacesFactory.FindSpace("/./mySpace", spaceConfig);

Before using the ExternalDataSource.NHibernate practice, compile it by calling <GigaSpaces Root>\dotnet\practices\ExternalDataSource\NHibernate\build.bat.

You can create your own NHibernate session factory and pass it to the NHibernateExternalDataSource constructor. In this case, there's no need to use SpaceConfig.ExternalDataSourceConfig.CustomProperties.

For a demonstration of how to start a partitioned-sync2backup cluster with asynchronous NHibernate persistency, refer to the NHibernate External Data Source section.


Custom SQL Data Source Implementation

A custom .NET SqlDataSource implementation can be used as well.

The following code demonstrates how to start an embedded space with a custom .NET SqlDataSource implementation as its External Data Source.

//Create a new space configuration object that is used to start a space
SpaceConfig spaceConfig = new SpaceConfig();
//Start a new ExternalDataSource config object
spaceConfig.ExternalDataSourceConfig = new ExternalDataSourceConfig();
//Start a new instance of the custom implementation and attach it to the config
spaceConfig.ExternalDataSourceConfig.Instance = new *CustomImplementation*();
//if custom properties should be passed to the Init method put them here, otherwise there's no need to create a dictionary of custom properties
spaceConfig.ExternalDataSourceConfig.CustomProperties = new Dictionary<string, string>();
//Add custom properties to the dictionary
spaceConfig.ExternalDataSourceConfig.CustomProperties.Add("[Property name]", "[Property value]");

//Starts the space with the External Data Source
ISpaceProxy persistentSpace = SpaceProxyProviderFactory.Instance.FindSpace("/./mySpace", spaceConfig);

Advanced Options

The number of objects passed between the .Net IDataEnumerator (Part of the ISqlDataSource interface) to the server on each iteration can be changed, its default value is set to 1000.

This can be done by adding a custom property to the ExternalDataSourceConfig object.

spaceConfig.ExternalDataSourceConfig.CustomProperties = new Dictionary<string, string>();
//Add custom properties to the dictionary
spaceConfig.ExternalDataSourceConfig.CustomProperties.Add("iterator-batch-size", "[batch size]");

Server Side Logging

To enable the .NET ExternalDataSource adapter logging, refer to the GigaSpaces Logging section.

Creating Custom ExternalDataSource Implementation

To create a custom implementation, implement the GigaSpaces.Core.Persistency.ISqlDataSource interface.

Before creating a custom implementation, read the following considerations.

See an example for the NHibernate implementation under <GigaSpaces Root>\dotnet\practices\ExternalDataSource\NHibernate.

GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence