HHH-5276 - REVINFO in different database schema creation
This commit is contained in:
parent
d2f7ee8ae5
commit
ac49a906e8
|
@ -72,10 +72,10 @@ public class RevisionInfoConfiguration {
|
|||
revisionPropType = "integer";
|
||||
}
|
||||
|
||||
private Document generateDefaultRevisionInfoXmlMapping() {
|
||||
private Document generateDefaultRevisionInfoXmlMapping(Configuration cfg) {
|
||||
Document document = DocumentHelper.createDocument();
|
||||
|
||||
Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, null, null), null);
|
||||
Element class_mapping = MetadataTools.createEntity(document, new AuditTableData(null, null, cfg.getProperty("org.hibernate.envers.default_schema"), cfg.getProperty("org.hibernate.envers.default_catalog")), null);
|
||||
|
||||
class_mapping.addAttribute("name", revisionInfoEntityName);
|
||||
class_mapping.addAttribute("table", "REVINFO");
|
||||
|
@ -236,7 +236,7 @@ public class RevisionInfoConfiguration {
|
|||
revisionInfoClass = DefaultRevisionEntity.class;
|
||||
revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
|
||||
RevisionListener.class, revisionInfoTimestampData, isTimestampAsDate());
|
||||
revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
|
||||
revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping(cfg);
|
||||
}
|
||||
|
||||
return new RevisionInfoConfigurationResult(
|
||||
|
@ -244,10 +244,10 @@ public class RevisionInfoConfiguration {
|
|||
new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdData.getName(),
|
||||
revisionInfoTimestampData.getName(), isTimestampAsDate()),
|
||||
generateRevisionInfoRelationMapping(),
|
||||
new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData), revisionInfoEntityName,
|
||||
new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData), revisionInfoEntityName,
|
||||
revisionInfoClass, revisionInfoTimestampData);
|
||||
}
|
||||
|
||||
|
||||
private boolean isTimestampAsDate() {
|
||||
String typename = revisionInfoTimestampType.getName();
|
||||
return "date".equals(typename) || "time".equals(typename) || "timestamp".equals(typename);
|
||||
|
@ -310,5 +310,5 @@ class RevisionInfoConfigurationResult {
|
|||
public PropertyData getRevisionInfoTimestampData() {
|
||||
return revisionInfoTimestampData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package org.hibernate.envers.test.integration.reventity;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Tests simple auditing process (read and write operations) when <i>REVINFO</i> and audit tables
|
||||
* exist in a different database schema.
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class DifferentDBSchemaTest extends AbstractEntityTest {
|
||||
private static final String SCHEMA_NAME = "ENVERS_AUDIT";
|
||||
private Integer steId = null;
|
||||
|
||||
@Override
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
// Creates new schema after establishing connection
|
||||
cfg.setProperty(Environment.URL, cfg.getProperties().getProperty(Environment.URL) + ";INIT=CREATE SCHEMA IF NOT EXISTS " + SCHEMA_NAME);
|
||||
cfg.setProperty("org.hibernate.envers.default_schema", SCHEMA_NAME);
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Priority(10)
|
||||
public void initData() throws InterruptedException {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
StrTestEntity ste = new StrTestEntity("x");
|
||||
em.persist(ste);
|
||||
steId = ste.getId();
|
||||
em.getTransaction().commit();
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
ste = em.find(StrTestEntity.class, steId);
|
||||
ste.setStr("y");
|
||||
em.getTransaction().commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevinfoSchemaName() {
|
||||
Table revisionTable = getCfg().getClassMapping("org.hibernate.envers.DefaultRevisionEntity").getTable();
|
||||
assert SCHEMA_NAME.equals(revisionTable.getSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsCounts() {
|
||||
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, steId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHistoryOfId1() {
|
||||
StrTestEntity ver1 = new StrTestEntity("x", steId);
|
||||
StrTestEntity ver2 = new StrTestEntity("y", steId);
|
||||
|
||||
assert getAuditReader().find(StrTestEntity.class, steId, 1).equals(ver1);
|
||||
assert getAuditReader().find(StrTestEntity.class, steId, 2).equals(ver2);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue