Andrews Andrews - 2 months ago 12
Java Question

Design Pattern - Where should I manipulate the String retrieved from a database. Closer to it or farther from it

We have a java based web application.
The animal name is stored in the database as AnimalName_GenusName for our internal purposes.



We use to send the information as
such to the Calling web page.

public class Animal {
private String name;
private Long id;
private String genusName;
private String species;

public String getName() {
return name;
public void setName(String name) { = name;
public String getGenusName() {
return genusName;
public void setGenusName(String genusName) {
this.genusName = genusName;



Now we want to show the information to the calling web page with the Genus name stripped off.

The requirement is to have a set of modules to show information as such and a set of modules to remove this genus name appended to it while saving.

We are planning to have a Filter that will intercept while sending the information to the calling page and strip off the information. We can define the modules that are involved in the filter by defining matching urls or Servlets.

Is this the right approach, how costlier is it to do this for 100000 data with 10 other columns?

Any other better approach? I was wondering about using a different method in the animal class to give the stripped off information. But that would mean all the modules have to be re-factored and not a nice choice.


The better approach is to store "AnimalName" and "GenusName" in different columns, since they're fundamentally different data. It will probably be a lot of initial investment, but if your application is going to be around for a long time it is well worth it.

Since you're not going to do that, I would try to do the stripping as close to the database as you can. The farther away from the database you get, the more likely you are to need to duplicate the effort (e.g. if you write a new client).

Nobody but you can determine the performance implications. We don't have enough information about your code or your hardware.