⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 performance.po

📁 hibernate-distribution-3.3.1.GA-dist.zip源码
💻 PO
📖 第 1 页 / 共 5 页
字号:
#. Tag: para#: performance.xml:370#, no-c-formatmsgid "The identifier getter method"msgstr "标志符的getter方法。"#. Tag: para#: performance.xml:376#, no-c-formatmsgid """Hibernate will detect persistent classes that override <literal>equals()</""literal> or <literal>hashCode()</literal>."msgstr """Hibernate将会识别出那些重载了<literal>equals()</literal>、或<literal>hashCode""()</literal>方法的持久化类。"#. Tag: para#: performance.xml:381#, no-c-formatmsgid """By choosing <literal>lazy=\"no-proxy\"</literal> instead of the default ""<literal>lazy=\"proxy\"</literal>, we can avoid the problems associated with ""typecasting. However, we will require buildtime bytecode instrumentation, ""and all operations will result in immediate proxy initialization."msgstr """若选择<literal>lazy=\"no-proxy\"</literal>而非默认的<literal>lazy=\"proxy\"</""literal>,我们可以避免类型转换带来的问题。然而,这样我们就需要编译期字节码增""强,并且所有的操作都会导致立刻进行代理初始化。"#. Tag: title#: performance.xml:391#, no-c-formatmsgid "Initializing collections and proxies"msgstr "实例化集合和代理(Initializing collections and proxies)"#. Tag: para#: performance.xml:393#, no-c-formatmsgid """A <literal>LazyInitializationException</literal> will be thrown by Hibernate ""if an uninitialized collection or proxy is accessed outside of the scope of ""the <literal>Session</literal>, ie. when the entity owning the collection or ""having the reference to the proxy is in the detached state."msgstr """在<literal>Session</literal>范围之外访问未初始化的集合或代理,Hibernate将会抛""出<literal>LazyInitializationException</literal>异常。 也就是说,在分离状态""下,访问一个实体所拥有的集合,或者访问其指向代理的属性时,会引发此异常。"#. Tag: para#: performance.xml:399#, no-c-formatmsgid """Sometimes we need to ensure that a proxy or collection is initialized before ""closing the <literal>Session</literal>. Of course, we can alway force ""initialization by calling <literal>cat.getSex()</literal> or <literal>cat.""getKittens().size()</literal>, for example. But that is confusing to readers ""of the code and is not convenient for generic code."msgstr """有时候我们需要保证某个代理或者集合在Session关闭前就已经被初始化了。 当然,我""们可以通过强行调用<literal>cat.getSex()</literal>或者<literal>cat.getKittens""().size()</literal>之类的方法来确保这一点。 但是这样的程序会造成读者的疑惑,""也不符合通常的代码规范。"#. Tag: para#: performance.xml:406#, no-c-formatmsgid """The static methods <literal>Hibernate.initialize()</literal> and ""<literal>Hibernate.isInitialized()</literal> provide the application with a ""convenient way of working with lazily initialized collections or proxies. ""<literal>Hibernate.initialize(cat)</literal> will force the initialization ""of a proxy, <literal>cat</literal>, as long as its <literal>Session</""literal> is still open. <literal>Hibernate.initialize( cat.getKittens() )</""literal> has a similar effect for the collection of kittens."msgstr """静态方法<literal>Hibernate.initialized()</literal> 为你的应用程序提供了一个便""捷的途径来延迟加载集合或代理。 只要它的Session处于open状态,""<literal>Hibernate.initialize(cat)</literal> 将会为cat强制对代理实例化。 同""样,<literal>Hibernate.initialize( cat.getKittens() )</literal> 对kittens的集""合具有同样的功能。"#. Tag: para#: performance.xml:415#, no-c-formatmsgid """Another option is to keep the <literal>Session</literal> open until all ""needed collections and proxies have been loaded. In some application ""architectures, particularly where the code that accesses data using ""Hibernate, and the code that uses it are in different application layers or ""different physical processes, it can be a problem to ensure that the ""<literal>Session</literal> is open when a collection is initialized. There ""are two basic ways to deal with this issue:"msgstr """还有另外一种选择,就是保持<literal>Session</literal>一直处于open状态,直到所""有需要的集合或代理都被载入。 在某些应用架构中,特别是对于那些使用Hibernate进""行数据访问的代码,以及那些在不同应用层和不同物理进程中使用Hibernate的代码。 ""在集合实例化时,如何保证<literal>Session</literal>处于open状态经常会是一个问""题。有两种方法可以解决此问题:"#. Tag: para#: performance.xml:426#, no-c-formatmsgid """In a web-based application, a servlet filter can be used to close the ""<literal>Session</literal> only at the very end of a user request, once the ""rendering of the view is complete (the <emphasis>Open Session in View</""emphasis> pattern). Of course, this places heavy demands on the correctness ""of the exception handling of your application infrastructure. It is vitally ""important that the <literal>Session</literal> is closed and the transaction ""ended before returning to the user, even when an exception occurs during ""rendering of the view. See the Hibernate Wiki for examples of this \"Open ""Session in View\" pattern."msgstr """在一个基于Web的应用中,可以利用servlet过滤器(filter),在用户请求(request)""结束、页面生成 结束时关闭<literal>Session</literal>(这里使用了<emphasis>在展""示层保持打开Session模式(Open Session in View)</emphasis>), 当然,这将依赖""于应用框架中异常需要被正确的处理。在返回界面给用户之前,乃至在生成界面过程中""发生异常的情况下, 正确关闭<literal>Session</literal>和结束事务将是非常重要""的, 请参见Hibernate wiki上的\"Open Session in View\"模式,你可以找到示例。"#. Tag: para#: performance.xml:439#, no-c-formatmsgid """In an application with a separate business tier, the business logic must ""\"prepare\" all collections that will be needed by the web tier before ""returning. This means that the business tier should load all the data and ""return all the data already initialized to the presentation/web tier that is ""required for a particular use case. Usually, the application calls ""<literal>Hibernate.initialize()</literal> for each collection that will be ""needed in the web tier (this call must occur before the session is closed) ""or retrieves the collection eagerly using a Hibernate query with a ""<literal>FETCH</literal> clause or a <literal>FetchMode.JOIN</literal> in ""<literal>Criteria</literal>. This is usually easier if you adopt the ""<emphasis>Command</emphasis> pattern instead of a <emphasis>Session Facade</""emphasis>."msgstr """在一个拥有单独业务层的应用中,业务层必须在返回之前,为web层“准备”好其所需的数""据集合。这就意味着 业务层应该载入所有表现层/web层所需的数据,并将这些已实例化""完毕的数据返回。通常,应用程序应该 为web层所需的每个集合调用""<literal>Hibernate.initialize()</literal>(这个调用必须发生咱session关闭之""前); 或者使用带有<literal>FETCH</literal>从句,或<literal>FetchMode.JOIN</""literal>的Hibernate查询, 事先取得所有的数据集合。如果你在应用中使用了""<emphasis>Command</emphasis>模式,代替<emphasis>Session Facade</emphasis> , ""那么这项任务将会变得简单的多。"#. Tag: para#: performance.xml:454#, no-c-formatmsgid """You may also attach a previously loaded object to a new <literal>Session</""literal> with <literal>merge()</literal> or <literal>lock()</literal> before ""accessing uninitialized collections (or other proxies). No, Hibernate does ""not, and certainly <emphasis>should</emphasis> not do this automatically, ""since it would introduce ad hoc transaction semantics!"msgstr """你也可以通过<literal>merge()</literal>或<literal>lock()</literal>方法,在访问""未实例化的集合(或代理)之前, 为先前载入的对象绑定一个新的<literal>Session</""literal>。 显然,Hibernate将不会,也不<emphasis>应该</emphasis>自动完成这些任""务,因为这将引入一个特殊的事务语义。"#. Tag: para#: performance.xml:464#, no-c-formatmsgid """Sometimes you don't want to initialize a large collection, but still need ""some information about it (like its size) or a subset of the data."msgstr """有时候,你并不需要完全实例化整个大的集合,仅需要了解它的部分信息(例如其大""小)、或者集合的部分内容。"#. Tag: para#: performance.xml:469#, no-c-formatmsgid """You can use a collection filter to get the size of a collection without ""initializing it:"msgstr "你可以使用集合过滤器得到其集合的大小,而不必实例化整个集合:"#. Tag: programlisting#: performance.xml:473#, no-c-formatmsgid """<![CDATA[( (Integer) s.createFilter( collection, \"select count(*)\" ).list""().get(0) ).intValue()]]>"msgstr ""#. Tag: para#: performance.xml:475#, no-c-formatmsgid """The <literal>createFilter()</literal> method is also used to efficiently ""retrieve subsets of a collection without needing to initialize the whole ""collection:"msgstr """这里的<literal>createFilter()</literal>方法也可以被用来有效的抓取集合的部分内""容,而无需实例化整个集合:"#. Tag: programlisting#: performance.xml:480#, no-c-formatmsgid """<![CDATA[s.createFilter( lazyCollection, \"\").setFirstResult(0).""setMaxResults(10).list();]]>"msgstr ""#. Tag: title#: performance.xml:485#, no-c-formatmsgid "Using batch fetching"msgstr "使用批量抓取(Using batch fetching)"#. Tag: para#: performance.xml:487#, no-c-formatmsgid """Hibernate can make efficient use of batch fetching, that is, Hibernate can ""load several uninitialized proxies if one proxy is accessed (or collections. ""Batch fetching is an optimization of the lazy select fetching strategy. ""There are two ways you can tune batch fetching: on the class and the ""collection level."msgstr """Hibernate可以充分有效的使用批量抓取,也就是说,如果仅一个访问代理(或集合),""那么Hibernate将不载入其他未实例化的代理。 批量抓取是延迟查询抓取的优化方案,""你可以在两种批量抓取方案之间进行选择:在类级别和集合级别。"#. Tag: para#: performance.xml:493#, no-c-formatmsgid """Batch fetching for classes/entities is easier to understand. Imagine you ""have the following situation at runtime: You have 25 <literal>Cat</literal> ""instances loaded in a <literal>Session</literal>, each <literal>Cat</""literal> has a reference to its <literal>owner</literal>, a <literal>Person</""literal>. The <literal>Person</literal> class is mapped with a proxy, ""<literal>lazy=\"true\"</literal>. If you now iterate through all cats and ""call <literal>getOwner()</literal> on each, Hibernate will by default ""execute 25 <literal>SELECT</literal> statements, to retrieve the proxied ""owners. You can tune this behavior by specifying a <literal>batch-size</""literal> in the mapping of <literal>Person</literal>:"msgstr """类/实体级别的批量抓取很容易理解。假设你在运行时将需要面对下面的问题:你在一个""<literal>Session</literal>中载入了25个 <literal>Cat</literal>实例,每个""<literal>Cat</literal>实例都拥有一个引用成员<literal>owner</literal>, 其指向""<literal>Person</literal>,而<literal>Person</literal>类是代理,同时""<literal>lazy=\"true\"</literal>。 如果你必须遍历整个cats集合,对每个元素调用""<literal>getOwner()</literal>方法,Hibernate将会默认的执行25次""<literal>SELECT</literal>查询, 得到其owner的代理对象。这时,你可以通过在映射""文件的<literal>Person</literal>属性,显式声明<literal>batch-size</literal>,""改变其行为:"#. Tag: programlisting#: performance.xml:503#, no-c-formatmsgid "<![CDATA[<class name=\"Person\" batch-size=\"10\">...</class>]]>"msgstr ""#. Tag: para#: performance.xml:505#, no-c-formatmsgid """Hibernate will now execute only three queries, the pattern is 10, 10, 5."msgstr "随之,Hibernate将只需要执行三次查询,分别为10、10、 5。"#. Tag: para#: performance.xml:509#, fuzzy, no-c-formatmsgid """You may also enable batch fetching of collections. For example, if each ""<literal>Person</literal> has a lazy collection of <literal>Cat</literal>s, ""and 10 persons are currently loaded in the <literal>Session</literal>, ""iterating through all persons will generate 10 <literal>SELECT</literal>s, ""one for every call to <literal>getCats()</literal>. If you enable batch ""fetching for the <literal>cats</literal> collection in the mapping of ""<literal>Person</literal>, Hibernate can pre-fetch collections:"msgstr """你也可以在集合级别定义批量抓取。例如,如果每个<literal>Person</literal>都拥有""一个延迟载入的<literal>Cats</literal>集合, 现在,<literal>Sesssion</literal>""中载入了10个person对象,遍历person集合将会引起10次<literal>SELECT</literal>查""询, 每次查询都会调用<literal>getCats()</literal>方法。如果你在""<literal>Person</literal>的映射定义部分,允许对<literal>cats</literal>批量抓""取, 那么,Hibernate将可以预先抓取整个集合。请看例子:"#. Tag: programlisting#: performance.xml:518#, no-c-formatmsgid """<![CDATA[<class name=\"Person\">\n""    <set name=\"cats\" batch-size=\"3\">\n""        ...\n""    </set>\n""</class>]]>"msgstr ""#. Tag: para#: performance.xml:520#, no-c-formatmsgid """With a <literal>batch-size</literal> of 3, Hibernate will load 3, 3, 3, 1 ""collections in four <literal>SELECT</literal>s. Again, the value of the ""attribute depends on the expected number of uninitialized collections in a ""particular <literal>Session</literal>."msgstr """如果整个的<literal>batch-size</literal>是3(笔误?),那么Hibernate将会分四次""执行<literal>SELECT</literal>查询, 按照3、3、3、1的大小分别载入数据。这里的""每次载入的数据量还具体依赖于当前<literal>Session</literal>中未实例化集合的个""数。"#. Tag: para#: performance.xml:526#, no-c-formatmsgid """Batch fetching of collections is particularly useful if you have a nested ""tree of items, ie. the typical bill-of-materials pattern. (Although a ""<emphasis>nested set</emphasis> or a <emphasis>materialized path</emphasis> ""might be a better option for read-mostly trees.)"msgstr """如果你的模型中有嵌套的树状结构,例如典型的帐单-原料结构(bill-of-materials ""pattern),集合的批量抓取是非常有用的。 (尽管在更多情况下对树进行读取时,""<emphasis>嵌套集合(nested set)</emphasis>或<emphasis>原料路径(materialized ""path)</emphasis>(××) 是更好的解决方法。)"#. Tag: title#: performance.xml:535#, no-c-formatmsgid "Using subselect fetching"msgstr "使用子查询抓取(Using subselect fetching)"#. Tag: para#: performance.xml:537#, no-c-formatmsgid """If one lazy collection or single-valued proxy has to be fetched, Hibernate ""loads all of them, re-running the original query in a subselect. This works ""in the same way as batch-fetching, without the piecemeal loading."

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -