DATAMONGO-1419 - Removed deprecated methods of AbstractMongoEventListener.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 by the original author(s).
|
||||
* Copyright 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,8 +20,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
/**
|
||||
* Base class to implement domain class specific {@link ApplicationListener}s.
|
||||
*
|
||||
@@ -95,20 +93,6 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures source element before conversion.
|
||||
*
|
||||
* @param source will never be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #onBeforeConvert(BeforeConvertEvent)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onBeforeConvert(E source) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onBeforeConvert({})", source);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures {@link BeforeConvertEvent}.
|
||||
*
|
||||
@@ -116,21 +100,9 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @since 1.8
|
||||
*/
|
||||
public void onBeforeConvert(BeforeConvertEvent<E> event) {
|
||||
onBeforeConvert(event.getSource());
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures source element and {@link com.mongodb.DBObject} representation before save.
|
||||
*
|
||||
* @param source will never be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #onBeforeSave(BeforeSaveEvent)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onBeforeSave(E source, DBObject dbo) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onBeforeSave({}, {})", source, dbo);
|
||||
LOG.debug("onBeforeConvert({})", event.getSource());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,21 +113,9 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @since 1.8
|
||||
*/
|
||||
public void onBeforeSave(BeforeSaveEvent<E> event) {
|
||||
onBeforeSave(event.getSource(), event.getDBObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures source element and {@link com.mongodb.DBObject} representation after save.
|
||||
*
|
||||
* @param source will never be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #onAfterSave(AfterSaveEvent)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onAfterSave(E source, DBObject dbo) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onAfterSave({}, {})", source, dbo);
|
||||
LOG.debug("onBeforeSave({}, {})", event.getSource(), event.getDBObject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,20 +126,9 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @since 1.8
|
||||
*/
|
||||
public void onAfterSave(AfterSaveEvent<E> event) {
|
||||
onAfterSave(event.getSource(), event.getDBObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures raw {@link com.mongodb.DBObject} when read from MongoDB.
|
||||
*
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #onAfterLoad(AfterLoadEvent)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onAfterLoad(DBObject dbo) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onAfterLoad({})", dbo);
|
||||
LOG.debug("onAfterSave({}, {})", event.getSource(), event.getDBObject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,21 +139,9 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @since 1.8
|
||||
*/
|
||||
public void onAfterLoad(AfterLoadEvent<E> event) {
|
||||
onAfterLoad(event.getDBObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures raw {@link com.mongodb.DBObject} and converted domain type after conversion.
|
||||
*
|
||||
* @param dbo can be {@literal null}.
|
||||
* @param source will never be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #onAfterConvert(AfterConvertEvent)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onAfterConvert(DBObject dbo, E source) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onAfterConvert({}, {})", dbo, source);
|
||||
LOG.debug("onAfterLoad({})", event.getDBObject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,21 +152,9 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @since 1.8
|
||||
*/
|
||||
public void onAfterConvert(AfterConvertEvent<E> event) {
|
||||
onAfterConvert(event.getDBObject(), event.getSource());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures {@link com.mongodb.DBObject} after delete.
|
||||
*
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #onAfterDelete(AfterDeleteEvent)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onAfterDelete(DBObject dbo) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onAfterDelete({})", dbo);
|
||||
LOG.debug("onAfterConvert({}, {})", event.getDBObject(), event.getSource());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,20 +165,9 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @since 1.8
|
||||
*/
|
||||
public void onAfterDelete(AfterDeleteEvent<E> event) {
|
||||
onAfterDelete(event.getDBObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture {@link com.mongodb.DBObject} before delete.
|
||||
*
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #onBeforeDelete(BeforeDeleteEvent)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onBeforeDelete(DBObject dbo) {
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onBeforeDelete({})", dbo);
|
||||
LOG.debug("onAfterDelete({})", event.getDBObject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,6 +178,9 @@ public abstract class AbstractMongoEventListener<E> implements ApplicationListen
|
||||
* @since 1.8
|
||||
*/
|
||||
public void onBeforeDelete(BeforeDeleteEvent<E> event) {
|
||||
onBeforeDelete(event.getDBObject());
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("onBeforeDelete({})", event.getDBObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,78 +19,77 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
/**
|
||||
* {@link ApplicationListener} for Mongo mapping events logging the events.
|
||||
*
|
||||
* @author Jon Brisbin
|
||||
* @author Martin Baumgartner
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingEventListener.class);
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeConvert(java.lang.Object)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeConvert(org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onBeforeConvert(Object source) {
|
||||
LOGGER.info("onBeforeConvert: {}", source);
|
||||
public void onBeforeConvert(BeforeConvertEvent<Object> event) {
|
||||
LOGGER.info("onBeforeConvert: {}", event.getSource());
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(java.lang.Object, com.mongodb.DBObject)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onBeforeSave(Object source, DBObject dbo) {
|
||||
LOGGER.info("onBeforeSave: {}, {}", source, dbo);
|
||||
public void onBeforeSave(BeforeSaveEvent<Object> event) {
|
||||
LOGGER.info("onBeforeSave: {}, {}", event.getSource(), event.getDBObject());
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterSave(java.lang.Object, com.mongodb.DBObject)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterSave(org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onAfterSave(Object source, DBObject dbo) {
|
||||
LOGGER.info("onAfterSave: {}, {}", source, dbo);
|
||||
public void onAfterSave(AfterSaveEvent<Object> event) {
|
||||
LOGGER.info("onAfterSave: {}, {}", event.getSource(), event.getDBObject());
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterLoad(com.mongodb.DBObject)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterLoad(org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onAfterLoad(DBObject dbo) {
|
||||
LOGGER.info("onAfterLoad: {}", dbo);
|
||||
public void onAfterLoad(AfterLoadEvent<Object> event) {
|
||||
LOGGER.info("onAfterLoad: {}", event.getDBObject());
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterConvert(com.mongodb.DBObject, java.lang.Object)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterConvert(org.springframework.data.mongodb.core.mapping.event.AfterConvertEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onAfterConvert(DBObject dbo, Object source) {
|
||||
LOGGER.info("onAfterConvert: {}, {}", dbo, source);
|
||||
public void onAfterConvert(AfterConvertEvent<Object> event) {
|
||||
LOGGER.info("onAfterConvert: {}, {}", event.getDBObject(), event.getSource());
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterDelete(com.mongodb.DBObject)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterDelete(org.springframework.data.mongodb.core.mapping.event.AfterDeleteEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onAfterDelete(DBObject dbo) {
|
||||
LOGGER.info("onAfterDelete: {}", dbo);
|
||||
public void onAfterDelete(AfterDeleteEvent<Object> event) {
|
||||
LOGGER.info("onAfterDelete: {}", event.getDBObject());
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeDelete(com.mongodb.DBObject)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeDelete(org.springframework.data.mongodb.core.mapping.event.BeforeDeleteEvent)
|
||||
*/
|
||||
@Override
|
||||
public void onBeforeDelete(DBObject dbo) {
|
||||
LOGGER.info("onBeforeDelete: {}", dbo);
|
||||
public void onBeforeDelete(BeforeDeleteEvent<Object> event) {
|
||||
LOGGER.info("onBeforeDelete: {}", event.getDBObject());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,13 +24,12 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
/**
|
||||
* javax.validation dependant entities validator. When it is registered as Spring component its automatically invoked
|
||||
* before entities are saved in database.
|
||||
*
|
||||
* @author Maciej Walkowiak
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class ValidatingMongoEventListener extends AbstractMongoEventListener<Object> {
|
||||
|
||||
@@ -44,17 +43,20 @@ public class ValidatingMongoEventListener extends AbstractMongoEventListener<Obj
|
||||
* @param validator must not be {@literal null}.
|
||||
*/
|
||||
public ValidatingMongoEventListener(Validator validator) {
|
||||
Assert.notNull(validator);
|
||||
|
||||
Assert.notNull(validator, "Validator must not be null!");
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(java.lang.Object, com.mongodb.DBObject)
|
||||
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void onBeforeSave(Object source, DBObject dbo) {
|
||||
public void onBeforeSave(BeforeSaveEvent<Object> event) {
|
||||
|
||||
Object source = event.getSource();
|
||||
|
||||
LOG.debug("Validating object: {}", source);
|
||||
Set violations = validator.validate(source);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 by the original author(s).
|
||||
* Copyright 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -128,7 +128,7 @@ public class AbstractMongoEventListenerUnitTests {
|
||||
public void handlesUntypedImplementations() {
|
||||
|
||||
UntypedEventListener listener = new UntypedEventListener();
|
||||
listener.onApplicationEvent(new MongoMappingEvent(new Object(), new BasicDBObject()));
|
||||
listener.onApplicationEvent(new MongoMappingEvent(new Object(), new BasicDBObject(), "collection"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +137,8 @@ public class AbstractMongoEventListenerUnitTests {
|
||||
@Test
|
||||
public void invokeContactCallbackForPersonEvent() {
|
||||
|
||||
MongoMappingEvent<DBObject> event = new BeforeDeleteEvent<Person>(new BasicDBObject(), Person.class, "collection-1");
|
||||
MongoMappingEvent<DBObject> event = new BeforeDeleteEvent<Person>(new BasicDBObject(), Person.class,
|
||||
"collection-1");
|
||||
SampleContactEventListener listener = new SampleContactEventListener();
|
||||
listener.onApplicationEvent(event);
|
||||
|
||||
@@ -150,7 +151,8 @@ public class AbstractMongoEventListenerUnitTests {
|
||||
@Test
|
||||
public void invokePersonCallbackForPersonEvent() {
|
||||
|
||||
MongoMappingEvent<DBObject> event = new BeforeDeleteEvent<Person>(new BasicDBObject(), Person.class, "collection-1");
|
||||
MongoMappingEvent<DBObject> event = new BeforeDeleteEvent<Person>(new BasicDBObject(), Person.class,
|
||||
"collection-1");
|
||||
SamplePersonEventListener listener = new SamplePersonEventListener();
|
||||
listener.onApplicationEvent(event);
|
||||
|
||||
@@ -192,22 +194,22 @@ public class AbstractMongoEventListenerUnitTests {
|
||||
boolean invokedOnAfterDelete;
|
||||
|
||||
@Override
|
||||
public void onBeforeConvert(Person source) {
|
||||
public void onBeforeConvert(BeforeConvertEvent<Person> event) {
|
||||
invokedOnBeforeConvert = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterLoad(DBObject dbo) {
|
||||
public void onAfterLoad(AfterLoadEvent<Person> event) {
|
||||
invokedOnAfterLoad = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterDelete(DBObject dbo) {
|
||||
public void onAfterDelete(AfterDeleteEvent<Person> event) {
|
||||
invokedOnAfterDelete = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeDelete(DBObject dbo) {
|
||||
public void onBeforeDelete(BeforeDeleteEvent<Person> event) {
|
||||
invokedOnBeforeDelete = true;
|
||||
}
|
||||
}
|
||||
@@ -220,25 +222,24 @@ public class AbstractMongoEventListenerUnitTests {
|
||||
boolean invokedOnAfterDelete;
|
||||
|
||||
@Override
|
||||
public void onBeforeConvert(Contact source) {
|
||||
public void onBeforeConvert(BeforeConvertEvent<Contact> event) {
|
||||
invokedOnBeforeConvert = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterLoad(DBObject dbo) {
|
||||
public void onAfterLoad(AfterLoadEvent<Contact> event) {
|
||||
invokedOnAfterLoad = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterDelete(DBObject dbo) {
|
||||
public void onAfterDelete(AfterDeleteEvent<Contact> event) {
|
||||
invokedOnAfterDelete = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBeforeDelete(DBObject dbo) {
|
||||
public void onBeforeDelete(BeforeDeleteEvent<Contact> event) {
|
||||
invokedOnBeforeDelete = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SampleAccountEventListener extends AbstractMongoEventListener<Account> {
|
||||
@@ -247,12 +248,12 @@ public class AbstractMongoEventListenerUnitTests {
|
||||
boolean invokedOnAfterLoad;
|
||||
|
||||
@Override
|
||||
public void onBeforeConvert(Account source) {
|
||||
public void onBeforeConvert(BeforeConvertEvent<Account> event) {
|
||||
invokedOnBeforeConvert = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAfterLoad(DBObject dbo) {
|
||||
public void onAfterLoad(AfterLoadEvent<Account> event) {
|
||||
invokedOnAfterLoad = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user