|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright (c) 2011 by the original author(s). |
|
|
|
* Copyright 2011 by the original author(s). |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -27,9 +27,9 @@ import org.springframework.core.GenericTypeResolver; |
|
|
|
* @author Jon Brisbin |
|
|
|
* @author Jon Brisbin |
|
|
|
* @author Oliver Gierke |
|
|
|
* @author Oliver Gierke |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public abstract class AbstractMongoEventListener<E> implements ApplicationListener<MongoMappingEvent<E>> { |
|
|
|
public abstract class AbstractMongoEventListener<E> implements ApplicationListener<MongoMappingEvent<?>> { |
|
|
|
|
|
|
|
|
|
|
|
protected final Log log = LogFactory.getLog(getClass()); |
|
|
|
protected final Log LOG = LogFactory.getLog(getClass()); |
|
|
|
private final Class<?> domainClass; |
|
|
|
private final Class<?> domainClass; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -43,54 +43,59 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen |
|
|
|
* (non-Javadoc) |
|
|
|
* (non-Javadoc) |
|
|
|
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent) |
|
|
|
* @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void onApplicationEvent(MongoMappingEvent<E> event) { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
public void onApplicationEvent(MongoMappingEvent<?> event) { |
|
|
|
|
|
|
|
|
|
|
|
E source = event.getSource(); |
|
|
|
Object source = event.getSource(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Invoke domain type independent events
|
|
|
|
|
|
|
|
if (event instanceof AfterLoadEvent) { |
|
|
|
|
|
|
|
onAfterLoad(((AfterLoadEvent) event).getSource()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check for matching domain type and invoke callbacks
|
|
|
|
if (source != null && !domainClass.isAssignableFrom(source.getClass())) { |
|
|
|
if (source != null && !domainClass.isAssignableFrom(source.getClass())) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (event instanceof BeforeConvertEvent) { |
|
|
|
if (event instanceof BeforeConvertEvent) { |
|
|
|
onBeforeConvert(source); |
|
|
|
onBeforeConvert((E) source); |
|
|
|
} else if (event instanceof BeforeSaveEvent) { |
|
|
|
} else if (event instanceof BeforeSaveEvent) { |
|
|
|
onBeforeSave(source, event.getDBObject()); |
|
|
|
onBeforeSave((E) source, event.getDBObject()); |
|
|
|
} else if (event instanceof AfterSaveEvent) { |
|
|
|
} else if (event instanceof AfterSaveEvent) { |
|
|
|
onAfterSave(source, event.getDBObject()); |
|
|
|
onAfterSave((E) source, event.getDBObject()); |
|
|
|
} else if (event instanceof AfterLoadEvent) { |
|
|
|
|
|
|
|
onAfterLoad((DBObject) event.getSource()); |
|
|
|
|
|
|
|
} else if (event instanceof AfterConvertEvent) { |
|
|
|
} else if (event instanceof AfterConvertEvent) { |
|
|
|
onAfterConvert(event.getDBObject(), source); |
|
|
|
onAfterConvert(event.getDBObject(), (E) source); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onBeforeConvert(E source) { |
|
|
|
public void onBeforeConvert(E source) { |
|
|
|
if (log.isDebugEnabled()) { |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
log.debug("onBeforeConvert(" + source + ")"); |
|
|
|
LOG.debug("onBeforeConvert(" + source + ")"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onBeforeSave(E source, DBObject dbo) { |
|
|
|
public void onBeforeSave(E source, DBObject dbo) { |
|
|
|
if (log.isDebugEnabled()) { |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
log.debug("onBeforeSave(" + source + ", " + dbo + ")"); |
|
|
|
LOG.debug("onBeforeSave(" + source + ", " + dbo + ")"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onAfterSave(E source, DBObject dbo) { |
|
|
|
public void onAfterSave(E source, DBObject dbo) { |
|
|
|
if (log.isDebugEnabled()) { |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
log.debug("onAfterSave(" + source + ", " + dbo + ")"); |
|
|
|
LOG.debug("onAfterSave(" + source + ", " + dbo + ")"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onAfterLoad(DBObject dbo) { |
|
|
|
public void onAfterLoad(DBObject dbo) { |
|
|
|
if (log.isDebugEnabled()) { |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
log.debug("onAfterLoad(" + dbo + ")"); |
|
|
|
LOG.debug("onAfterLoad(" + dbo + ")"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onAfterConvert(DBObject dbo, E source) { |
|
|
|
public void onAfterConvert(DBObject dbo, E source) { |
|
|
|
if (log.isDebugEnabled()) { |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
log.debug("onAfterConvert(" + dbo + "," + source + ")"); |
|
|
|
LOG.debug("onAfterConvert(" + dbo + "," + source + ")"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|