|
OverviewYou may find running examples at:
Write-Read Through Example Using JDBCThis 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:
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. 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
Write-Read Through Example Using HibernateThis 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:
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. 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
|
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.
Add Comment