|
Hibernate example source code file (PersistentCollectionChangeWorkUnit.java)
The Hibernate PersistentCollectionChangeWorkUnit.java source code/* * 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.synchronization.work; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hibernate.Session; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.envers.RevisionType; import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.configuration.AuditEntitiesConfiguration; import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData; /** * @author Adam Warski (adam at warski dot org) */ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit implements AuditWorkUnit { private final List<PersistentCollectionChangeData> collectionChanges; private final String referencingPropertyName; public PersistentCollectionChangeWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration auditCfg, PersistentCollection collection, CollectionEntry collectionEntry, Serializable snapshot, Serializable id, String referencingPropertyName) { super(sessionImplementor, entityName, auditCfg, new PersistentCollectionChangeWorkUnitId(id, collectionEntry.getRole()), RevisionType.MOD); this.referencingPropertyName = referencingPropertyName; collectionChanges = auditCfg.getEntCfg().get(getEntityName()).getPropertyMapper() .mapCollectionChanges(referencingPropertyName, collection, snapshot, id); } public PersistentCollectionChangeWorkUnit(SessionImplementor sessionImplementor, String entityName, AuditConfiguration verCfg, Serializable id, List<PersistentCollectionChangeData> collectionChanges, String referencingPropertyName) { super(sessionImplementor, entityName, verCfg, id, RevisionType.MOD); this.collectionChanges = collectionChanges; this.referencingPropertyName = referencingPropertyName; } public boolean containsWork() { return collectionChanges != null && collectionChanges.size() != 0; } public Map<String, Object> generateData(Object revisionData) { throw new UnsupportedOperationException("Cannot generate data for a collection change work unit!"); } @SuppressWarnings({"unchecked"}) public void perform(Session session, Object revisionData) { AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg(); for (PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges) { // Setting the revision number ((Map<String, Object>) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName())) .put(entitiesCfg.getRevisionFieldName(), revisionData); auditStrategy.performCollectionChange(session, verCfg, persistentCollectionChangeData, revisionData); } } public String getReferencingPropertyName() { return referencingPropertyName; } public List<PersistentCollectionChangeData> getCollectionChanges() { return collectionChanges; } public AuditWorkUnit merge(AddWorkUnit second) { return null; } public AuditWorkUnit merge(ModWorkUnit second) { return null; } public AuditWorkUnit merge(DelWorkUnit second) { return null; } public AuditWorkUnit merge(CollectionChangeWorkUnit second) { return null; } public AuditWorkUnit merge(FakeBidirectionalRelationWorkUnit second) { return null; } public AuditWorkUnit dispatch(WorkUnitMergeVisitor first) { if (first instanceof PersistentCollectionChangeWorkUnit) { PersistentCollectionChangeWorkUnit original = (PersistentCollectionChangeWorkUnit) first; // Merging the collection changes in both work units. // First building a map from the ids of the collection-entry-entities from the "second" collection changes, // to the PCCD objects. That way, we will be later able to check if an "original" collection change // should be added, or if it is overshadowed by a new one. Map<Object, PersistentCollectionChangeData> newChangesIdMap = new HashMap Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate PersistentCollectionChangeWorkUnit.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.