Fix for failing tests

This commit is contained in:
Michal Skowronek 2011-08-24 16:12:15 +02:00
parent 9c4b385bdb
commit 313bb01c50
6 changed files with 26 additions and 41 deletions

View File

@ -270,15 +270,19 @@ public class AuditedPropertiesReader {
if (aud != null) {
propertyData.setStore(aud.modStore());
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
propertyData.setUsingModifiedFlag(globalCfg.isOverrideUsingModifiedFlag() ?
globalCfg.isUsingModifiedFlag() : aud.usingModifiedFlag());
propertyData.setUsingModifiedFlag(checkUsingModifiedFlag(aud));
return true;
} else {
return false;
}
}
private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
protected boolean checkUsingModifiedFlag(Audited aud) {
return globalCfg.isOverrideUsingModifiedFlag() ?
globalCfg.isUsingModifiedFlag() : aud.usingModifiedFlag();
}
private void setPropertyAuditMappedBy(XProperty property, PropertyAuditingData propertyData) {
AuditMappedBy auditMappedBy = property.getAnnotation(AuditMappedBy.class);
if (auditMappedBy != null) {
propertyData.setAuditMappedBy(auditMappedBy.mappedBy());

View File

@ -9,7 +9,7 @@ import org.hibernate.envers.configuration.GlobalConfiguration;
* Reads the audited properties for components.
*
* @author Hern&aacut;n Chanfreau
*
* @author Michal Skowronek (mskowr at o2 dot pl)
*/
public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
@ -30,6 +30,7 @@ public class ComponentAuditedPropertiesReader extends AuditedPropertiesReader {
if (aud != null) {
propertyData.setStore(aud.modStore());
propertyData.setRelationTargetAuditMode(aud.targetAuditMode());
propertyData.setUsingModifiedFlag(checkUsingModifiedFlag(aud));
} else {
propertyData.setStore(ModificationStore.FULL);
}

View File

@ -32,6 +32,7 @@ import java.util.List;
/**
* @author Adam Warski (adam at warski dot org)
* @author Michal Skowronek (mskowr at o2 dot pl)
*/
public class PropertyAuditingData {
private String name;

View File

@ -109,10 +109,6 @@ public abstract class BaseEnversEventListener implements EnversListener {
HibernateProxy hibernateProxy = (HibernateProxy) value;
toEntityName = session.bestGuessEntityName(value);
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 {
toEntityName = session.guessEntityName(value);

View File

@ -22,10 +22,13 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.envers.synchronization.work;
import org.hibernate.Hibernate;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.configuration.metadata.MetadataTools;
import org.hibernate.proxy.HibernateProxy;
import java.io.Serializable;
import java.util.HashMap;
@ -36,7 +39,7 @@ import java.util.Map;
* @author Michal Skowronek (mskowr at o2 dot pl)
*/
public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit {
private final Object entity;
private Object entity;
private final String collectionPropertyName;
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.collectionPropertyName = collectionPropertyName;
assert collectionPropertyName != null;
assert entity != null;
}
public boolean containsWork() {
@ -54,6 +58,7 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
public Map<String, Object> generateData(Object revisionData) {
fillDataWithId(data, revisionData);
resolveProxyIfNeeded();
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
.mapToMapFromEntity(sessionImplementor, data, entity, null);
verCfg.getEntCfg().get(getEntityName()).getPropertyMapper()
@ -63,6 +68,14 @@ public class CollectionChangeWorkUnit extends AbstractAuditWorkUnit implements A
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) {
String modifiedFlagForCollection = getModifiedFlagPropertyNameForCollection();
if(data.containsKey(modifiedFlagForCollection)) {

View File

@ -22,22 +22,14 @@
* Boston, MA 02110-1301 USA
*/
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 org.hibernate.Session;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
import java.util.*;
/**
* @author Adam Warski (adam at warski dot org)
* @author Hern<EFBFBD>n Chanfreau
@ -76,28 +68,6 @@ public class Tools {
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 <T> Class type.