Monday, December 23, 2013

Switching Databases : ATG


In many database-dependent applications, you may want to make changes in an offline database and then switch over your live application so that the inactive database becomes the live database. ATG’s switching facility is based on a class named atg.service.jdbc.SwitchingDataSource. You can use a SwitchingDataSource in place of a regular data source (such as atg.service.jdbc.MonitoredDataSource)

The SwitchingDataSource can be switched between two or more underlying DataSources. All DataSource method calls are passed through to the DataSource specified by the currentDataSource property of the SwitchingDataSource. Note that each DataSource that the SwitchingDataSource points to must be of class atg.nucleus.JNDIReference, with a JNDIName property that points to an application server data source.


Configuring a SwitchingDataSource


$class=atg.service.jdbc.SwitchingDataSource
#
# A map from data source names to data sources
#
dataSources=\
     DataSourceA=/atg/commerce/jdbc/ProductCatalogDataSourceA,\
     DataSourceB=/atg/commerce/jdbc/ProductCatalogDataSourceB

#
# The name of the data source that should be used on startup
#
initialDataSourceName=DataSourceA

repository=/atg/dynamo/service/jdbc/SDSRepository


initialDataSourceName:


The short name for the DataSource that should be used for the currentDataSource on the very first run. On subsequent runs, the initial currentDataSource is obtained from the state recorded in the SDSRepository.


dataSources:


Set to a ServiceMap of DataSources. This property maps short names of DataSources to their Nucleus component path. The following example shows how you might set the dataSources property:

dataSources=FirstDataSource=\
/atg/dynamo/service/jdbc/FirstDataSource,\
  SecondDataSource=\
/atg/dynamo/service/jdbc/SecondDataSource


repository:


Set with a reference to /atg/dynamo/service/jdbc/SDSRepository


Database Switching and Query Caching


If you are using a GSA repository and set the cacheSwitchLoadQueries property of the GSAItemDescriptor to true, the query cache is loaded for a cache switch. If false, the query cache starts out empty after a cache switch.


Database Switching and Repository Caches


If you set the cacheSwitchHot property of the repository component to true, when the repository receives a SwitchingDataSourceEvent of type PREPARE from the SwitchingDataSource, it prepopulates off-line caches with data from the next DataSource. Then, when the switch occurs and the repository receives a SwitchingDataSourceEvent of type SWITCH from the SwitchingDataSource, the caches are not flushed; instead, the off-line caches go live. This can improve performance during and immediately after a database switchover.


No comments:

Popular Posts