HHH-7187 - Enhanced default revision entity
This commit is contained in:
parent
775b6da1db
commit
c4822556c1
|
@ -70,6 +70,9 @@ public class GlobalConfiguration {
|
|||
// Suffix to be used for modified flags columns
|
||||
private String modifiedFlagSuffix;
|
||||
|
||||
// Use enhanced default revision entity (only for internal use)
|
||||
private final boolean useEnhancedRevisionEntity;
|
||||
|
||||
/*
|
||||
Which operator to use in correlated subqueries (when we want a property to be equal to the result of
|
||||
a correlated subquery, for example: e.p <operator> (select max(e2.p) where e2.p2 = e.p2 ...).
|
||||
|
@ -109,6 +112,12 @@ public class GlobalConfiguration {
|
|||
"false");
|
||||
trackEntitiesChangedInRevisionEnabled = Boolean.parseBoolean(trackEntitiesChangedInRevisionEnabledStr);
|
||||
|
||||
String useEnhancedRevisionEntityStr = getProperty(properties,
|
||||
"org.hibernate.envers.use_enhanced_revision_entity",
|
||||
"org.hibernate.envers.use_enhanced_revision_entity",
|
||||
"false");
|
||||
useEnhancedRevisionEntity = Boolean.parseBoolean(useEnhancedRevisionEntityStr);
|
||||
|
||||
hasGlobalSettingForWithModifiedFlag =
|
||||
properties.getProperty(GLOBAL_WITH_MODIFIED_FLAG_PROPERTY) != null;
|
||||
String usingModifiedFlagStr = getProperty(properties,
|
||||
|
@ -181,4 +190,8 @@ public class GlobalConfiguration {
|
|||
public String getModifiedFlagSuffix() {
|
||||
return modifiedFlagSuffix;
|
||||
}
|
||||
|
||||
public boolean isUseEnhancedRevisionEntity() {
|
||||
return useEnhancedRevisionEntity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,11 @@ public class RevisionInfoConfiguration {
|
|||
|
||||
public RevisionInfoConfiguration(GlobalConfiguration globalCfg) {
|
||||
this.globalCfg = globalCfg;
|
||||
revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
|
||||
if (globalCfg.isUseEnhancedRevisionEntity()) {
|
||||
revisionInfoEntityName = "org.hibernate.envers.enhanced.DefaultRevisionEntity";
|
||||
} else {
|
||||
revisionInfoEntityName = "org.hibernate.envers.DefaultRevisionEntity";
|
||||
}
|
||||
revisionInfoIdData = new PropertyData("id", "id", "field", null);
|
||||
revisionInfoTimestampData = new PropertyData("timestamp", "timestamp", "field", null);
|
||||
modifiedEntityNamesData = new PropertyData("modifiedEntityNames", "modifiedEntityNames", "field", null);
|
||||
|
@ -93,7 +97,7 @@ public class RevisionInfoConfiguration {
|
|||
class_mapping.addAttribute("table", "REVINFO");
|
||||
|
||||
Element idProperty = MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdData.getName(),
|
||||
revisionPropType);
|
||||
revisionPropType, globalCfg.isUseEnhancedRevisionEntity());
|
||||
MetadataTools.addColumn(idProperty, "REV", null, null, null, null, null, null, false);
|
||||
|
||||
Element timestampProperty = MetadataTools.addProperty(class_mapping, revisionInfoTimestampData.getName(),
|
||||
|
@ -291,9 +295,10 @@ public class RevisionInfoConfiguration {
|
|||
revisionInfoClass = pc.getMappedClass();
|
||||
Class<? extends RevisionListener> revisionListenerClass = getRevisionListenerClass(revisionEntity.value());
|
||||
revisionInfoTimestampType = pc.getProperty(revisionInfoTimestampData.getName()).getType();
|
||||
if (globalCfg.isTrackEntitiesChangedInRevisionEnabled() ||
|
||||
DefaultTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass) ||
|
||||
modifiedEntityNamesFound.isSet()) {
|
||||
if (globalCfg.isTrackEntitiesChangedInRevisionEnabled()
|
||||
|| (!globalCfg.isUseEnhancedRevisionEntity() && DefaultTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass))
|
||||
|| (globalCfg.isUseEnhancedRevisionEntity() && org.hibernate.envers.enhanced.DefaultTrackingModifiedEntitiesRevisionEntity.class.isAssignableFrom(revisionInfoClass))
|
||||
|| modifiedEntityNamesFound.isSet()) {
|
||||
// If tracking modified entities parameter is enabled, custom revision info entity is a subtype
|
||||
// of DefaultTrackingModifiedEntitiesRevisionEntity class, or @ModifiedEntityNames annotation is used.
|
||||
revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName,
|
||||
|
@ -314,12 +319,14 @@ public class RevisionInfoConfiguration {
|
|||
|
||||
if (revisionInfoGenerator == null) {
|
||||
if (globalCfg.isTrackEntitiesChangedInRevisionEnabled()) {
|
||||
revisionInfoClass = DefaultTrackingModifiedEntitiesRevisionEntity.class;
|
||||
revisionInfoEntityName = DefaultTrackingModifiedEntitiesRevisionEntity.class.getName();
|
||||
revisionInfoClass = globalCfg.isUseEnhancedRevisionEntity() ? org.hibernate.envers.enhanced.DefaultTrackingModifiedEntitiesRevisionEntity.class
|
||||
: DefaultTrackingModifiedEntitiesRevisionEntity.class;
|
||||
revisionInfoEntityName = revisionInfoClass.getName();
|
||||
revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
|
||||
revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate(), modifiedEntityNamesData);
|
||||
} else {
|
||||
revisionInfoClass = DefaultRevisionEntity.class;
|
||||
revisionInfoClass = globalCfg.isUseEnhancedRevisionEntity() ? org.hibernate.envers.enhanced.DefaultRevisionEntity.class
|
||||
: DefaultRevisionEntity.class;
|
||||
revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
|
||||
revisionListenerClass, revisionInfoTimestampData, isTimestampAsDate());
|
||||
}
|
||||
|
|
|
@ -40,14 +40,23 @@ import org.hibernate.mapping.Formula;
|
|||
*/
|
||||
public class MetadataTools {
|
||||
|
||||
public static Element addNativelyGeneratedId(Element parent, String name, String type) {
|
||||
public static Element addNativelyGeneratedId(Element parent, String name, String type,
|
||||
boolean useEnhancedRevisionEntity) {
|
||||
Element id_mapping = parent.addElement("id");
|
||||
id_mapping.addAttribute("name", name).addAttribute("type", type);
|
||||
|
||||
Element generator_mapping = id_mapping.addElement("generator");
|
||||
generator_mapping.addAttribute("class", "native");
|
||||
/*generator_mapping.addAttribute("class", "sequence");
|
||||
generator_mapping.addElement("param").addAttribute("name", "sequence").setText("custom");*/
|
||||
if (useEnhancedRevisionEntity) {
|
||||
generator_mapping.addAttribute("class", "org.hibernate.id.enhanced.SequenceStyleGenerator");
|
||||
generator_mapping.addElement("param").addAttribute("name", "sequence_name").setText("REVISION_GENERATOR");
|
||||
generator_mapping.addElement("param").addAttribute("name", "table_name").setText("REVISION_GENERATOR");
|
||||
generator_mapping.addElement("param").addAttribute("name", "initial_value").setText("1");
|
||||
generator_mapping.addElement("param").addAttribute("name", "increment_size").setText("1");
|
||||
} else {
|
||||
generator_mapping.addAttribute("class", "native");
|
||||
}
|
||||
// generator_mapping.addAttribute("class", "sequence");
|
||||
// generator_mapping.addElement("param").addAttribute("name", "sequence").setText("custom");
|
||||
|
||||
return id_mapping;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.envers.enhanced;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import org.hibernate.envers.RevisionNumber;
|
||||
import org.hibernate.envers.RevisionTimestamp;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Transient;
|
||||
import java.io.Serializable;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class DefaultRevisionEntity implements Serializable {
|
||||
private static final long serialVersionUID = 4159156677698841902L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(generator = "RevisionNumberSequenceGenerator")
|
||||
@GenericGenerator(name = "RevisionNumberSequenceGenerator",
|
||||
strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
|
||||
parameters = {@Parameter(name = "table_name", value = "REVISION_GENERATOR"),
|
||||
@Parameter(name = "sequence_name", value = "REVISION_GENERATOR"),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "1")
|
||||
}
|
||||
)
|
||||
@RevisionNumber
|
||||
private int id;
|
||||
|
||||
@RevisionTimestamp
|
||||
private long timestamp;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public Date getRevisionDate() {
|
||||
return new Date(timestamp);
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DefaultRevisionEntity)) return false;
|
||||
|
||||
DefaultRevisionEntity that = (DefaultRevisionEntity) o;
|
||||
|
||||
if (id != that.id) return false;
|
||||
if (timestamp != that.timestamp) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = id;
|
||||
result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "DefaultRevisionEntity(id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ")";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC 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 Middleware LLC.
|
||||
*
|
||||
* 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.envers.enhanced;
|
||||
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.envers.ModifiedEntityNames;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Extension of standard {@link DefaultRevisionEntity} that allows tracking entity names changed in each revision.
|
||||
* This revision entity is implicitly used 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)
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class DefaultTrackingModifiedEntitiesRevisionEntity extends DefaultRevisionEntity {
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV"))
|
||||
@Column(name = "ENTITYNAME")
|
||||
@Fetch(FetchMode.JOIN)
|
||||
@ModifiedEntityNames
|
||||
private Set<String> modifiedEntityNames = new HashSet<String>();
|
||||
|
||||
public Set<String> getModifiedEntityNames() {
|
||||
return modifiedEntityNames;
|
||||
}
|
||||
|
||||
public void setModifiedEntityNames(Set<String> modifiedEntityNames) {
|
||||
this.modifiedEntityNames = modifiedEntityNames;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof DefaultTrackingModifiedEntitiesRevisionEntity)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
DefaultTrackingModifiedEntitiesRevisionEntity that = (DefaultTrackingModifiedEntitiesRevisionEntity) o;
|
||||
|
||||
if (modifiedEntityNames != null ? !modifiedEntityNames.equals(that.modifiedEntityNames)
|
||||
: that.modifiedEntityNames != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (modifiedEntityNames != null ? modifiedEntityNames.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "DefaultTrackingModifiedEntitiesRevisionEntity(" + super.toString() + ", modifiedEntityNames = " + modifiedEntityNames + ")";
|
||||
}
|
||||
}
|
|
@ -27,9 +27,6 @@ import java.io.IOException;
|
|||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.OracleRevisionEntity;
|
||||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.OracleTrackingModifiedEntitiesRevisionEntity;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
@ -61,16 +58,6 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
|
|||
|
||||
public abstract void configure(Ejb3Configuration cfg);
|
||||
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
if (dialect instanceof Oracle8iDialect) {
|
||||
if (Boolean.parseBoolean(configurationProperties.getProperty("org.hibernate.envers.track_entities_changed_in_revision"))) {
|
||||
cfg.addAnnotatedClass(OracleTrackingModifiedEntitiesRevisionEntity.class);
|
||||
} else {
|
||||
cfg.addAnnotatedClass(OracleRevisionEntity.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addConfigurationProperties(Properties configuration) { }
|
||||
|
||||
protected static Dialect getDialect() {
|
||||
|
@ -110,6 +97,8 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
|
|||
}
|
||||
if ( createSchema() ) {
|
||||
configurationProperties.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
configurationProperties.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
configurationProperties.setProperty("org.hibernate.envers.use_enhanced_revision_entity", "true");
|
||||
}
|
||||
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
||||
configurationProperties.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
||||
|
@ -119,7 +108,6 @@ public abstract class AbstractEntityTest extends AbstractEnversTest {
|
|||
|
||||
cfg = new Ejb3Configuration();
|
||||
configure(cfg);
|
||||
revisionEntityForDialect(cfg, getDialect(), configurationProperties);
|
||||
cfg.configure(configurationProperties);
|
||||
|
||||
emf = (EntityManagerFactoryImpl) cfg.buildEntityManagerFactory( createBootstrapRegistryBuilder() );
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.io.File;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
|
@ -41,6 +42,8 @@ public abstract class AbstractOneSessionTest extends AbstractEnversTest {
|
|||
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
||||
config.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
|
||||
}
|
||||
config.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
config.setProperty("org.hibernate.envers.use_enhanced_revision_entity", "true");
|
||||
addProperties(config);
|
||||
|
||||
this.initMappings();
|
||||
|
|
|
@ -3,9 +3,6 @@ package org.hibernate.envers.test;
|
|||
import java.net.URISyntaxException;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.OracleRevisionEntity;
|
||||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.OracleTrackingModifiedEntitiesRevisionEntity;
|
||||
import org.junit.Before;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
|
@ -44,6 +41,8 @@ public abstract class AbstractSessionTest extends AbstractEnversTest {
|
|||
config = new Configuration();
|
||||
if ( createSchema() ) {
|
||||
config.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
|
||||
config.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
config.setProperty("org.hibernate.envers.use_enhanced_revision_entity", "true");
|
||||
}
|
||||
String auditStrategy = getAuditStrategy();
|
||||
if (auditStrategy != null && !"".equals(auditStrategy)) {
|
||||
|
@ -51,7 +50,6 @@ public abstract class AbstractSessionTest extends AbstractEnversTest {
|
|||
}
|
||||
|
||||
this.initMappings();
|
||||
revisionEntityForDialect(config, getDialect());
|
||||
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
|
||||
sessionFactory = config.buildSessionFactory( serviceRegistry );
|
||||
|
@ -61,16 +59,6 @@ public abstract class AbstractSessionTest extends AbstractEnversTest {
|
|||
}
|
||||
protected abstract void initMappings() throws MappingException, URISyntaxException ;
|
||||
|
||||
protected void revisionEntityForDialect(Configuration cfg, Dialect dialect) {
|
||||
if (dialect instanceof Oracle8iDialect) {
|
||||
if (Boolean.parseBoolean(config.getProperty("org.hibernate.envers.track_entities_changed_in_revision"))) {
|
||||
cfg.addAnnotatedClass(OracleTrackingModifiedEntitiesRevisionEntity.class);
|
||||
} else {
|
||||
cfg.addAnnotatedClass(OracleRevisionEntity.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SessionFactory getSessionFactory(){
|
||||
return sessionFactory;
|
||||
}
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
package org.hibernate.envers.test.entities.reventity;
|
||||
|
||||
import org.hibernate.envers.RevisionNumber;
|
||||
import org.hibernate.envers.RevisionTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public abstract class AbstractOracleRevisionEntity implements Serializable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "RevisionNumberSequenceGenerator")
|
||||
@SequenceGenerator(name = "RevisionNumberSequenceGenerator", sequenceName="REVISION_SEQ",
|
||||
allocationSize = 1, initialValue = 1)
|
||||
@RevisionNumber
|
||||
private int id;
|
||||
|
||||
@RevisionTimestamp
|
||||
private long timestamp;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Transient
|
||||
public Date getRevisionDate() {
|
||||
return new Date(timestamp);
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AbstractOracleRevisionEntity)) return false;
|
||||
|
||||
AbstractOracleRevisionEntity that = (AbstractOracleRevisionEntity) o;
|
||||
|
||||
if (id != that.id) return false;
|
||||
if (timestamp != that.timestamp) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = id;
|
||||
result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AbstractOracleRevisionEntity(id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ")";
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package org.hibernate.envers.test.entities.reventity;
|
||||
|
||||
import org.hibernate.envers.RevisionEntity;
|
||||
import org.hibernate.envers.RevisionNumber;
|
||||
import org.hibernate.envers.RevisionTimestamp;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Entity
|
||||
@RevisionEntity
|
||||
public class OracleRevisionEntity extends AbstractOracleRevisionEntity {
|
||||
public String toString() {
|
||||
return "OracleRevisionEntity(" + super.toString() + ")";
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package org.hibernate.envers.test.entities.reventity.trackmodifiedentities;
|
||||
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.envers.ModifiedEntityNames;
|
||||
import org.hibernate.envers.test.entities.reventity.AbstractOracleRevisionEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public abstract class AbstractOracleTrackingModifiedEntitiesRevisionEntity extends AbstractOracleRevisionEntity {
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "REVCHANGES", joinColumns = @JoinColumn(name = "REV"))
|
||||
@Column(name = "ENTITYNAME")
|
||||
@Fetch(FetchMode.JOIN)
|
||||
@ModifiedEntityNames
|
||||
private Set<String> modifiedEntityNames = new HashSet<String>();
|
||||
|
||||
public Set<String> getModifiedEntityNames() {
|
||||
return modifiedEntityNames;
|
||||
}
|
||||
|
||||
public void setModifiedEntityNames(Set<String> modifiedEntityNames) {
|
||||
this.modifiedEntityNames = modifiedEntityNames;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AbstractOracleTrackingModifiedEntitiesRevisionEntity)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
AbstractOracleTrackingModifiedEntitiesRevisionEntity that = (AbstractOracleTrackingModifiedEntitiesRevisionEntity) o;
|
||||
|
||||
if (modifiedEntityNames != null ? !modifiedEntityNames.equals(that.modifiedEntityNames)
|
||||
: that.modifiedEntityNames != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (modifiedEntityNames != null ? modifiedEntityNames.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "AbstractOracleTrackingModifiedEntitiesRevisionEntity(" + super.toString() + ", modifiedEntityNames = " + modifiedEntityNames + ")";
|
||||
}
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
package org.hibernate.envers.test.entities.reventity.trackmodifiedentities;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
import org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity;
|
||||
import org.hibernate.envers.enhanced.DefaultTrackingModifiedEntitiesRevisionEntity;
|
||||
import org.hibernate.envers.RevisionEntity;
|
||||
|
||||
/**
|
||||
|
@ -11,6 +12,7 @@ import org.hibernate.envers.RevisionEntity;
|
|||
@Entity
|
||||
@RevisionEntity(ExtendedRevisionListener.class)
|
||||
public class ExtendedRevisionEntity extends DefaultTrackingModifiedEntitiesRevisionEntity {
|
||||
@Column(name = "USER_COMMENT")
|
||||
private String comment;
|
||||
|
||||
public String getComment() {
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
package org.hibernate.envers.test.entities.reventity.trackmodifiedentities;
|
||||
|
||||
import org.hibernate.envers.RevisionEntity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Entity
|
||||
@RevisionEntity(OracleExtendedRevisionListener.class)
|
||||
public class OracleExtendedRevisionEntity extends AbstractOracleTrackingModifiedEntitiesRevisionEntity {
|
||||
private String userComment;
|
||||
|
||||
public String getUserComment() {
|
||||
return userComment;
|
||||
}
|
||||
|
||||
public void setUserComment(String userComment) {
|
||||
this.userComment = userComment;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package org.hibernate.envers.test.entities.reventity.trackmodifiedentities;
|
||||
|
||||
import org.hibernate.envers.RevisionListener;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class OracleExtendedRevisionListener implements RevisionListener {
|
||||
public static final String COMMENT_VALUE = "User Comment";
|
||||
|
||||
public void newRevision(Object revisionEntity) {
|
||||
((OracleExtendedRevisionEntity)revisionEntity).setUserComment(COMMENT_VALUE);
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package org.hibernate.envers.test.entities.reventity.trackmodifiedentities;
|
||||
|
||||
import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.envers.ModifiedEntityNames;
|
||||
import org.hibernate.envers.RevisionEntity;
|
||||
import org.hibernate.envers.test.entities.reventity.AbstractOracleRevisionEntity;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "TrackModifiedEntitiesRevInfo")
|
||||
@RevisionEntity
|
||||
public class OracleTrackingModifiedEntitiesRevisionEntity extends AbstractOracleTrackingModifiedEntitiesRevisionEntity {
|
||||
public String toString() {
|
||||
return "OracleTrackingModifiedEntitiesRevisionEntity(" + super.toString() + ")";
|
||||
}
|
||||
}
|
|
@ -26,9 +26,7 @@ package org.hibernate.envers.test.integration.basic;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -49,11 +47,6 @@ public class NoneAudited extends AbstractEntityTest {
|
|||
// The AuditReader shouldn't be created
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
// Do not add any dialect-specific Envers configuration.
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionInfoTableNotCreated() {
|
||||
@SuppressWarnings({"unchecked"}) List<PersistentClass> pcs = iteratorToList(getCfg().getClassMappings());
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Properties;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.RollbackException;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -46,10 +45,6 @@ import org.hibernate.testing.jta.TestingJtaBootstrap;
|
|||
public class JtaExceptionListener extends AbstractEntityTest {
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(ExceptionListenerRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,10 +32,13 @@ import javax.persistence.ElementCollection;
|
|||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.envers.AuditJoinTable;
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||
import org.hibernate.envers.test.entities.components.Component1;
|
||||
|
@ -45,6 +48,7 @@ import org.hibernate.envers.test.entities.components.Component2;
|
|||
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "PartialModFlags")
|
||||
@Audited(withModifiedFlag = false)
|
||||
public class PartialModifiedFlagsEntity {
|
||||
@Id
|
||||
|
@ -71,6 +75,8 @@ public class PartialModifiedFlagsEntity {
|
|||
|
||||
@Audited(withModifiedFlag = true)
|
||||
@ElementCollection
|
||||
@JoinTable(name = "PartialModFlags_StrSet")
|
||||
@AuditJoinTable(name = "PartialModFlags_StrSet_AUD")
|
||||
private Set<String> stringSet = new HashSet<String>();
|
||||
|
||||
@Audited(withModifiedFlag = true)
|
||||
|
@ -81,6 +87,8 @@ public class PartialModifiedFlagsEntity {
|
|||
@Audited(withModifiedFlag = true)
|
||||
@ElementCollection
|
||||
@MapKeyColumn(nullable=false)
|
||||
@JoinTable(name = "PartialModFlags_StrMap")
|
||||
@AuditJoinTable(name = "PartialModFlags_StrMap_AUD")
|
||||
private Map<String, String> stringMap = new HashMap<String, String>();
|
||||
|
||||
@Audited(withModifiedFlag = true)
|
||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.envers.test.integration.modifiedflags.entities;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
|
@ -33,6 +34,7 @@ import org.hibernate.envers.Audited;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "WithModFlagRefIng")
|
||||
@Audited(withModifiedFlag = true)
|
||||
public class WithModifiedFlagReferencingEntity {
|
||||
@Id
|
||||
|
|
|
@ -24,10 +24,8 @@
|
|||
package org.hibernate.envers.test.integration.query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -48,10 +46,6 @@ public class CustomRevEntityQuery extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrIntTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,10 @@ package org.hibernate.envers.test.integration.query;
|
|||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.OracleRevisionEntity;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.enhanced.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
|
@ -97,11 +95,7 @@ public class DeletedEntities extends AbstractEntityTest {
|
|||
assert result.size() == 1;
|
||||
|
||||
assert ((Object []) result.get(0))[0].equals(new StrIntTestEntity("b", 11, id2));
|
||||
if (getDialect() instanceof Oracle8iDialect) {
|
||||
assert ((OracleRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
|
||||
} else {
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
|
||||
}
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
|
||||
assert ((Object []) result.get(0))[2].equals(RevisionType.ADD);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,13 +28,11 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.OracleRevisionEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.enhanced.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
|
@ -220,15 +218,9 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
assert ((Object []) result.get(1))[0].equals(new StrIntTestEntity("c", 10, id1));
|
||||
assert ((Object []) result.get(2))[0].equals(new StrIntTestEntity(null, null, id1));
|
||||
|
||||
if (getDialect() instanceof Oracle8iDialect) {
|
||||
assert ((OracleRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
|
||||
assert ((OracleRevisionEntity) ((Object []) result.get(1))[1]).getId() == 2;
|
||||
assert ((OracleRevisionEntity) ((Object []) result.get(2))[1]).getId() == 4;
|
||||
} else {
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(1))[1]).getId() == 2;
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(2))[1]).getId() == 4;
|
||||
}
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(1))[1]).getId() == 2;
|
||||
assert ((DefaultRevisionEntity) ((Object []) result.get(2))[1]).getId() == 4;
|
||||
|
||||
assert ((Object []) result.get(0))[2].equals(RevisionType.ADD);
|
||||
assert ((Object []) result.get(1))[2].equals(RevisionType.MOD);
|
||||
|
|
|
@ -28,10 +28,8 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -53,10 +51,6 @@ public class Custom extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,10 +28,8 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -52,10 +50,6 @@ public class CustomBoxed extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomBoxedRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,8 @@ package org.hibernate.envers.test.integration.reventity;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -52,10 +50,6 @@ public class CustomColumnMapping extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomRevEntityColumnMapping.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,8 @@ package org.hibernate.envers.test.integration.reventity;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -50,10 +48,6 @@ public class CustomDate extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomDateRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,8 @@
|
|||
package org.hibernate.envers.test.integration.reventity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -45,10 +43,6 @@ public class CustomNoListener extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomDataRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,8 @@ package org.hibernate.envers.test.integration.reventity;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -50,10 +48,6 @@ public class CustomPropertyAccess extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomPropertyAccessRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class DifferentDBSchemaTest extends AbstractEntityTest {
|
|||
|
||||
@Test
|
||||
public void testRevinfoSchemaName() {
|
||||
Table revisionTable = getCfg().getClassMapping("org.hibernate.envers.DefaultRevisionEntity").getTable();
|
||||
Table revisionTable = getCfg().getClassMapping("org.hibernate.envers.enhanced.DefaultRevisionEntity").getTable();
|
||||
assert SCHEMA_NAME.equals(revisionTable.getSchema());
|
||||
}
|
||||
|
||||
|
|
|
@ -25,25 +25,18 @@ package org.hibernate.envers.test.integration.reventity;
|
|||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class ExceptionListener extends AbstractEntityTest {
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(ExceptionListenerRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,12 +28,8 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.OracleRevisionEntity;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -54,15 +50,7 @@ public class Inherited extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
if (dialect instanceof Oracle8iDialect) {
|
||||
cfg.addAnnotatedClass(OracleRevisionEntity.class);
|
||||
} else {
|
||||
cfg.addAnnotatedClass(InheritedRevEntity.class);
|
||||
}
|
||||
cfg.addAnnotatedClass(InheritedRevEntity.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,13 +113,11 @@ public class Inherited extends AbstractEntityTest {
|
|||
public void testFindRevision() {
|
||||
AuditReader vr = getAuditReader();
|
||||
|
||||
long rev1Timestamp = getDialect() instanceof Oracle8iDialect ? vr.findRevision(OracleRevisionEntity.class, 1).getTimestamp()
|
||||
: vr.findRevision(InheritedRevEntity.class, 1).getTimestamp();
|
||||
long rev1Timestamp = vr.findRevision(InheritedRevEntity.class, 1).getTimestamp();
|
||||
assert rev1Timestamp > timestamp1;
|
||||
assert rev1Timestamp <= timestamp2;
|
||||
|
||||
long rev2Timestamp = getDialect() instanceof Oracle8iDialect ? vr.findRevision(OracleRevisionEntity.class, 2).getTimestamp()
|
||||
: vr.findRevision(InheritedRevEntity.class, 2).getTimestamp();
|
||||
long rev2Timestamp = vr.findRevision(InheritedRevEntity.class, 2).getTimestamp();
|
||||
assert rev2Timestamp > timestamp2;
|
||||
assert rev2Timestamp <= timestamp3;
|
||||
}
|
||||
|
@ -144,12 +130,10 @@ public class Inherited extends AbstractEntityTest {
|
|||
revNumbers.add(1);
|
||||
revNumbers.add(2);
|
||||
|
||||
Class<?> revisionClass = getDialect() instanceof Oracle8iDialect ? OracleRevisionEntity.class
|
||||
: InheritedRevEntity.class;
|
||||
Map revisionMap = vr.findRevisions(revisionClass, revNumbers);
|
||||
Map revisionMap = vr.findRevisions(InheritedRevEntity.class, revNumbers);
|
||||
assert(revisionMap.size() == 2);
|
||||
assert(revisionMap.get(1).equals(vr.findRevision(revisionClass, 1)));
|
||||
assert(revisionMap.get(2).equals(vr.findRevision(revisionClass, 2)));
|
||||
assert(revisionMap.get(1).equals(vr.findRevision(InheritedRevEntity.class, 1)));
|
||||
assert(revisionMap.get(2).equals(vr.findRevision(InheritedRevEntity.class, 2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
package org.hibernate.envers.test.integration.reventity;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.enhanced.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.RevisionEntity;
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,10 +28,8 @@ import java.util.Date;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -52,10 +50,6 @@ public class Listener extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(ListenerRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,7 @@
|
|||
package org.hibernate.envers.test.integration.reventity;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -47,10 +45,6 @@ public class LongRevEntityInheritanceChildAuditing extends AbstractEntityTest {
|
|||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(ChildEntity.class);
|
||||
cfg.addAnnotatedClass(ParentEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(LongRevNumberRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,8 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -47,10 +45,6 @@ public class LongRevNumber extends AbstractEntityTest {
|
|||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(LongRevNumberRevEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
package org.hibernate.envers.test.integration.reventity;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6696")
|
||||
public class OverrideCustomRevListenerTest extends GloballyConfiguredRevListenerTest {
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
super.configure(cfg);
|
||||
cfg.addAnnotatedClass(ListenerRevEntity.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
package org.hibernate.envers.test.integration.reventity;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6696")
|
||||
public class OverrideDefaultRevListenerTest extends GloballyConfiguredRevListenerTest {
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
super.configure(cfg);
|
||||
cfg.addAnnotatedClass(LongRevNumberRevEntity.class);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.ModifiedEntityNames;
|
||||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.AnnotatedTrackingRevisionEntity;
|
||||
|
@ -13,7 +12,8 @@ import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.Annota
|
|||
*/
|
||||
public class AnnotatedTrackingEntitiesTest extends DefaultTrackingEntitiesTest {
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
super.configure(cfg);
|
||||
cfg.addAnnotatedClass(AnnotatedTrackingRevisionEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities;
|
|||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
@ -17,7 +16,6 @@ import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.Custom
|
|||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.ModifiedEntityTypeEntity;
|
||||
import org.hibernate.envers.test.tools.TestTools;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Tests proper behavior of entity listener that implements {@link EntityTrackingRevisionListener}
|
||||
|
@ -34,10 +32,6 @@ public class CustomTrackingEntitiesTest extends AbstractEntityTest {
|
|||
cfg.addAnnotatedClass(ModifiedEntityTypeEntity.class);
|
||||
cfg.addAnnotatedClass(StrTestEntity.class);
|
||||
cfg.addAnnotatedClass(StrIntTestEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
cfg.addAnnotatedClass(CustomTrackingRevisionEntity.class);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,6 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.OracleTrackingModifiedEntitiesRevisionEntity;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package org.hibernate.envers.test.integration.reventity.trackmodifiedentities;
|
||||
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.AbstractSessionTest;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.OracleTrackingModifiedEntitiesRevisionEntity;
|
||||
import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Car;
|
||||
import org.hibernate.envers.test.integration.entityNames.manyToManyAudited.Person;
|
||||
import org.hibernate.envers.test.tools.TestTools;
|
||||
|
|
|
@ -2,12 +2,6 @@ package org.hibernate.envers.test.integration.reventity.trackmodifiedentities;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.OracleExtendedRevisionEntity;
|
||||
import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.OracleExtendedRevisionListener;
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -22,12 +16,9 @@ import org.hibernate.envers.test.entities.reventity.trackmodifiedentities.Extend
|
|||
*/
|
||||
public class ExtendedRevisionEntityTest extends DefaultTrackingEntitiesTest {
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
if (dialect instanceof Oracle8iDialect) {
|
||||
cfg.addAnnotatedClass(OracleExtendedRevisionEntity.class);
|
||||
} else {
|
||||
cfg.addAnnotatedClass(ExtendedRevisionEntity.class);
|
||||
}
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
super.configure(cfg);
|
||||
cfg.addAnnotatedClass(ExtendedRevisionEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,18 +28,9 @@ public class ExtendedRevisionEntityTest extends DefaultTrackingEntitiesTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SkipForDialect(Oracle8iDialect.class)
|
||||
public void testCommentPropertyValue() {
|
||||
ExtendedRevisionEntity ere = getAuditReader().findRevision(ExtendedRevisionEntity.class, 1);
|
||||
|
||||
Assert.assertEquals(ExtendedRevisionListener.COMMENT_VALUE, ere.getComment());
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresDialect(Oracle8iDialect.class)
|
||||
public void testCommentPropertyValueOracle() {
|
||||
OracleExtendedRevisionEntity ere = getAuditReader().findRevision(OracleExtendedRevisionEntity.class, 1);
|
||||
|
||||
Assert.assertEquals(OracleExtendedRevisionListener.COMMENT_VALUE, ere.getUserComment());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import java.util.Set;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -73,10 +72,6 @@ public class ValidityAuditStrategyRevEndTestCustomRevEnt extends AbstractEntityT
|
|||
cfg.addAnnotatedClass(CustomDateRevEntity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revisionEntityForDialect(Ejb3Configuration cfg, Dialect dialect, Properties configurationProperties) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addConfigurationProperties(Properties configuration) {
|
||||
super.addConfigurationProperties( configuration );
|
||||
|
|
|
@ -34,7 +34,6 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.dialect.Oracle8iDialect;
|
||||
import org.hibernate.envers.test.entities.reventity.OracleRevisionEntity;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -42,7 +41,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.dialect.MySQL5Dialect;
|
||||
import org.hibernate.dialect.SQLServerDialect;
|
||||
import org.hibernate.ejb.Ejb3Configuration;
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.enhanced.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.strategy.ValidityAuditStrategy;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.Priority;
|
||||
|
@ -427,30 +426,20 @@ public class ValidityAuditStrategyRevEndTsTest extends AbstractEntityTest {
|
|||
return resultList;
|
||||
}
|
||||
|
||||
private void verifyRevEndTimeStamps(String debugInfo,
|
||||
List<Map<String, Object>> revisionEntities) {
|
||||
private void verifyRevEndTimeStamps(String debugInfo, List<Map<String, Object>> revisionEntities) {
|
||||
for (Map<String, Object> revisionEntity : revisionEntities) {
|
||||
|
||||
Date revendTimestamp = (Date) revisionEntity.get(revendTimestampColumName);
|
||||
if (getDialect() instanceof Oracle8iDialect) {
|
||||
OracleRevisionEntity revEnd = (OracleRevisionEntity) revisionEntity.get("REVEND");
|
||||
if (revendTimestamp == null) {
|
||||
Assert.assertNull(revEnd);
|
||||
DefaultRevisionEntity revEnd = (DefaultRevisionEntity) revisionEntity.get("REVEND");
|
||||
|
||||
if (revendTimestamp == null) {
|
||||
Assert.assertNull(revEnd);
|
||||
} else {
|
||||
if (getDialect() instanceof MySQL5Dialect) {
|
||||
// MySQL5 DATETIME column type does not contain milliseconds.
|
||||
Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)));
|
||||
} else {
|
||||
Assert.assertEquals(revendTimestamp.getTime(), revEnd.getTimestamp());
|
||||
}
|
||||
} else {
|
||||
DefaultRevisionEntity revEnd = (DefaultRevisionEntity) revisionEntity.get("REVEND");
|
||||
if (revendTimestamp == null) {
|
||||
Assert.assertNull(revEnd);
|
||||
} else {
|
||||
if (getDialect() instanceof MySQL5Dialect) {
|
||||
// MySQL5 DATETIME column type does not contain milliseconds.
|
||||
Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)));
|
||||
} else {
|
||||
Assert.assertEquals(revendTimestamp.getTime(), revEnd.getTimestamp());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,11 @@ public class SchemaExportTest extends AbstractSessionTest {
|
|||
@Override
|
||||
protected void initMappings() throws MappingException, URISyntaxException {
|
||||
config.addAnnotatedClass(StrTestEntity.class);
|
||||
// Disable schema auto generation.
|
||||
config.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
|
||||
config.setProperty("org.hibernate.envers.use_enhanced_revision_entity", "true");
|
||||
}
|
||||
protected boolean createSchema() {
|
||||
// Disable schema auto generation.
|
||||
return false;
|
||||
}
|
||||
@Test
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.hibernate.Session;
|
|||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.enhanced.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.test.AbstractSessionTest;
|
||||
import org.hibernate.envers.test.entities.StrTestEntity;
|
||||
import org.hibernate.envers.test.entities.onetomany.SetRefEdEntity;
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.enhanced.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.configuration.GlobalConfiguration;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
|
|
Loading…
Reference in New Issue