简体   繁体   中英

Configuring a fall back datasource in RESTLet DAO Client Server Architecture In Java

I am using a Restlet DAO Client Server Architecture in Java, and a JDBC MySQL Data source with server deployed on Apache Tomcat 7.0 . My master database is online while the replicated slave database (read-only) is on local lan .

The server itself on startup should choose between the two available databases - if online(master) is reachable it connects with it, - else establishes a read only connection with the local DB

Assuming no internet, we connect to the local DB. Now How do I switch to the online DB once Internet is back. And switching has to be done on the reverse scenario as well ie first we have internet and then no internet.

I think that you should implement a custom DataSource (implementation of the JDBC interface DataSource ) that acts as a proxy in front of the two targets datasources (one for the local DB and one for the remote one).

In this scenario, we need to implement a way to check if the internet connection is there or not.

You can notice that you DAO classes should base on a data source to interact with the database. Dependency injection or factory pattern could be helpful here...

Hope it helps you, Thierry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM