我正在使用Spring 4.0.3构建一个应用程序
我正在处理一些巨大的数据,在我的@Repository中,我有一个方法可以从数据库中获得大约300,000条记录。
我将根据其类型多次使用此数据(例如,我将显示发生了多少个导出操作,而在同一页面的另一个位置,我将显示发生了多少个导入操作)。
我需要最小化数据库交互,我应该在服务层中有两个或更多的方法,一个用于导入,一个用于导出,等等。还是有别的办法?
附注:通过这样做,服务和存储库接口将有不同数量的方法,这是一个好的实践吗?
发布于 2015-04-15 23:34:47
如果您希望将数据库往返次数保持在最少,那么让DB为您处理数据并检索所有统计信息(导入、导出的数量等)可能是个好主意。在一个查询中。
类似于:
SELECT imports, exports
FROM (select count(*) from OPS where TYPE="import") as imports,
(select count(*) from OPS where TYPE="export") as exports如果算法比较复杂,可能需要一些PL/SQL或类似的语言,但是数据库的目标是处理数据,所以为什么不充分利用它呢?
发布于 2015-04-15 23:44:23
您可以对其进行缓存,以避免db调用。
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(){
..
}
}https://stackoverflow.com/questions/29654423
复制相似问题