There is a business need to keep your data synchronzied using Oracle Databases or any other database for that matter. As a developer, you tend to foucus on using Oracle Dependency or OLEDB to synchronize your applications with the data but by incorporating TayzGrid we can do that for you in a seemless fashion.
TayzGrid is an elastic Open Source In-Memory Data Grid which improves application performance and scalability. Unlike a relational database which quickly becomes a bottleneck, TayzGrid scales linearly; allowing you to add more servers in order to increase transaction capacity in a linear fashion.
But when you store application data in the grid, you are creating multiple copies of that data; both in the data grid and your relational database. If this data in the database changes, you want to ensure the data grid is also updated so that there are never data consistency issues with the relational database.
TayzGrid provides an out-of-box database synchronization feature which allows to update itself when there are changes made to the data in the relational database. Database synchronization features are meant for specific types of usage and they can collectively handle a variety of scenarios for database synchronization. These features are:
If your database is Oracle 10g or later and running on either UNIX or Windows, using Oracle Dependency is a powerful feature.
Oracle Dependency can be specified for any item when you're adding or updating it in the data grid. Oracle Dependency is a SQL statement or a stored procedure call which corresponds to a dataset in the Oracle database. The Oracle database server then monitors this dataset for any changes (additions, updates, or removals). When changes occur, the Oracle server notifies the TayzGrid cluster. TayzGrid then either removes this item from the java data grid or reloads a fresh copy from the database to the cluster.
Oracle Dependency using Oracle Notifications notifies TayzGrid almost instantaneously after the database has been updated. These notifications use Oracle's client/server communication protocol to communicate with the TayzGrid cluster.
Below is a sample of using Oracle Dependency in your code.
CacheDependency oracleDependency = new OracleCacheDependency(connectionString, "SELECT PRODUCTID, rowId, PRODUCTNAME FROM PRODUCTS WHERE PRODUCTID = 1"); CacheItem cacheItem = new CacheItem("OracleDependentValue"); cacheItem.setDependency(oracleDependency); _cache.add("Item:1", cacheItem);
Database dependency is used by TayzGrid in case your database is an OLEDB compliant database other than Oracle. DbDependency can also be used with Oracle if you do not want event notifications which may get overwhelming in case there are rapid changes to your data.
In DbDependency, a special table called TayzGrid_db_sync is created in the database which contains one row for each item in the data grid with a Database dependency. Database triggers are modified so that they update rows in this table when the corresponding data is changed in the database. TayzGrid polls this TayzGrid_db_sync table looking for rows that have been updated. TayzGrid can fetch thousands of rows in one poll and then synchronize them with the database. Synchronization means removing the corresponding item from the data grid.
A sample for using DbDependency in your code is shown below:
CacheDependency dependency = DBDependencyFactory.CreateOleDbCacheDependency( connectionString, Integer.toString(i) + ":oldRow.Products"); _cache.insert(i + ":oldRow.Products", i, dependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default);
The Database synchronization default behavior is to remove the data grid item when corresponding data changes in the database. However, there are situations where you just want to update the cluster with the updated data.
To handle this need, TayzGrid allows a combination of database synchronization (Oracle Dependency or Database Dependency) with a Read-through hander. In effect, TayzGrid simply calls the Read-through handler to reload the latest version of the in-memory data grid item and then updates the in-memory data grid for Java accordingly.