This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing/getting session in class without any effects in old code

 
Mohanasundar Nagarajan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

Herewith I will explain the scenario first,

We are using JSP/Servelt based web application running on Tomcat and I'm in the process of migration, struggled here.

In a servelet, 1 object being initialized that contains an pre initialized variable x = "abc".
The same class is been instantiated in more than 200 servlets.


Now the problem is the value of x has to be updated from the session.
I don't want to address all the files instead is it possible to get session in that class with out altering its methods and constructors.

Is it any easiest way to address this issue?

Kindly help me, I'm really struggling.

Regards,
Mohanasundar.n



 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pass it to any POJO class, have read the below two conversations gone here already.
webpage1
webpage2
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the problem is the value of x has to be updated from the session.


Are you really saying that a variable used in 200 servlets changes according to a user variable contained in a session?

Given that any number of users could be using these servlets, how do you plan to keep them from mixing up the uses of that variable?

Please clarify

Bill
 
Mohanasundar Nagarajan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes really instantiating,

Let me Explaining clearly, if any mistake forgive me.

We have an Application of 10 years old, which supports both Oracle and PostgreSQL databases.

Wherever requires db specific query/logic, we will use.



Till now we are having 2 Context for Oracle and PostgreSQL separate

For Oracle context, We have class like



For PostgreSQL context, We have same class like




classes will be used in servlets like,

[b][/b]

DBType is used in more than 200 servlet + jsp's.

Now I'm trying to join both the context,
Consider I'm keeping DBType.type in session



If I get session in DBType, I may change like this,


Hope you got my requirement.

Thanks in advance,
Mohanasundar N
 
Paul Clapham
Sheriff
Pie
Posts: 20768
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to assume that putting the database type in the user's session was the right decision. Although that certainly isn't obvious from what you have posted so far. For all I know it might be better to put the database type in the application scope instead of session scope.

So then that DBType class would need to have access to the user's session. If it doesn't have that now, you would have to change the DBType class so that the servlet can pass it the session. And that would mean you would have to change every servlet which uses it.

But I would really prefer to answer your first question. The one where you were told why you had to change the system in the first place. Without knowing your actual requirements, we're just left discussing incompletely-described proposed solutions to a problem which we know nothing about. So anything you get as an answer won't be very useful.
 
Mohanasundar Nagarajan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot go for application scope as user can choose db either oracle or PostgreSQL
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If all those classes need is a single string, they certainly don't need the whole session. Whats wrong with a constructor

DBType( String theType) // where the String can come from anywhere, session, cookie, hidden variable, etc.

Bill
 
Mohanasundar Nagarajan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I overload constructor, I need to address all the pages where default constructor is been used.

Is there any possibility to do this without overloading by the way of listeners or any other mecanisam to do this.

If not possible I have to address all the pages if my team lead is ready or they have to continue with two context.

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you really saying that a variable used in 200 servlets changes according each user's preferences?

Given that any number of users could be using these servlets, how do you plan to keep them from mixing up the uses of that variable?

I don't see any quick and dirty way around it. The whole set of servlets contain a bad design decision - no easy way out.

Bill
 
Mohanasundar Nagarajan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bill. We are providing supports e-tendering and for few client are using oracle others postgress.
But source code are similar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic