/** * Constructs an AbstractCollectionEvent object. * * @param collection - the collection * @param source - the Session source * @param affectedOwner - the owner that is affected by this event; * can be null if unavailable * @param affectedOwnerId - the ID for the owner that is affected * by this event; can be null if unavailable * that is affected by this event; can be null if unavailable */ public AbstractCollectionEvent( CollectionPersister collectionPersister, PersistentCollection collection, EventSource source, Object affectedOwner, Serializable affectedOwnerId) { super(source); this.collection = collection; this.affectedOwner = affectedOwner; this.affectedOwnerId = affectedOwnerId; this.affectedOwnerEntityName = getAffectedOwnerEntityName( collectionPersister, affectedOwner, source ); }
protected final void onCollectionActionInversed( AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl, CollectionEntry collectionEntry) { if ( shouldGenerateRevision( event ) ) { final String entityName = event.getAffectedOwnerEntityName(); final String ownerEntityName = ( (AbstractCollectionPersister) collectionEntry.getLoadedPersister() ).getOwnerEntityName(); final String referencingPropertyName = collectionEntry.getRole().substring( ownerEntityName.length() + 1 ); final RelationDescription rd = searchForRelationDescription( entityName, referencingPropertyName ); if ( rd != null ) { if ( rd.getRelationType().equals( RelationType.TO_MANY_NOT_OWNING ) && rd.isIndexed() ) { onCollectionAction( event, newColl, oldColl, collectionEntry ); } } } }
protected void checkResult(CollectionListeners listeners, CollectionListeners.Listener listenerExpected, Entity ownerExpected, Collection collExpected, int index) { assertSame( listenerExpected, listeners.getListenersCalled().get( index ) ); assertSame( ownerExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerOrNull() ); assertEquals( ownerExpected.getId(), ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getAffectedOwnerIdOrNull() ); assertEquals( ownerExpected.getClass().getName(), ( (AbstractCollectionEvent) listeners.getEvents().get( index ) ).getAffectedOwnerEntityName() ); assertSame( collExpected, ( ( AbstractCollectionEvent ) listeners.getEvents().get( index ) ).getCollection() ); }
/** * Checks whether modification of not-owned relation field triggers new revision and owner entity is versioned. * * @param event Collection event. * * @return {@code true} if revision based on given event should be generated, {@code false} otherwise. */ protected boolean shouldGenerateRevision(AbstractCollectionEvent event) { final String entityName = event.getAffectedOwnerEntityName(); if ( getEnversService().getEntitiesConfigurations().isVersioned( entityName ) ) { final CollectionEntry collectionEntry = getCollectionEntry( event ); final boolean isInverse = collectionEntry.getLoadedPersister().isInverse(); final boolean isOneToMany = collectionEntry.getLoadedPersister() instanceof OneToManyPersister; if ( isInverse || isOneToMany ) { return getEnversService().getGlobalConfiguration().isGenerateRevisionsForCollections(); } return true; } // if the entity is not audited, we dont generate a revision. return false; }
protected void checkListener( MultipleCollectionListeners listeners, MultipleCollectionListeners.Listener listenerExpected, org.hibernate.test.event.collection.Entity ownerExpected, List<? extends org.hibernate.test.event.collection.Entity> expectedCollectionEntrySnapshot, int index) { AbstractCollectionEvent event = listeners .getEvents().get(index); assertSame(listenerExpected, listeners.getListenersCalled().get(index)); assertEquals(ownerExpected, event.getAffectedOwnerOrNull()); assertEquals(ownerExpected.getId(), event.getAffectedOwnerIdOrNull()); assertEquals(ownerExpected.getClass().getName(), event.getAffectedOwnerEntityName()); if (event instanceof PreCollectionUpdateEvent) { Serializable snapshot = listeners.getSnapshots().get(index); assertEquals(expectedCollectionEntrySnapshot, snapshot); } if (event instanceof PreCollectionRemoveEvent) { Serializable snapshot = listeners.getSnapshots().get(index); assertEquals(expectedCollectionEntrySnapshot, snapshot); } if (event instanceof PostCollectionRecreateEvent) { Serializable snapshot = listeners.getSnapshots().get(index); assertEquals(expectedCollectionEntrySnapshot, snapshot); } }
final String entityName = event.getAffectedOwnerEntityName(); final String ownerEntityName = ( (AbstractCollectionPersister) collectionEntry.getLoadedPersister() ).getOwnerEntityName(); final String referencingPropertyName = collectionEntry.getRole().substring( ownerEntityName.length() + 1 ); new CollectionChangeWorkUnit( event.getSession(), event.getAffectedOwnerEntityName(), referencingPropertyName, getEnversService(),
event.getAffectedOwnerEntityName(), rd.getFromPropertyName(), relatedEntityName
/** * Constructs an AbstractCollectionEvent object. * * @param collectionDescriptor - the collection descriptor * @param collection - the collection * @param source - the Session source * @param affectedOwner - the owner that is affected by this event; * can be null if unavailable * @param affectedOwnerId - the ID for the owner that is affected * by this event; can be null if unavailable */ public AbstractCollectionEvent( PersistentCollectionDescriptor collectionDescriptor, PersistentCollection collection, EventSource source, Object affectedOwner, Object affectedOwnerId) { super( source ); this.collection = collection; this.affectedOwner = affectedOwner; this.affectedOwnerId = affectedOwnerId; this.affectedOwnerEntityName = getAffectedOwnerEntityName( collectionDescriptor, affectedOwner, source ); }
/** * Constructs an AbstractCollectionEvent object. * * @param collection - the collection * @param source - the Session source * @param affectedOwner - the owner that is affected by this event; * can be null if unavailable * @param affectedOwnerId - the ID for the owner that is affected * by this event; can be null if unavailable * that is affected by this event; can be null if unavailable */ public AbstractCollectionEvent( CollectionPersister collectionPersister, PersistentCollection collection, EventSource source, Object affectedOwner, Serializable affectedOwnerId) { super(source); this.collection = collection; this.affectedOwner = affectedOwner; this.affectedOwnerId = affectedOwnerId; this.affectedOwnerEntityName = getAffectedOwnerEntityName( collectionPersister, affectedOwner, source ); }
/** * Constructs an AbstractCollectionEvent object. * * @param collection - the collection * @param source - the Session source * @param affectedOwner - the owner that is affected by this event; * can be null if unavailable * @param affectedOwnerId - the ID for the owner that is affected * by this event; can be null if unavailable * that is affected by this event; can be null if unavailable */ public AbstractCollectionEvent( CollectionPersister collectionPersister, PersistentCollection collection, EventSource source, Object affectedOwner, Serializable affectedOwnerId) { super(source); this.collection = collection; this.affectedOwner = affectedOwner; this.affectedOwnerId = affectedOwnerId; this.affectedOwnerEntityName = getAffectedOwnerEntityName( collectionPersister, affectedOwner, source ); }
protected final void onCollectionActionInversed( AbstractCollectionEvent event, PersistentCollection newColl, Serializable oldColl, CollectionEntry collectionEntry) { if ( shouldGenerateRevision( event ) ) { final String entityName = event.getAffectedOwnerEntityName(); final String referencingPropertyName = resolveReferencingPropertyName( collectionEntry ); final RelationDescription rd = searchForRelationDescription( entityName, referencingPropertyName ); if ( rd != null ) { if ( rd.getRelationType().equals( RelationType.TO_MANY_NOT_OWNING ) && rd.isIndexed() ) { onCollectionAction( event, newColl, oldColl, collectionEntry ); } } } }
/** * Checks whether modification of not-owned relation field triggers new revision and owner entity is versioned. * * @param event Collection event. * * @return {@code true} if revision based on given event should be generated, {@code false} otherwise. */ protected boolean shouldGenerateRevision(AbstractCollectionEvent event) { final String entityName = event.getAffectedOwnerEntityName(); if ( getAuditService().getEntityBindings().isVersioned( entityName ) ) { final CollectionEntry collectionEntry = getCollectionEntry( event ); if ( isInverse( collectionEntry ) || isOneToMany( collectionEntry ) ) { return getAuditService().getOptions().isRevisionOnCollectionChangeEnabled(); } return true; } // if this entity is not audited, we do not generate a revision. return false; }
protected void processCollectionEvent(AbstractCollectionEvent event) { if ( state.eventsDisabled() ) { return; } Object entity = event.getAffectedOwnerOrNull(); if ( entity == null ) { //Hibernate cannot determine every single time the owner especially in case detached objects are involved // or property-ref is used //Should log really but we don't know if we're interested in this collection for indexing return; } PersistentCollection persistentCollection = event.getCollection(); final String collectionRole; if ( persistentCollection != null ) { collectionRole = persistentCollection.getRole(); } else { collectionRole = null; } AbstractDocumentBuilder documentBuilder = getDocumentBuilder( entity ); if ( documentBuilder != null && documentBuilder.collectionChangeRequiresIndexUpdate( collectionRole ) ) { Serializable id = getId( entity, event ); if ( id == null ) { log.idCannotBeExtracted( event.getAffectedOwnerEntityName() ); return; } processWork( tenantIdentifier( event ), entity, id, WorkType.COLLECTION, event, false ); } }
event.getAffectedOwnerEntityName(), rd.getFromPropertyName(), relatedEntityName
final String entityName = event.getAffectedOwnerEntityName(); final String referencingPropertyName = resolveReferencingPropertyName( collectionEntry ); new CollectionChangeWorkUnit( event.getSession(), event.getAffectedOwnerEntityName(), referencingPropertyName, getAuditService(),