Reputation: 6159
I am building an application using Spring 4.0.3
I am dealing with some huge data, in my @Repository I have a method that gets about 300,000 records from the db.
I will use this data multiple times according to its type (for example, I will display how many export operations had happened and in another place in the same page, I will display how many import operations happened).
I need to minimize the db interactions, should I have 2 or more methods in the service layer one for import, one for export, etc... or is there another way?
P.S. by doing this the service and repository interfaces will have different number of methods, is this a good practice?
Upvotes: 1
Views: 124
Reputation: 379
you can cache it, so as to avoid db calls.
class business{
@cache the response
method1(import){
dbstore.getdata();
process the data to get import result;
}
@cache the response
method2(export){
dbstore.getdata();
process the data to get export result;
}
}
class dbstore{
getdata(){
..
}
}
Upvotes: 0
Reputation: 6149
If you want to keep DB roundtrips to a minimum, it may be a good idea to ask the DB to crunch the data for you and retrieve all statistics (number of imports, exports, etc.) in one query.
Something like :
SELECT imports, exports
FROM (select count(*) from OPS where TYPE="import") as imports,
(select count(*) from OPS where TYPE="export") as exports
A bit of PL/SQL or equivalent may be needed if the algorithm is more complicated, but databases's goal in life is to crunch data, so why not use it to its full potential ?
Upvotes: 1