Data clean-up; what layer?

85 views Asked by At

I have an app built on Model-Glue: Unity that contains some search forms. I need to trim leading and trailing spaces from search strings before using them to query the database. I'm also keeping the search terms in a bean that a user can save and re-use.

My problem is that I am unsure where to perform that trim(). The bean seems to be the wrong place for it, as I'm keeping the bean simple (no logic). Normally I would take care of that when updating the bean, but I'm using MakeEventBean to keep things simple. Re-touching all of the data in the Service layer seems an unnecessary layer of overhead. And, lastly, doing it in the datalayer with the actual SQL query doesn't seem right either. It'll work, but the information in my search bean will still be wrong.

What have you done in such cases?

2

There are 2 answers

0
ale On BEST ANSWER

I ended up making my Beans a little smarter than they were. Rather than monkey with every single setThing() method, I added a trimAll() method simple applied a trim() to each of the private properties in the Bean.

1
Sergey Galashyn On

Disclaimer: I'm not a MG user, so I'm not sure if this will be good and possible approach. Just want to share the idea.

In case of Transfer ORM beans I do such specific things in decorators which extend auto-generated beans.

For example, I can easily override setter setSearchPhrase(phrase), where trim the argument value and invoke original method.