I have a situation here.
Want to bypass database connection if caching disabled. If caching found enable, only then try to establish a database connection.
One part of application should work when database is down as it doesn't require connection to database at all.
While other parts should throw exception when database connection not available.
the piece of code looks like this:
Now this code is working as per my requirement. for the time being.
But have two major problems to be solved here.
1) this piece of code :
is getting called in other class as well. i.e. inside this:
have initialise method. which internally calls this method:
Because StageAccessService is the real entry point for all other classes to access information about stage (staging). (So making StageConfig singleton, won't help me)
Now is there any way i can avoid :
this.stageConfig = new StageConfig(stage, channel, date);
getting called twice in my code.
why this is required is this method checks for caching real values.
2) Other workaround can be like: check if database connection is there or not. log the exception in catch block. but don't throw back.
So that the part which doesn't require database connection can work. But if request is not calling that part, then better throw exception also.
I don't know which approach is good in this case.
Can anyone suggest anything better then this.