Fix for failing tests
This commit is contained in:
parent
9c4b385bdb
commit
313bb01c50
|
@ -270,14 +270,18 @@ public class AuditedPropertiesReader {
|
||||||
if (aud != null) {
|
if (aud != null) {
|
||||||
propertyData.setStore(aud.modStore());
|
propertyData.setStore(aud.modStore());
|
||||||
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
|
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
|
||||||
propertyData.setUsingModifiedFlag(globalCfg.isOverrideUsingModifiedFlag() ?
|
propertyData.setUsingModifiedFlag(checkUsingModifiedFlag(aud));
|
||||||
globalCfg.isUsingModifiedFlag() : aud.usingModifiedFlag());
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean checkUsingModifiedFlag(Audited aud) {
|
||||||
|
return globalCfg.isOverrideUsingModifiedFlag() ?
|
||||||
|
globalCfg.isUsingModifiedFlag() : aud.usingModifiedFlag();
|
||||||
|
}
|
||||||
|
|
||||||
private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
|
private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
|
||||||
AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class);
|
AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class);
|
||||||
if (auditMappedBy != null) {
|
if (auditMappedBy != null) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.hibernate.envers.configuration.GlobalConfiguration;
|
||||||
* Reads the audited properties for components.
|
* Reads the audited properties for components.
|
||||||
*
|
*
|
||||||
* @author Hern&aacut;n Chanfreau
|
* @author Hern&aacut;n Chanfreau
|
||||||
*
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
*/
|
*/
|
||||||
public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
|
public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
|
||||||
if (aud != null) {
|
if (aud != null) {
|
||||||
propertyData.setStore(aud.modStore());
|
propertyData.setStore(aud.modStore());
|
||||||
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
|
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
|
||||||
|
propertyData.setUsingModifiedFlag(checkUsingModifiedFlag(aud));
|
||||||
} else {
|
} else {
|
||||||
propertyData.setStore(ModificationStore.FULL);
|
propertyData.setStore(ModificationStore.FULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
*/
|
*/
|
||||||
public class PropertyAuditingData {
|
public class PropertyAuditingData {
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
@ -109,10 +109,6 @@ public abstract class BaseEnversEventListener implements EnversListener {
|
||||||
HibernateProxy hibernateProxy = (HibernateProxy) value;
|
HibernateProxy hibernateProxy = (HibernateProxy) value;
|
||||||
toEntityName = session.bestGuessEntityName(value);
|
toEntityName = session.bestGuessEntityName(value);
|
||||||
id = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
|
id = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
|
||||||
// MiSk - make sure this is fine
|
|
||||||
value = hibernateProxy.getHibernateLazyInitializer().getImplementation(session);
|
|
||||||
// We've got to initialize the object from the proxy to later read its state.
|
|
||||||
// value = Tools.getTargetFromProxy(session.getFactory(), hibernateProxy);
|
|
||||||
} else {
|
} else {
|
||||||
toEntityName = session.guessEntityName(value);
|
toEntityName = session.guessEntityName(value);
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,13 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.synchronization.work;
|
package org.hibernate.envers.synchronization.work;
|
||||||
|
|
||||||
|
import org.hibernate.Hibernate;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.envers.RevisionType;
|
import org.hibernate.envers.RevisionType;
|
||||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||||
import org.hibernate.envers.configuration.metadata.MetadataTools;
|
import org.hibernate.envers.configuration.metadata.MetadataTools;
|
||||||
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -36,7 +39,7 @@ import java.util.Map;
|
||||||
* @author Michal Skowronek (mskowr at o2 dot pl)
|
* @author Michal Skowronek (mskowr at o2 dot pl)
|
||||||
*/
|
*/
|
||||||
public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit {
|
public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit {
|
||||||
private final Object entity;
|
private Object entity;
|
||||||
private final String collectionPropertyName;
|
private final String collectionPropertyName;
|
||||||
private final Map<String, Object> data = new HashMap<String, Object>();
|
private final Map<String, Object> data = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
@ -46,6 +49,7 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.collectionPropertyName = collectionPropertyName;
|
this.collectionPropertyName = collectionPropertyName;
|
||||||
assert collectionPropertyName != null;
|
assert collectionPropertyName != null;
|
||||||
|
assert entity != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsWork() {
|
public boolean containsWork() {
|
||||||
|
@ -54,6 +58,7 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
|
||||||
|
|
||||||
public Map<String, Object> generateData(Object revisionData) {
|
public Map<String, Object> generateData(Object revisionData) {
|
||||||
fillDataWithId(data, revisionData);
|
fillDataWithId(data, revisionData);
|
||||||
|
resolveProxyIfNeeded();
|
||||||
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
||||||
.mapToMapFromEntity(sessionImplementor, data, entity, null);
|
.mapToMapFromEntity(sessionImplementor, data, entity, null);
|
||||||
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
|
||||||
|
@ -63,6 +68,14 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void resolveProxyIfNeeded() {
|
||||||
|
if (entity instanceof HibernateProxy) {
|
||||||
|
Hibernate.initialize(entity);
|
||||||
|
this.entity = ((HibernateProxy) entity)
|
||||||
|
.getHibernateLazyInitializer().getImplementation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addCollectionModifiedData(Map<String, Object> data) {
|
public void addCollectionModifiedData(Map<String, Object> data) {
|
||||||
String modifiedFlagForCollection = getModifiedFlagPropertyNameForCollection();
|
String modifiedFlagForCollection = getModifiedFlagPropertyNameForCollection();
|
||||||
if(data.containsKey(modifiedFlagForCollection)) {
|
if(data.containsKey(modifiedFlagForCollection)) {
|
||||||
|
|
|
@ -22,22 +22,14 @@
|
||||||
* Boston, MA 02110-1301 USA
|
* Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
package org.hibernate.envers.tools;
|
package org.hibernate.envers.tools;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
import javassist.util.proxy.ProxyFactory;
|
import javassist.util.proxy.ProxyFactory;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
* @author Hern<EFBFBD>n Chanfreau
|
* @author Hern<EFBFBD>n Chanfreau
|
||||||
|
@ -76,28 +68,6 @@ public class Tools {
|
||||||
return session.getEntityPersister(entityName, obj).getIdentifier(obj, session);
|
return session.getEntityPersister(entityName, obj).getIdentifier(obj, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactoryImplementor, HibernateProxy proxy) {
|
|
||||||
if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
|
|
||||||
return proxy.getHibernateLazyInitializer().getImplementation();
|
|
||||||
}
|
|
||||||
|
|
||||||
SessionImplementor sessionImplementor = proxy.getHibernateLazyInitializer().getSession();
|
|
||||||
Session tempSession = sessionImplementor==null
|
|
||||||
? sessionFactoryImplementor.openTemporarySession()
|
|
||||||
: sessionImplementor.getFactory().openTemporarySession();
|
|
||||||
try {
|
|
||||||
Object target = tempSession.get(
|
|
||||||
proxy.getHibernateLazyInitializer().getEntityName(),
|
|
||||||
proxy.getHibernateLazyInitializer().getIdentifier()
|
|
||||||
);
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
tempSession.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param clazz Class wrapped with a proxy or not.
|
* @param clazz Class wrapped with a proxy or not.
|
||||||
* @param <T> Class type.
|
* @param <T> Class type.
|
||||||
|
|
Loading…
Reference in New Issue