📄 transactions.po
字号:
msgid ""msgstr """Project-Id-Version: PACKAGE VERSION\n""Report-Msgid-Bugs-To: http://bugs.kde.org\n""POT-Creation-Date: 2008-08-14 15:28+0000\n""PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n""Last-Translator: FULL NAME <EMAIL@ADDRESS>\n""Language-Team: LANGUAGE <LL@li.org>\n""MIME-Version: 1.0\n""Content-Type: text/plain; charset=UTF-8\n""Content-Transfer-Encoding: 8bit\n"#. Tag: title#: transactions.xml:29#, no-c-formatmsgid "Transactions And Concurrency"msgstr "事务和并发"#. Tag: para#: transactions.xml:31#, no-c-formatmsgid """The most important point about Hibernate and concurrency control is that it ""is very easy to understand. Hibernate directly uses JDBC connections and JTA ""resources without adding any additional locking behavior. We highly ""recommend you spend some time with the JDBC, ANSI, and transaction isolation ""specification of your database management system."msgstr """Hibernate的事务和并发控制很容易掌握。Hibernate直接使用JDBC连接和JTA资源,不添""加任何附加锁定 行为。我们强烈推荐你花点时间了解JDBC编程,ANSI SQL查询语言和你""使用 的数据库系统的事务隔离规范。"#. Tag: para#: transactions.xml:38#, no-c-formatmsgid """Hibernate does not lock objects in memory. Your application can expect the ""behavior as defined by the isolation level of your database transactions. ""Note that thanks to the <literal>Session</literal>, which is also a ""transaction-scoped cache, Hibernate provides repeatable reads for lookup by ""identifier and entity queries (not reporting queries that return scalar ""values)."msgstr """Hibernate不锁定内存中的对象。你的应用程序会按照你的数据库事务的隔离级别规定的""那样运作。幸亏有了<literal>Session</literal>,使得Hibernate通过标识符查找,和""实体查询(不是返回标量值的报表查询)提供了可重复的读取(Repeatable reads)功""能,<literal>Session</literal>同时也是事务范围内的缓存(cache)。"#. Tag: para#: transactions.xml:46#, no-c-formatmsgid """In addition to versioning for automatic optimistic concurrency control, ""Hibernate also offers a (minor) API for pessimistic locking of rows, using ""the <literal>SELECT FOR UPDATE</literal> syntax. Optimistic concurrency ""control and this API are discussed later in this chapter."msgstr """除了对自动乐观并发控制提供版本管理,针对行级悲观锁定,Hibernate也提供了辅助的""(较小的)API,它使用了 <literal>SELECT FOR UPDATE</literal>的SQL语法。本章后""面会讨论乐观并发控制和这个API。"#. Tag: para#: transactions.xml:53#, no-c-formatmsgid """We start the discussion of concurrency control in Hibernate with the ""granularity of <literal>Configuration</literal>, <literal>SessionFactory</""literal>, and <literal>Session</literal>, as well as database transactions ""and long conversations."msgstr """我们从<literal>Configuration</literal>层、<literal>SessionFactory</literal>""层, 和 <literal>Session</literal>层开始讨论Hibernate的并行控制、数据库事务和""应用 程序的长事务。"#. Tag: title#: transactions.xml:60#, no-c-formatmsgid "Session and transaction scopes"msgstr "Session和事务范围(transaction scope)"#. Tag: para#: transactions.xml:62#, no-c-formatmsgid """A <literal>SessionFactory</literal> is an expensive-to-create, threadsafe ""object intended to be shared by all application threads. It is created once, ""usually on application startup, from a <literal>Configuration</literal> ""instance."msgstr """<literal>SessionFactory</literal>对象的创建代价很昂贵,它是线程安全的对象,它""为所有的应用程序线程所共享。它只创建一次,通常是在应用程序启动的时候,由一个""<literal>Configuraion</literal>的实例来创建。"#. Tag: para#: transactions.xml:68#, no-c-formatmsgid """A <literal>Session</literal> is an inexpensive, non-threadsafe object that ""should be used once, for a single request, a conversation, single unit of ""work, and then discarded. A <literal>Session</literal> will not obtain a ""JDBC <literal>Connection</literal> (or a <literal>Datasource</literal>) ""unless it is needed, hence consume no resources until used."msgstr """<literal>Session</literal>对象的创建代价比较小,是非线程安全的,对于单个请""求,单个会话、单个的 工作单元而言,它只被使用一次,然后就丢弃。只有在需要的时""候,一个<literal>Session</literal>对象 才会获取一个JDBC的""<literal>Connection</literal>(或一个<literal>Datasource</literal>) 对象,因""此假若不使用的时候它不消费任何资源。"#. Tag: para#: transactions.xml:76#, no-c-formatmsgid """To complete this picture you also have to think about database transactions. ""A database transaction has to be as short as possible, to reduce lock ""contention in the database. Long database transactions will prevent your ""application from scaling to highly concurrent load. Hence, it is almost ""never good design to hold a database transaction open during user think ""time, until the unit of work is complete."msgstr """此外我们还要考虑数据库事务。数据库事务应该尽可能的短,降低数据库中的锁争用。 ""数据库长事务会阻止你的应用程序扩展到高的并发负载。因此,假若在用户思考期间让""数据库事务开着,直到整个工作单元完成才关闭这个事务,这绝不是一个好的设计。"#. Tag: para#: transactions.xml:85#, no-c-formatmsgid """What is the scope of a unit of work? Can a single Hibernate ""<literal>Session</literal> span several database transactions or is this a ""one-to-one relationship of scopes? When should you open and close a ""<literal>Session</literal> and how do you demarcate the database transaction ""boundaries?"msgstr """一个操作单元(Unit of work)的范围是多大?单个的Hibernate <literal>Session</""literal>能跨越多个 数据库事务吗?还是一个<literal>Session</literal>的作用范围""对应一个数据库事务的范围?应该何时打开 <literal>Session</literal>,何时关闭""<literal>Session</literal>?,你又如何划分数据库事务的边界呢?"#. Tag: title#: transactions.xml:93#, no-c-formatmsgid "Unit of work"msgstr "操作单元(Unit of work)"#. Tag: para#: transactions.xml:95#, no-c-formatmsgid """First, don't use the <emphasis>session-per-operation</emphasis> antipattern, ""that is, don't open and close a <literal>Session</literal> for every simple ""database call in a single thread! Of course, the same is true for database ""transactions. Database calls in an application are made using a planned ""sequence, they are grouped into atomic units of work. (Note that this also ""means that auto-commit after every single SQL statement is useless in an ""application, this mode is intended for ad-hoc SQL console work. Hibernate ""disables, or expects the application server to do so, auto-commit mode ""immediately.) Database transactions are never optional, all communication ""with a database has to occur inside a transaction, no matter if you read or ""write data. As explained, auto-commit behavior for reading data should be ""avoided, as many small transactions are unlikely to perform better than one ""clearly defined unit of work. The latter is also much more maintainable and ""extensible."msgstr """首先,别用<emphasis>session-per-operation</emphasis>这种反模式了,也就是说,""在单个线程中, 不要因为一次简单的数据库调用,就打开和关闭一次""<literal>Session</literal>!数据库事务也是如此。 应用程序中的数据库调用是按照""计划好的次序,分组为原子的操作单元。(注意,这也意味着,应用程 序中,在单个的""SQL语句发送之后,自动事务提交(auto-commit)模式失效了。这种模式专门为SQL控制台""操作设计的。 Hibernate禁止立即自动事务提交模式,或者期望应用服务器禁止立即自""动事务提交模式。)数据库事务绝不是可有可无的,任何与数据库之间的通讯都必须在""某个事务中进行,不管你是在读还是在写数据。对读数据而言,应该避免auto-commit行""为,因为很多小的事务比一个清晰定义的工作单元性能差。后者也更容易维护和扩展。"#. Tag: para#: transactions.xml:111#, fuzzy, no-c-formatmsgid """The most common pattern in a multi-user client/server application is ""<emphasis>session-per-request</emphasis>. In this model, a request from the ""client is sent to the server (where the Hibernate persistence layer runs), a ""new Hibernate <literal>Session</literal> is opened, and all database ""operations are executed in this unit of work. Once the work has been ""completed (and the response for the client has been prepared), the session ""is flushed and closed. You would also use a single database transaction to ""serve the clients request, starting and committing it when you open and ""close the <literal>Session</literal>. The relationship between the two is ""one-to-one and this model is a perfect fit for many applications."msgstr """在多用户的client/server应用程序中,最常用的模式是 <emphasis>每个请求一个会话""(session-per-request)</emphasis>。 在这种模式下,来自客户端的请求被发送到服务""器端(即Hibernate持久化层运行的地方),一 个新的Hibernate <literal>Session</""literal>被打开,并且执行这个操作单元中所有的数据库操作。 一旦操作完成(同时对""客户端的响应也准备就绪),session被同步,然后关闭。你也可以使用单 个数据库事""务来处理客户端请求,在你打开<literal>Session</literal>之后启动事务,在你关闭 ""<literal>Session</literal>之前提交事务。会话和请求之间的关系是一对一的关系,""这种模式对 于大多数应用程序来说是很棒的。"#. Tag: para#: transactions.xml:123#, fuzzy, no-c-formatmsgid """The challenge lies in the implementation. Hibernate provides built-in ""management of the \"current session\" to simplify this pattern. All you have ""to do is start a transaction when a server request has to be processed, and ""end the transaction before the response is sent to the client. You can do ""this in any way you like, common solutions are <literal>ServletFilter</""literal>, AOP interceptor with a pointcut on the service methods, or a proxy/""interception container. An EJB container is a standardized way to implement ""cross-cutting aspects such as transaction demarcation on EJB session beans, ""declaratively with CMT. If you decide to use programmatic transaction ""demarcation, prefer the Hibernate <literal>Transaction</literal> API shown ""later in this chapter, for ease of use and code portability."msgstr """实现才是真正的挑战。Hibernate内置了对\"当前session(current session)\" 的管""理,用于简化此模式。你要做的一切就是在服务器端要处理请求的时候,开启事务,在""响应发送给客户之前结束事务。你可以用任何方式来完成这一操作,通常的方案有""<literal>ServletFilter</literal>,在service方法中进行pointcut的AOP拦截器,或""者proxy/interception容器。EJB容器是实现横切诸如EJB session bean上的事务分界,""用CMT对事务进行声明等方面的标准手段。假若你决定使用编程式的事务分界,请参考本""章后面讲到的Hibernate <literal>Transaction</literal> API,这对易用性和代码可""移植性都有好处。"#. Tag: para#: transactions.xml:136#, no-c-formatmsgid """Your application code can access a \"current session\" to process the ""request by simply calling <literal>sessionFactory.getCurrentSession()</""literal> anywhere and as often as needed. You will always get a ""<literal>Session</literal> scoped to the current database transaction. This ""has to be configured for either resource-local or JTA environments, see ""<xref linkend=\"architecture-current-session\"/>."msgstr """在任何时间,任何地方,你的应用代码可以通过简单的调用<literal>sessionFactory.""getCurrentSession()</literal>来访问\"当前session\",用于处理请求。你总是会得""到当前数据库事务范围内的<literal>Session</literal>。在使用本地资源或JTA环境""时,必须配置它,请参见<xref linkend=\"architecture-current-session\"/>。"#. Tag: para#: transactions.xml:144#, no-c-formatmsgid """Sometimes it is convenient to extend the scope of a <literal>Session</""literal> and database transaction until the \"view has been rendered\". This ""is especially useful in servlet applications that utilize a separate ""rendering phase after the request has been processed. Extending the database ""transaction until view rendering is complete is easy to do if you implement ""your own interceptor. However, it is not easily doable if you rely on EJBs ""with container-managed transactions, as a transaction will be completed when ""an EJB method returns, before rendering of any view can start. See the ""Hibernate website and forum for tips and examples around this <emphasis>Open ""Session in View</emphasis> pattern."msgstr """有时,将<literal>Session</literal>和数据库事务的边界延伸到\"展示层被渲染后""\"会带来便利。有些serlvet应用程序在对请求进行处理后,有个单独的渲染期,这种延""伸对这种程序特别有用。假若你实现你自己的拦截器,把事务边界延伸到展示层渲染结""束后非常容易。然而,假若你依赖有容器管理事务的EJB,这就不太容易了,因为事务会""在EJB方法返回后结束,而那是在任何展示层渲染开始之前。请访问Hibernate网站和论""坛,你可以找到<emphasis>Open Session in View</emphasis>这一模式的提示和示例。"#. Tag: title#: transactions.xml:159#, no-c-formatmsgid "Long conversations"msgstr "长对话"#. Tag: para#: transactions.xml:161#, no-c-format
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -