org.hibernate.envers.internal.entities.mapper.relation.ListCollectionMapper Maven / Gradle / Ivy
/*
* 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.Collection;
import java.util.List;
import java.util.Map;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.envers.boot.internal.EnversService;
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.ListCollectionInitializor;
import org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.ListProxy;
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
import org.hibernate.envers.internal.tools.Tools;
import org.hibernate.envers.tools.Pair;
/**
* @author Adam Warski (adam at warski dot org)
*/
public final class ListCollectionMapper extends AbstractCollectionMapper implements PropertyMapper {
private final MiddleComponentData elementComponentData;
private final MiddleComponentData indexComponentData;
public ListCollectionMapper(
CommonCollectionMapperData commonCollectionMapperData,
MiddleComponentData elementComponentData, MiddleComponentData indexComponentData,
boolean revisionTypeInId) {
super( commonCollectionMapperData, List.class, ListProxy.class, false, revisionTypeInId );
this.elementComponentData = elementComponentData;
this.indexComponentData = indexComponentData;
}
@Override
protected Initializor getInitializor(
EnversService enversService,
AuditReaderImplementor versionsReader,
Object primaryKey,
Number revision,
boolean removed) {
return new ListCollectionInitializor(
enversService,
versionsReader,
commonCollectionMapperData.getQueryGenerator(),
primaryKey,
revision,
removed,
elementComponentData,
indexComponentData
);
}
@Override
@SuppressWarnings({"unchecked"})
protected Collection getNewCollectionContent(PersistentCollection newCollection) {
if ( newCollection == null ) {
return null;
}
else {
return Tools.listToIndexElementPairList( (List