|
Hibernate example source code file (DefaultTrackingEntitiesTest.java)
The Hibernate DefaultTrackingEntitiesTest.java source codepackage org.hibernate.envers.test.integration.reventity.trackmodifiedentities; import org.hibernate.ejb.Ejb3Configuration; import org.hibernate.envers.CrossTypeRevisionChangesReader; import org.hibernate.envers.RevisionType; import org.hibernate.envers.test.AbstractEntityTest; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrIntTestEntity; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.tools.TestTools; import org.hibernate.envers.tools.Pair; import org.hibernate.mapping.Column; import org.hibernate.mapping.Table; import org.junit.Test; import javax.persistence.EntityManager; import java.util.Iterator; import java.util.List; import java.util.Map; /** * Tests proper behavior of tracking modified entity names when {@code org.hibernate.envers.track_entities_changed_in_revision} * parameter is set to {@code true}. * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ @SuppressWarnings({"unchecked"}) public class DefaultTrackingEntitiesTest extends AbstractEntityTest { private Integer steId = null; private Integer siteId = null; @Override public void configure(Ejb3Configuration cfg) { cfg.setProperty("org.hibernate.envers.track_entities_changed_in_revision", "true"); cfg.addAnnotatedClass(StrTestEntity.class); cfg.addAnnotatedClass(StrIntTestEntity.class); } @Test @Priority(10) public void initData() { EntityManager em = getEntityManager(); // Revision 1 - Adding two entities em.getTransaction().begin(); StrTestEntity ste = new StrTestEntity("x"); StrIntTestEntity site = new StrIntTestEntity("y", 1); em.persist(ste); em.persist(site); steId = ste.getId(); siteId = site.getId(); em.getTransaction().commit(); // Revision 2 - Modifying one entity em.getTransaction().begin(); site = em.find(StrIntTestEntity.class, siteId); site.setNumber(2); em.getTransaction().commit(); // Revision 3 - Deleting both entities em.getTransaction().begin(); ste = em.find(StrTestEntity.class, steId); site = em.find(StrIntTestEntity.class, siteId); em.remove(ste); em.remove(site); em.getTransaction().commit(); } @Test public void testRevEntityTableCreation() { Iterator<Table> tableIterator = getCfg().getTableMappings(); while (tableIterator.hasNext()) { Table table = tableIterator.next(); if ("REVCHANGES".equals(table.getName())) { assert table.getColumnSpan() == 2; assert table.getColumn(new Column("REV")) != null; assert table.getColumn(new Column("ENTITYNAME")) != null; return; } } assert false; } @Test public void testTrackAddedEntities() { StrTestEntity ste = new StrTestEntity("x", steId); StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(1), ste, site); } @Test public void testTrackModifiedEntities() { StrIntTestEntity site = new StrIntTestEntity("y", 2, siteId); assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(2), site); } @Test public void testTrackDeletedEntities() { StrTestEntity ste = new StrTestEntity(null, steId); StrIntTestEntity site = new StrIntTestEntity(null, null, siteId); assert TestTools.checkList(getCrossTypeRevisionChangesReader().findEntities(3), site, ste); } @Test public void testFindChangesInInvalidRevision() { assert getCrossTypeRevisionChangesReader().findEntities(4).isEmpty(); } @Test public void testTrackAddedEntitiesGroupByRevisionType() { StrTestEntity ste = new StrTestEntity("x", steId); StrIntTestEntity site = new StrIntTestEntity("y", 1, siteId); Map<RevisionType, List Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate DefaultTrackingEntitiesTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.