Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.jspecify.annotations.NonNull;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -124,9 +126,8 @@ protected void onPersistenceEvent(final AbstractPersistenceEvent event) {
}
}

public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
return PreInsertEvent.class.isAssignableFrom(eventType) ||
PreUpdateEvent.class.isAssignableFrom(eventType);
public boolean supportsEventType(@NonNull Class<? extends ApplicationEvent> eventType) {
return PreInsertEvent.class.isAssignableFrom(eventType) || PreUpdateEvent.class.isAssignableFrom(eventType);
}
Comment on lines +129 to 131

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same finding as on the DomainEventListener copy of this method: Spring 7's SmartApplicationListener.supportsEventType's eventType is documented never null (it's supportsSourceType's sourceType that's @Nullable, not this one). The PR description was wrong about which parameter is nullable — fixed now. @NonNull + fail-fast here is intentional and correct; no code change needed.


public boolean beforeInsert(PersistentEntity entity, EntityAccess ea) {
Expand Down Expand Up @@ -341,21 +342,21 @@ private static void runWithAllDisabled(final ThreadLocal<DisabledTimestamps> dis
}
}

private static void runWithDisabled(final ThreadLocal<DisabledTimestamps> disabledTimestamps, final List<Class> classes, final Runnable runnable) {
private static void runWithDisabled(final ThreadLocal<DisabledTimestamps> disabledTimestamps, final List<Class<?>> classes, final Runnable runnable) {
// only the names this scope newly disables may be re-enabled on exit; a name already
// disabled by an enclosing scope on this thread must survive this scope's finally
List<String> added = new ArrayList<>(classes.size());
DisabledTimestamps disabled = getOrCreateDisabled(disabledTimestamps);
try {
for (Class clazz : classes) {
for (Class<?> clazz : classes) {
String entityName = clazz.getName();
if (disabled.entityNames.add(entityName)) {
added.add(entityName);
}
}
runnable.run();
} finally {
disabled.entityNames.removeAll(added);
added.forEach(disabled.entityNames::remove);
removeIfEmpty(disabledTimestamps, disabled);
}
}
Expand All @@ -379,7 +380,7 @@ public void withoutLastUpdated(final Runnable runnable) {
* @param classes Which classes to disable the last updated processing for
* @param runnable The code to execute while the last updated listener is disabled
*/
public void withoutLastUpdated(final List<Class> classes, final Runnable runnable) {
public void withoutLastUpdated(final List<Class<?>> classes, final Runnable runnable) {
runWithDisabled(disabledLastUpdated, classes, runnable);
}

Expand All @@ -391,8 +392,8 @@ public void withoutLastUpdated(final List<Class> classes, final Runnable runnabl
* @param clazz Which class to disable the last updated processing for
* @param runnable The code to execute while the last updated listener is disabled
*/
public void withoutLastUpdated(final Class clazz, final Runnable runnable) {
ArrayList<Class> list = new ArrayList<>(1);
public void withoutLastUpdated(final Class<?> clazz, final Runnable runnable) {
ArrayList<Class<?>> list = new ArrayList<>(1);
list.add(clazz);
withoutLastUpdated(list, runnable);
}
Expand All @@ -416,7 +417,7 @@ public void withoutDateCreated(final Runnable runnable) {
* @param classes Which classes to disable the date created processing for
* @param runnable The code to execute while the date created listener is disabled
*/
public void withoutDateCreated(final List<Class> classes, final Runnable runnable) {
public void withoutDateCreated(final List<Class<?>> classes, final Runnable runnable) {
runWithDisabled(disabledDateCreated, classes, runnable);
}

Expand All @@ -428,8 +429,8 @@ public void withoutDateCreated(final List<Class> classes, final Runnable runnabl
* @param clazz Which class to disable the date created processing for
* @param runnable The code to execute while the date created listener is disabled
*/
public void withoutDateCreated(final Class clazz, final Runnable runnable) {
ArrayList<Class> list = new ArrayList<>(1);
public void withoutDateCreated(final Class<?> clazz, final Runnable runnable) {
ArrayList<Class<?>> list = new ArrayList<>(1);
list.add(clazz);
withoutDateCreated(list, runnable);
}
Expand All @@ -453,7 +454,7 @@ public void withoutTimestamps(final Runnable runnable) {
* @param classes Which classes to disable the timestamp processing for
* @param runnable The code to execute while the timestamp listeners are disabled
*/
public void withoutTimestamps(final List<Class> classes, final Runnable runnable) {
public void withoutTimestamps(final List<Class<?>> classes, final Runnable runnable) {
withoutDateCreated(classes, () -> withoutLastUpdated(classes, runnable));
}

Expand All @@ -465,7 +466,7 @@ public void withoutTimestamps(final List<Class> classes, final Runnable runnable
* @param clazz Which class to disable the timestamp processing for
* @param runnable The code to execute while the timestamp listeners are disabled
*/
public void withoutTimestamps(final Class clazz, final Runnable runnable) {
public void withoutTimestamps(final Class<?> clazz, final Runnable runnable) {
withoutDateCreated(clazz, () -> withoutLastUpdated(clazz, runnable));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.grails.datastore.gorm.events

import org.springframework.context.ApplicationEvent
import org.springframework.context.ApplicationEventPublisher
import org.springframework.context.ApplicationListener

Expand All @@ -35,5 +36,5 @@ interface ConfigurableApplicationEventPublisher extends ApplicationEventPublishe
*
* @param listener The application listener
*/
void addApplicationListener(ApplicationListener<?> listener)
void addApplicationListener(ApplicationListener<? extends ApplicationEvent> listener)
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,34 @@ import org.springframework.context.event.SmartApplicationListener
class DefaultApplicationEventPublisher implements ConfigurableApplicationEventPublisher {

private List<ApplicationListener> applicationListeners = []

@Override
void publishEvent(ApplicationEvent event) {
for (listener in applicationListeners) {
if (listener instanceof SmartApplicationListener) {
SmartApplicationListener smartApplicationListener = (SmartApplicationListener) listener
if (!smartApplicationListener.supportsEventType((Class<ApplicationEvent>) event.getClass())) {
continue
}
else if (!smartApplicationListener.supportsSourceType(event.source.getClass())) {
continue
}
}
listener.onApplicationEvent(event)
}
dispatch(event)
}

@Override
void publishEvent(Object event) {
dispatch(new PayloadApplicationEvent<Object>(this, event))
}

private void dispatch(ApplicationEvent event) {
for (listener in applicationListeners) {
def eventObject = new PayloadApplicationEvent<Object>(this, event)
if (listener instanceof SmartApplicationListener) {
SmartApplicationListener smartApplicationListener = (SmartApplicationListener) listener
if (!smartApplicationListener.supportsEventType((Class<ApplicationEvent>) eventObject.getClass())) {
if (!smartApplicationListener.supportsEventType(event.getClass())) {
continue
Comment on lines 52 to 55
}
else if (!smartApplicationListener.supportsSourceType(eventObject.source.getClass())) {
else if (!smartApplicationListener.supportsSourceType(event.source.getClass())) {
continue
}
}

listener.onApplicationEvent(eventObject)
listener.onApplicationEvent(event)
}
}

@Override
void addApplicationListener(ApplicationListener<?> listener) {
void addApplicationListener(ApplicationListener<? extends ApplicationEvent> listener) {
applicationListeners.add(listener)
}
}
Loading
Loading