java - Similar SQL queries in different methods -
there 2 similar methods:
collection<movie> findall(userdetails userdetails); //find movies rated user collection<movie> findall(userdetails userdetails, string s); //find movies rated user , containing "s" in title
so, second first + regex. jpql code respectively:
select movie........ //doesn't mater //the same logic
and
select movie........ lower(movie.title) :s //the same logic
all difference 1 line of code, forces me code repeating in these 2 methods. how can avoid code repeating in case?
i thought implement private method receive queries these 2 , process "the same logic". approach?
keep both methods , create method receives result , process data.
collection<movie> findall(...) { // params here result result = select movie........ //doesn't mater return processdata(result); }
Comments
Post a Comment