alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (events.po)

This example Hibernate source code file (events.po) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

auditable, auditinterceptor, cdata, cdata, hibernate, hibernate, loadeventlistener, object, object, serializable, string, tag, tag, type

The Hibernate events.po source code

# translation of Collection_Mapping.po to
# Xi Huang <xhuang@redhat.com>, 2006.
# Xi HUANG <xhuang@redhat.com>, 2007.
msgid ""
msgstr ""
"Project-Id-Version: Collection_Mapping\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-02-10T07:25:34\n"
"PO-Revision-Date: 2009-11-23 09:36+1000\n"
"Last-Translator: Xi HUANG <xhuang@redhat.com>\n"
"Language-Team:  <en@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: KBabel 1.11.4\n"

#. Tag: title
#, no-c-format
msgid "Interceptors and events"
msgstr "拦截器与事件(Interceptors and events)"

#. Tag: para
#, no-c-format
msgid ""
"It is useful for the application to react to certain events that occur "
"inside Hibernate. This allows for the implementation of generic "
"functionality and the extension of Hibernate functionality."
msgstr ""
"应用程序能够响应 Hibernate 内部产生的特定事件是非常有用的。这样就允许实现某些"
"通用的功能以及允许对 Hibernate 功能进行扩展。"

#. Tag: title
#, no-c-format
msgid "Interceptors"
msgstr "拦截器(Interceptors)"

#. Tag: para
#, no-c-format
msgid ""
"The <literal>Interceptor 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 "
"automatically sets the <literal>createTimestamp when an "
"<literal>Auditable is created and updates the "
"<literal>lastUpdateTimestamp property when an Auditable 接口提供了从会话(session)回调(callback)应"
"用程序(application)的机制, 这种回调机制可以允许应用程序在持久化对象被保"
"存、更新、删除或是加载之前,检查并(或)修改其 属性。一个可能的用途,就是用来"
"跟踪审核(auditing)信息。例如:下面的这个<literal>拦截器,会在一个"
"实现了 <literal>Auditable 接口的对象被创建时自动地设置 "
"<literal>createTimestamp 属性,并在实现了 AuditablelastUpdateTimestamp "
"属性。 "

#. Tag: para
#, no-c-format
msgid ""
"You can either implement <literal>Interceptor directly or extend "
"<literal>EmptyInterceptor."
msgstr ""
"你可以直接实现 <literal>Interceptor 接口,也可以(最好)继承自 "
"<literal>EmptyInterceptor。 "

#. Tag: para
#, no-c-format
msgid ""
"There are two kinds of inteceptors: <literal>Session-scoped and "
"<literal>SessionFactory-scoped."
msgstr ""
"拦截器可以有两种:<literal>Session 范围内的和 "
"<literal>SessionFactory 范围内的。"

#. Tag: para
#, no-c-format
msgid ""
"A <literal>Session-scoped interceptor is specified when a session "
"is opened using one of the overloaded SessionFactory.openSession() methods "
"accepting an <literal>Interceptor."
msgstr ""
"当使用某个重载的 SessionFactory.openSession() 使用 <literal>InterceptorSession-scoped interceptor is registered with "
"the <literal>Configuration object prior to building the "
"<literal>SessionFactory. Unless a session is opened explicitly "
"specifying the interceptor to use, the supplied interceptor will be applied "
"to all sessions opened from that <literal>SessionFactory. "
"<literal>SessionFactory-scoped interceptors must be thread safe. "
"Ensure that you do not store session-specific states, since multiple "
"sessions will use this interceptor potentially concurrently."
msgstr ""
"<literal>SessionFactory 范围内的拦截器要通过 "
"<literal>Configuration 中注册,而这必须在创建 "
"<literal>SessionFactory 之前。在这种情况下,给出的拦截器会被这个 "
"<literal>SessionFactory 所打开的所有 session 使用了;除非 session "
"打开时明确指明了使用的拦截器。<literal>SessionFactory 范围内的拦截"
"器,必须是线程安全的。确保你没有保存 session 专有的状态,因为多个 session 可"
"能并发使用这个拦截器。"

#. Tag: title
#, no-c-format
msgid "Event system"
msgstr "事件系统(Event system)"

#. Tag: para
#, no-c-format
msgid ""
"If you have to react to particular events in your persistence layer, you can "
"also use the Hibernate3 <emphasis>event architecture. The event "
"system can be used in addition, or as a replacement, for interceptors."
msgstr ""
"如果需要响应持久层的某些特殊事件,你也可以使用 Hibernate3 的事件框架。该事件"
"系统可以用来替代拦截器,也可以作为拦截器的补充来使用。 "

#. Tag: para
#, no-c-format
msgid ""
"All the methods of the <literal>Session interface correlate to an "
"event. You have a <literal>LoadEvent, a FlushEventorg."
"hibernate.event</literal> package for the full list of defined event types. "
"When a request is made of one of these methods, the Hibernate "
"<literal>Session generates an appropriate event and passes it to "
"the configured event listeners for that type. Out-of-the-box, these "
"listeners implement the same processing in which those methods always "
"resulted. However, you are free to implement a customization of one of the "
"listener interfaces (i.e., the <literal>LoadEvent is processed by "
"the registered implementation of the <literal>LoadEventListener "
"interface), in which case their implementation would be responsible for "
"processing any <literal>load() requests made of the "
"<literal>Session."
msgstr ""
"基本上,<literal>Session 接口的每个方法都有相对应的事件。比如 "
"<literal>LoadEvent,FlushEvent,等等(查阅 XML "
"配置文件的 DTD,以及 <literal>org.hibernate.event 包来获得所有已定"
"义的事件的列表)。当某个方 法被调用时,Hibernate <literal>Session会"
"生成一个相对应的事件并激活所 有配置好的事件监听器。系统预设的监听器实现的处理"
"过程就是被监听的方法要做的(被监听的方法所做的其实仅仅是激活监听器,“实际”的"
"工作是由监听器完成的)。不过,你可以自由地选择实现 一个自己定制的监听器(比"
"如,实现并注册用来处理处理 <literal>LoadEvent 的 "
"<literal>LoadEventListener 接口), 来负责处理所有的调用 "
"<literal>Session 的 load() 方法的请求。"

#. Tag: para
#, no-c-format
msgid ""
"The listeners should be considered singletons. This means they are shared "
"between requests, and should not save any state as instance variables."
msgstr ""
"监听器应该被看作是单例(singleton)对象,也就是说,所有同类型的事件的处理共享"
"同一个监听器实例,因此监听器不应该保存任何状态(也就是不应该使用成员变量)。"

#. Tag: para
#, no-c-format
msgid ""
"A custom listener implements the appropriate interface for the event it "
"wants to process and/or extend one of the convenience base classes (or even "
"the default event listeners used by Hibernate out-of-the-box as these are "
"declared non-final for this purpose). Custom listeners can either be "
"registered programmatically through the <literal>Configuration "
"object, or specified in the Hibernate configuration XML. Declarative "
"configuration through the properties file is not supported. Here is an "
"example of a custom load event listener:"
msgstr ""
"用户定制的监听器应该实现与所要处理的事件相对应的接口,或者从一个合适的基类继"
"承(甚至是从 Hibernate 自带的默认事件监听器类继承,为了方便你这样做,这些类都"
"被声明成 non-final 的了)。用户定制的监听器可以通过编程使用 "
"<literal>Configuration 对象 来注册,也可以在Hibernate的 XML 格式的"
"配置文件中进行声明(不支持在 Properties 格式的配置文件声明监听器)。下面是一"
"个用户定制的加载事件(load event)的监听器:"

#. Tag: para
#, no-c-format
msgid ""
"You also need a configuration entry telling Hibernate to use the listener in "
"addition to the default listener:"
msgstr ""
"你还需要修改一处配置,来告诉 Hibernate,除了默认的监听器,还要附加选定的监听"
"器。"

#. Tag: para
#, no-c-format
msgid "Instead, you can register it programmatically:"
msgstr "或者,你可以通过编程的方式来注册它:"

#. Tag: para
#, no-c-format
msgid ""
"Listeners registered declaratively cannot share instances. If the same class "
"name is used in multiple <literal><listener/> elements, each "
"reference will result in a separate instance of that class. If you need to "
"share listener instances between listener types you must use the "
"programmatic registration approach."
msgstr ""
"通过在XML配置文件声明而注册的监听器不能共享实例。如果在多个 <literal><"
"listener/></literal> 节点中使用 了相同的类的名字,则每一个引用都将会产生一"
"个独立的实例。如果你需要在多个监听器类型之间共享 监听器的实例,则你必须使用编"
"程的方式来进行注册。 "

#. Tag: para
#, no-c-format
msgid ""
"Why implement an interface and define the specific type during "
"configuration? A listener implementation could implement multiple event "
"listener interfaces. Having the type additionally defined during "
"registration makes it easier to turn custom listeners on or off during "
"configuration."
msgstr ""
"为什么我们实现了特定监听器的接口,在注册的时候还要明确指出我们要注册哪个事件"
"的监听器呢? 这是因为一个类可能实现多个监听器的接口。在注册的时候明确指定要监"
"听的事件,可以让启用或者禁用对某个事件的监听的配置工作简单些。 "

#. Tag: title
#, no-c-format
msgid "Hibernate declarative security"
msgstr "Hibernate 的声明式安全机制"

#. Tag: para
#, no-c-format
msgid ""
"Usually, declarative security in Hibernate applications is managed in a "
"session facade layer. Hibernate3 allows certain actions to be permissioned "
"via JACC, and authorized via JAAS. This is an optional functionality that is "
"built on top of the event architecture."
msgstr ""
"通常,Hibernate 应用程序的声明式安全机制由会话外观层(session facade)所管"
"理。现在,Hibernate3允许某些特定的行为由 JACC 进行许可管理,由 JAAS 进行授权"
"管理。本功能是一个建立在事件框架之上的可选的功能。 "

#. Tag: para
#, no-c-format
msgid ""
"First, you must configure the appropriate event listeners, to enable the use "
"of JAAS authorization."
msgstr ""
"首先,你必须要配置适当的事件监听器(event listener),来激活使用 JAAS 管理授"
"权的功能。"

#. Tag: para
#, no-c-format
msgid ""
"Note that <literal><listener type=\"...\" class=\"...\"/> is "
"shorthand for <literal><event type=\"...\"><listener class=\"...\"/"
"></event></literal> when there is exactly one listener for a "
"particular event type."
msgstr ""
"注意,<literal><listener type=\"...\" class=\"...\"/> 只是 "
"<literal><event type=\"...\"><listener class=\"...\"/></"
"event></literal> 的简写,对每一个事件类型都必须严格的有一个监听器与之对"
"应。 "

#. Tag: para
#, no-c-format
msgid ""
"Next, while still in <literal>hibernate.cfg.xml, bind the "
"permissions to roles:"
msgstr ""
"接下来,仍然在 <literal>hibernate.cfg.xml 文件中,绑定角色的权限: "

#. Tag: para
#, no-c-format
msgid "The role names are the roles understood by your JACC provider."
msgstr "这些角色的名字就是你的 JACC provider 所定义的角色的名字。"

#~ msgid ""
#~ "<![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 ""
#~ "<![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"
#~ "}]]>"

#~ msgid ""
#~ "<![CDATA[Session session = sf.openSession( new AuditInterceptor() );]]>"
#~ msgstr ""
#~ "<![CDATA[Session session = sf.openSession( new AuditInterceptor() );]]>"

#~ msgid ""
#~ "<![CDATA[new Configuration().setInterceptor( new AuditInterceptor() );]]>"
#~ msgstr ""
#~ "<![CDATA[new Configuration().setInterceptor( new AuditInterceptor() );]]>"

#~ msgid ""
#~ "<![CDATA[public class MyLoadListener implements LoadEventListener {\n"
#~ "    // this is the single method defined by the LoadEventListener "
#~ "interface\n"
#~ "    public void onLoad(LoadEvent event, LoadEventListener.LoadType "
#~ "loadType)\n"
#~ "            throws HibernateException {\n"
#~ "        if ( !MySecurity.isAuthorized( event.getEntityClassName(), event."
#~ "getEntityId() ) ) {\n"
#~ "            throw MySecurityException(\"Unauthorized access\");\n"
#~ "        }\n"
#~ "    }\n"
#~ "}]]>"
#~ msgstr ""
#~ "<![CDATA[public class MyLoadListener implements LoadEventListener {\n"
#~ "    // this is the single method defined by the LoadEventListener "
#~ "interface\n"
#~ "    public void onLoad(LoadEvent event, LoadEventListener.LoadType "
#~ "loadType)\n"
#~ "            throws HibernateException {\n"
#~ "        if ( !MySecurity.isAuthorized( event.getEntityClassName(), event."
#~ "getEntityId() ) ) {\n"
#~ "            throw MySecurityException(\"Unauthorized access\");\n"
#~ "        }\n"
#~ "    }\n"
#~ "}]]>"

#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<![CDATA["

#~ msgid ""
#~ "<![CDATA[Configuration cfg = new Configuration();\n"
#~ "LoadEventListener[] stack = { new MyLoadListener(), new "
#~ "DefaultLoadEventListener() };\n"
#~ "cfg.EventListeners().setLoadEventListeners(stack);]]>"
#~ msgstr ""
#~ "<![CDATA[Configuration cfg = new Configuration();\n"
#~ "LoadEventListener[] stack = { new MyLoadListener(), new "
#~ "DefaultLoadEventListener() };\n"
#~ "cfg.EventListeners().setLoadEventListeners(stack);]]>"

#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<![CDATA["

#~ msgid ""
#~ "<![CDATA["
#~ msgstr ""
#~ "<![CDATA["

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate events.po source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.