org.hibernate.envers.internal.entities.mapper.relation.MapCollectionMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate-envers Show documentation
Show all versions of hibernate-envers Show documentation
Hibernate's entity version (audit/history) support
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.envers.internal.entities.mapper.relation;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.boot.internal.EnversService;
import org.hibernate.envers.internal.entities.mapper.PersistentCollectionChangeData;
import org.hibernate.envers.internal.entities.mapper.PropertyMapper;
import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.Initializor;
import org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor.MapCollectionInitializor;
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
import org.hibernate.persister.collection.CollectionPersister;
/**
* @author Adam Warski (adam at warski dot org)
* @author Chris Cranford
*/
public class MapCollectionMapper extends AbstractCollectionMapper implements PropertyMapper {
protected final MiddleComponentData elementComponentData;
protected final MiddleComponentData indexComponentData;
public MapCollectionMapper(
CommonCollectionMapperData commonCollectionMapperData,
Class collectionClass, Class proxyClass,
MiddleComponentData elementComponentData, MiddleComponentData indexComponentData,
boolean revisionTypeInId) {
super( commonCollectionMapperData, collectionClass, proxyClass, false, revisionTypeInId );
this.elementComponentData = elementComponentData;
this.indexComponentData = indexComponentData;
}
@Override
protected Initializor getInitializor(
EnversService enversService,
AuditReaderImplementor versionsReader,
Object primaryKey,
Number revision,
boolean removed) {
return new MapCollectionInitializor<>(
enversService,
versionsReader,
commonCollectionMapperData.getQueryGenerator(),
primaryKey,
revision,
removed,
collectionClass,
elementComponentData,
indexComponentData
);
}
@Override
protected Collection getNewCollectionContent(PersistentCollection newCollection) {
if ( newCollection == null ) {
return null;
}
else {
return ( (Map) newCollection ).entrySet();
}
}
@Override
protected Collection getOldCollectionContent(Serializable oldCollection) {
if ( oldCollection == null ) {
return null;
}
else {
return ( (Map) oldCollection ).entrySet();
}
}
@Override
protected void mapToMapFromObject(
SessionImplementor session,
Map idData,
Map data,
Object changed) {
elementComponentData.getComponentMapper().mapToMapFromObject(
session,
idData,
data,
( (Map.Entry) changed ).getValue()
);
indexComponentData.getComponentMapper().mapToMapFromObject(
session,
idData,
data,
( (Map.Entry) changed ).getKey()
);
}
@Override
protected Set