X-Git-Url: http://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fit%2Ftutorials-5.1.17%2Fenvers%2Fsrc%2Ftest%2Fjava%2Forg%2Fhibernate%2Ftutorial%2Fenvers%2FEnversIllustrationTest.java;fp=src%2Fit%2Ftutorials-5.1.17%2Fenvers%2Fsrc%2Ftest%2Fjava%2Forg%2Fhibernate%2Ftutorial%2Fenvers%2FEnversIllustrationTest.java;h=5e29faa6b93e33e623bd9ad9af09d530308d3220;hb=3990b3badc8320a705c9899b0a63f40b4b219d1a;hp=0000000000000000000000000000000000000000;hpb=d42dc8bc0d20f97e64dacd7983486fe18af0c8df;p=hibernate4-maven-plugin diff --git a/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/EnversIllustrationTest.java b/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/EnversIllustrationTest.java new file mode 100644 index 00000000..5e29faa6 --- /dev/null +++ b/src/it/tutorials-5.1.17/envers/src/test/java/org/hibernate/tutorial/envers/EnversIllustrationTest.java @@ -0,0 +1,105 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2010, Red Hat Inc. or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Inc. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.tutorial.envers; + +import java.util.Date; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import junit.framework.TestCase; + +import org.hibernate.envers.AuditReader; +import org.hibernate.envers.AuditReaderFactory; + +/** + * Illustrates the set up and use of Envers. + *
+ * This example is different from the others in that we really need to save multiple revisions to the entity in
+ * order to get a good look at Envers in action.
+ *
+ * @author Steve Ebersole
+ */
+public class EnversIllustrationTest extends TestCase {
+ private EntityManagerFactory entityManagerFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ // like discussed with regards to SessionFactory, an EntityManagerFactory is set up once for an application
+ // IMPORTANT: notice how the name here matches the name we gave the persistence-unit in persistence.xml!
+ entityManagerFactory = Persistence.createEntityManagerFactory( "org.hibernate.tutorial.envers" );
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ entityManagerFactory.close();
+ }
+
+ public void testBasicUsage() {
+ // create a couple of events
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ entityManager.getTransaction().begin();
+ entityManager.persist( new Event( "Our very first event!", new Date() ) );
+ entityManager.persist( new Event( "A follow up event", new Date() ) );
+ entityManager.getTransaction().commit();
+ entityManager.close();
+
+ // now lets pull events from the database and list them
+ entityManager = entityManagerFactory.createEntityManager();
+ entityManager.getTransaction().begin();
+ List