📄 events.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#: events.xml:29#, no-c-formatmsgid "Interceptors and events"msgstr "拦截器与事件(Interceptors and events)"#. Tag: para#: events.xml:31#, no-c-formatmsgid """It is often useful for the application to react to certain events that occur ""inside Hibernate. This allows implementation of certain kinds of generic ""functionality, and extension of Hibernate functionality."msgstr """应用程序能够响应Hibernate内部产生的特定事件是非常有用的。这样就允许实现某些通""用的功能 以及允许对Hibernate功能进行扩展。"#. Tag: title#: events.xml:38#, no-c-formatmsgid "Interceptors"msgstr "拦截器(Interceptors)"#. Tag: para#: events.xml:40#, no-c-formatmsgid """The <literal>Interceptor</literal> interface provides callbacks from the ""session to the application allowing the application to inspect and/or ""manipulate properties of a persistent object before it is saved, updated, ""deleted or loaded. One possible use for this is to track auditing ""information. For example, the following <literal>Interceptor</literal> ""automatically sets the <literal>createTimestamp</literal> when an ""<literal>Auditable</literal> is created and updates the ""<literal>lastUpdateTimestamp</literal> property when an <literal>Auditable</""literal> is updated."msgstr """<literal>Interceptor</literal>接口提供了从会话(session)回调(callback)应用程序""(application)的机制, 这种回调机制可以允许应用程序在持久化对象被保存、更新、""删除或是加载之前,检查并(或)修改其 属性。一个可能的用途,就是用来跟踪审核""(auditing)信息。例如:下面的这个<literal>拦截器</literal>,会在一个实现了 ""<literal>Auditable</literal>接口的对象被创建时自动地设置""<literal>createTimestamp</literal>属性,并在实现了 <literal>Auditable</""literal>接口的对象被更新时,同步更新<literal>lastUpdateTimestamp</literal>属""性。"#. Tag: para#: events.xml:51#, no-c-formatmsgid """You may either implement <literal>Interceptor</literal> directly or (better) ""extend <literal>EmptyInterceptor</literal>."msgstr """你可以直接实现<literal>Interceptor</literal>接口,也可以(最好)继承自""<literal>EmptyInterceptor</literal>。"#. Tag: programlisting#: events.xml:56#, no-c-formatmsgid """<![CDATA[package org.hibernate.test;\n""\n""import java.io.Serializable;\n""import java.util.Date;\n""import java.util.Iterator;\n""\n""import org.hibernate.EmptyInterceptor;\n""import org.hibernate.Transaction;\n""import org.hibernate.type.Type;\n""\n""public class AuditInterceptor extends EmptyInterceptor {\n""\n"" private int updates;\n"" private int creates;\n"" private int loads;\n""\n"" public void onDelete(Object entity,\n"" Serializable id,\n"" Object[] state,\n"" String[] propertyNames,\n"" Type[] types) {\n"" // do nothing\n"" }\n""\n"" public boolean onFlushDirty(Object entity,\n"" Serializable id,\n"" Object[] currentState,\n"" Object[] previousState,\n"" String[] propertyNames,\n"" Type[] types) {\n""\n"" if ( entity instanceof Auditable ) {\n"" updates++;\n"" for ( int i=0; i < propertyNames.length; i++ ) {\n"" if ( \"lastUpdateTimestamp\".equals( propertyNames[i] ) ) {\n"" currentState[i] = new Date();\n"" return true;\n"" }\n"" }\n"" }\n"" return false;\n"" }\n""\n"" public boolean onLoad(Object entity,\n"" Serializable id,\n"" Object[] state,\n"" String[] propertyNames,\n"" Type[] types) {\n"" if ( entity instanceof Auditable ) {\n"" loads++;\n"" }\n"" return false;\n"" }\n""\n"" public boolean onSave(Object entity,\n"" Serializable id,\n"" Object[] state,\n"" String[] propertyNames,\n"" Type[] types) {\n""\n"" if ( entity instanceof Auditable ) {\n"" creates++;\n"" for ( int i=0; i<propertyNames.length; i++ ) {\n"" if ( \"createTimestamp\".equals( propertyNames[i] ) ) {\n"" state[i] = new Date();\n"" return true;\n"" }\n"" }\n"" }\n"" return false;\n"" }\n""\n"" public void afterTransactionCompletion(Transaction tx) {\n"" if ( tx.wasCommitted() ) {\n"" System.out.println(\"Creations: \" + creates + \", Updates: \" + ""updates, \"Loads: \" + loads);\n"" }\n"" updates=0;\n"" creates=0;\n"" loads=0;\n"" }\n""\n""}]]>"msgstr ""#. Tag: para#: events.xml:58#, no-c-formatmsgid """Interceptors come in two flavors: <literal>Session</literal>-scoped and ""<literal>SessionFactory</literal>-scoped."msgstr """拦截器可以有两种:<literal>Session</literal>范围内的,和""<literal>SessionFactory</literal>范围内的。"#. Tag: para#: events.xml:63#, no-c-formatmsgid """A <literal>Session</literal>-scoped interceptor is specified when a session ""is opened using one of the overloaded SessionFactory.openSession() methods ""accepting an <literal>Interceptor</literal>."msgstr """当使用某个重载的SessionFactory.openSession()使用<literal>Interceptor</""literal>作为参数调用打开一个session的时候,就指定了<literal>Session</literal>""范围内的拦截器。"#. Tag: programlisting#: events.xml:69#, no-c-formatmsgid "<![CDATA[Session session = sf.openSession( new AuditInterceptor() );]]>"msgstr ""#. Tag: para#: events.xml:71#, no-c-formatmsgid """A <literal>SessionFactory</literal>-scoped interceptor is registered with ""the <literal>Configuration</literal> object prior to building the ""<literal>SessionFactory</literal>. In this case, the supplied interceptor ""will be applied to all sessions opened from that <literal>SessionFactory</""literal>; this is true unless a session is opened explicitly specifying the ""interceptor to use. <literal>SessionFactory</literal>-scoped interceptors ""must be thread safe, taking care to not store session-specific state since ""multiple sessions will use this interceptor (potentially) concurrently."msgstr """<literal>SessionFactory</literal>范围内的拦截器要通过<literal>Configuration</""literal>中注册,而这必须在创建<literal>SessionFactory</literal>之前。在这种情""况下,给出的拦截器会被这个<literal>SessionFactory</literal>所打开的所有""session使用了;除非session打开时明确指明了使用的拦截器。""<literal>SessionFactory</literal>范围内的拦截器,必须是线程安全的,因为多个""session可能并发使用这个拦截器,要因此小心不要保存与session相关的状态。"#. Tag: programlisting#: events.xml:80#, no-c-formatmsgid """<![CDATA[new Configuration().setInterceptor( new AuditInterceptor() );]]>"msgstr ""#. Tag: title#: events.xml:85#, no-c-formatmsgid "Event system"msgstr "事件系统(Event system)"#. Tag: para#: events.xml:87#, no-c-formatmsgid """If you have to react to particular events in your persistence layer, you may ""also use the Hibernate3 <emphasis>event</emphasis> architecture. The event ""system can be used in addition or as a replacement for interceptors."msgstr """如果需要响应持久层的某些特殊事件,你也可以使用Hibernate3的事件框架。 该事件系""统可以用来替代拦截器,也可以作为拦截器的补充来使用。"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -