简体   繁体   中英

Spring @Repository and @Service

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?

PS by doing this the service and repository interfaces will have different number of methods, is this a good practice?

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 ?

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(){
  ..
  }
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM