Edited Envers chapter
This commit is contained in:
parent
e34e464103
commit
70f53da5da
|
@ -5,50 +5,51 @@
|
||||||
<title>Tutorial Using Envers</title>
|
<title>Tutorial Using Envers</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
This tutorial is located within the download bundle under <filename>envers</filename> and illustrates
|
This tutorial is located within the download bundle under <filename>envers</filename>.
|
||||||
<itemizedlist>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
configuring Envers
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
using the Envers APIs to look back through history
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</para>
|
</para>
|
||||||
|
<itemizedlist>
|
||||||
|
<title>Objectives</title>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Configure Envers.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
Use the Envers APIs to view and analyze historical data.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
|
||||||
<section id="hibernate-gsg-tutorial-envers-config">
|
<section id="hibernate-gsg-tutorial-envers-config">
|
||||||
<title><filename>persistence.xml</filename></title>
|
<title><filename>persistence.xml</filename></title>
|
||||||
<para>
|
<para>
|
||||||
This file was discussed in the <phrase>JPA</phrase> tutorial, and is largely the same here. The major
|
This file was discussed in the <systemitem>JPA</systemitem> tutorial in <xref
|
||||||
difference is the set of properties defining <firstterm><phrase>listeners</phrase></firstterm>.
|
linkend="hibernate-gsg-tutorial-jpa-config" />, and is largely the same here. The major difference is the set
|
||||||
Essentially this enables Envers to recieve notfications from Hibernate processing of certain
|
of properties defining <firstterm>listeners</firstterm>. Listeners enable Envers to receive notfications from
|
||||||
<firstterm><phrase>events</phrase></firstterm> such as an entity being saved or updated.
|
Hibernate processing about <firstterm>events</firstterm> such as saving or updating of entities.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="hibernate-gsg-tutorial-envers-entity">
|
<section id="hibernate-gsg-tutorial-envers-entity">
|
||||||
<title>The annotated entity Java class</title>
|
<title>The annotated entity Java class</title>
|
||||||
<para>
|
<para>
|
||||||
Again, the entity is largely the same as seen in the <phrase>JPA</phrase> tutorial. The major
|
Again, the entity is largely the same as in <xref linkend="hibernate-gsg-tutorial-jpa-entity" /> . The major
|
||||||
difference to notice is the addition of the <interfacename>@org.hibernate.envers.Audited</interfacename>
|
difference is the addition of the <interfacename>@org.hibernate.envers.Audited</interfacename> annotation, which
|
||||||
annotation which tells Envers to automatically track changes to this entity.
|
tells Envers to automatically track changes to this entity.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="hibernate-gsg-tutorial-envers-test">
|
<section id="hibernate-gsg-tutorial-envers-test">
|
||||||
<title>Example code</title>
|
<title>Example code</title>
|
||||||
<para>
|
<para>
|
||||||
Again, this tutorial makes use of the <phrase>JPA</phrase> APIs. However, the code also makes a
|
Again, this tutorial makes use of the <systemitem>JPA</systemitem> APIs. However, the code also makes a change to one
|
||||||
change to one of the entites and then uses the Envers API to pull back the initial revision (version)
|
of the entites, then uses the Envers API to pull back the initial <firstterm>revision</firstterm> as well as the updated
|
||||||
as well as the updated revision.
|
revision. A revision refers to a version of an entity.
|
||||||
</para>
|
</para>
|
||||||
<example id="hibernate-gsg-tutorial-envers-test-api">
|
<example id="hibernate-gsg-tutorial-envers-test-api">
|
||||||
<title>Using the <interfacename>org.hibernate.envers.AuditReader</interfacename></title>
|
<title>Using the <interfacename>org.hibernate.envers.AuditReader</interfacename></title>
|
||||||
<programlisting role="JAVA">public void testBasicUsage() {
|
<programlisting role="JAVA">public void testBasicUsage() {
|
||||||
...
|
...
|
||||||
AuditReader reader = AuditReaderFactory.get( entityManager );
|
AuditReader reader = AuditReaderFactory.get( entityManager );
|
||||||
Event firstRevision = reader.find( Event.class, 2L, 1 );
|
Event firstRevision = reader.find( Event.class, 2L, 1 );
|
||||||
|
@ -56,17 +57,41 @@
|
||||||
Event secondRevision = reader.find( Event.class, 2L, 2 );
|
Event secondRevision = reader.find( Event.class, 2L, 2 );
|
||||||
...
|
...
|
||||||
}</programlisting>
|
}</programlisting>
|
||||||
</example>
|
</example>
|
||||||
<para>
|
<procedure>
|
||||||
First an <interfacename>org.hibernate.envers.AuditReader</interfacename> is obtained
|
<title>Description of Example</title>
|
||||||
from the <classname>org.hibernate.envers.AuditReaderFactory</classname> wrapping the
|
<step>
|
||||||
|
<para>
|
||||||
|
An <interfacename>org.hibernate.envers.AuditReader</interfacename> is obtained from the
|
||||||
|
<classname>org.hibernate.envers.AuditReaderFactory</classname> which wraps the
|
||||||
<interfacename>javax.persistence.EntityManager</interfacename>.
|
<interfacename>javax.persistence.EntityManager</interfacename>.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
</step>
|
||||||
Then the <methodname>find</methodname> method is used to retrieve specific revisions of the entity. The
|
<step>
|
||||||
first call reads "find revision number 1 of Event with id 2". The second call reads "find revision
|
<para>
|
||||||
number 2 of Event with id 2".
|
Next,the <methodname>find</methodname> method retrieves specific revisions of the entity. The first call
|
||||||
</para>
|
reads <literal>find revision number 1 of Event with id 2</literal>. The second call reads <literal>find
|
||||||
|
revision number 2 of Event with id 2</literal>.
|
||||||
|
</para>
|
||||||
|
</step>
|
||||||
|
</procedure>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section id="hibernate-gsg-tutorial-annotations-further">
|
||||||
|
<title>Take it further!</title>
|
||||||
|
<itemizedlist>
|
||||||
|
<title>Practice Exercises</title>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
<listitem>
|
||||||
|
<para>
|
||||||
|
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</itemizedlist>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
</chapter>
|
</chapter>
|
|
@ -127,18 +127,5 @@ entityManager.close();]]></programlisting>
|
||||||
<section id="hibernate-gsg-tutorial-annotations-further">
|
<section id="hibernate-gsg-tutorial-annotations-further">
|
||||||
<title>Take it further!</title>
|
<title>Take it further!</title>
|
||||||
<itemizedlist>
|
<itemizedlist>
|
||||||
<title>Practice Exercises</title>
|
<title>Practice Exercises</title> <listitem> <para> </para> </listitem> <listitem> <para> </para> </listitem>
|
||||||
<listitem>
|
</itemizedlist> </section> </chapter>
|
||||||
<para>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
<listitem>
|
|
||||||
<para>
|
|
||||||
|
|
||||||
</para>
|
|
||||||
</listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
</chapter>
|
|
Loading…
Reference in New Issue