DAO通常应具有哪个范围 [英] which scope should a DAO typically have

查看:68
本文介绍了DAO通常应具有哪个范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

毫无疑问,小岛将不会拥有任何状态。

its out of question that a dao will not hold any state.

但是,为了最轻松地访问该类,最好使用原型(= new时间)或单身人士?

however, for easiest access to the class, is it better to use prototype( = new every time) or singleton?

简单的对象创建对于dao来说是便宜的。它通常仅拥有一个sessionfactory,从单身人士列表访问该对象的
可能是同样昂贵。

simple object creation is cheap for dao's.. it typically only holds a sessionfactory, accessing the object from a list of singletons may be equally expensive.

澄清:这个问题的重点是,是否对daos的范围有一个常规约定。

clarfication: the focus of this question is, if there is a common convention to the scoping of daos.

推荐答案

如果您的问题是关于体系结构的,那么我将把DAO的作用域确定为您正在执行的工作单元。这会减少潜在的交叉交易污染线程问题

If your question is about architecture, I'd go with scoping DAOs to the Unit of Work or Transaction you are doing. This reduces the potential for cross-transaction pollution and threading-issues.

如果您的问题是关于性能的,那么答案就在分析器之内,该分析器会为您的工作量准确个数字 strong>。

If your question is about performance, then the answer lies within a profiler, which gives you accurate numbers for your particular workload.

这篇关于DAO通常应具有哪个范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆