Skip to content

Commit 50e3735

Browse files
committed
DATAMONGO-1419 - Removed deprecated methods of AbstractMongoEventListener.
1 parent a15daba commit 50e3735

File tree

4 files changed

+66
-147
lines changed

4 files changed

+66
-147
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/AbstractMongoEventListener.java

Lines changed: 11 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2015 by the original author(s).
2+
* Copyright 2011-2016 by the original author(s).
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,8 +20,6 @@
2020
import org.springframework.context.ApplicationListener;
2121
import org.springframework.core.GenericTypeResolver;
2222

23-
import com.mongodb.DBObject;
24-
2523
/**
2624
* Base class to implement domain class specific {@link ApplicationListener}s.
2725
*
@@ -95,42 +93,16 @@ public void onApplicationEvent(MongoMappingEvent<?> event) {
9593
}
9694
}
9795

98-
/**
99-
* Captures source element before conversion.
100-
*
101-
* @param source will never be {@literal null}.
102-
* @deprecated since 1.8. Please use {@link #onBeforeConvert(BeforeConvertEvent)}.
103-
*/
104-
@Deprecated
105-
public void onBeforeConvert(E source) {
106-
107-
if (LOG.isDebugEnabled()) {
108-
LOG.debug("onBeforeConvert({})", source);
109-
}
110-
}
111-
11296
/**
11397
* Captures {@link BeforeConvertEvent}.
11498
*
11599
* @param event never {@literal null}.
116100
* @since 1.8
117101
*/
118102
public void onBeforeConvert(BeforeConvertEvent<E> event) {
119-
onBeforeConvert(event.getSource());
120-
}
121-
122-
/**
123-
* Captures source element and {@link com.mongodb.DBObject} representation before save.
124-
*
125-
* @param source will never be {@literal null}.
126-
* @param dbo can be {@literal null}.
127-
* @deprecated since 1.8. Please use {@link #onBeforeSave(BeforeSaveEvent)}.
128-
*/
129-
@Deprecated
130-
public void onBeforeSave(E source, DBObject dbo) {
131103

132104
if (LOG.isDebugEnabled()) {
133-
LOG.debug("onBeforeSave({}, {})", source, dbo);
105+
LOG.debug("onBeforeConvert({})", event.getSource());
134106
}
135107
}
136108

@@ -141,21 +113,9 @@ public void onBeforeSave(E source, DBObject dbo) {
141113
* @since 1.8
142114
*/
143115
public void onBeforeSave(BeforeSaveEvent<E> event) {
144-
onBeforeSave(event.getSource(), event.getDBObject());
145-
}
146-
147-
/**
148-
* Captures source element and {@link com.mongodb.DBObject} representation after save.
149-
*
150-
* @param source will never be {@literal null}.
151-
* @param dbo can be {@literal null}.
152-
* @deprecated since 1.8. Please use {@link #onAfterSave(AfterSaveEvent)}.
153-
*/
154-
@Deprecated
155-
public void onAfterSave(E source, DBObject dbo) {
156116

157117
if (LOG.isDebugEnabled()) {
158-
LOG.debug("onAfterSave({}, {})", source, dbo);
118+
LOG.debug("onBeforeSave({}, {})", event.getSource(), event.getDBObject());
159119
}
160120
}
161121

@@ -166,20 +126,9 @@ public void onAfterSave(E source, DBObject dbo) {
166126
* @since 1.8
167127
*/
168128
public void onAfterSave(AfterSaveEvent<E> event) {
169-
onAfterSave(event.getSource(), event.getDBObject());
170-
}
171-
172-
/**
173-
* Captures raw {@link com.mongodb.DBObject} when read from MongoDB.
174-
*
175-
* @param dbo can be {@literal null}.
176-
* @deprecated since 1.8. Please use {@link #onAfterLoad(AfterLoadEvent)}.
177-
*/
178-
@Deprecated
179-
public void onAfterLoad(DBObject dbo) {
180129

181130
if (LOG.isDebugEnabled()) {
182-
LOG.debug("onAfterLoad({})", dbo);
131+
LOG.debug("onAfterSave({}, {})", event.getSource(), event.getDBObject());
183132
}
184133
}
185134

@@ -190,21 +139,9 @@ public void onAfterLoad(DBObject dbo) {
190139
* @since 1.8
191140
*/
192141
public void onAfterLoad(AfterLoadEvent<E> event) {
193-
onAfterLoad(event.getDBObject());
194-
}
195-
196-
/**
197-
* Captures raw {@link com.mongodb.DBObject} and converted domain type after conversion.
198-
*
199-
* @param dbo can be {@literal null}.
200-
* @param source will never be {@literal null}.
201-
* @deprecated since 1.8. Please use {@link #onAfterConvert(AfterConvertEvent)}.
202-
*/
203-
@Deprecated
204-
public void onAfterConvert(DBObject dbo, E source) {
205142

206143
if (LOG.isDebugEnabled()) {
207-
LOG.debug("onAfterConvert({}, {})", dbo, source);
144+
LOG.debug("onAfterLoad({})", event.getDBObject());
208145
}
209146
}
210147

@@ -215,21 +152,9 @@ public void onAfterConvert(DBObject dbo, E source) {
215152
* @since 1.8
216153
*/
217154
public void onAfterConvert(AfterConvertEvent<E> event) {
218-
onAfterConvert(event.getDBObject(), event.getSource());
219-
220-
}
221-
222-
/**
223-
* Captures {@link com.mongodb.DBObject} after delete.
224-
*
225-
* @param dbo can be {@literal null}.
226-
* @deprecated since 1.8. Please use {@link #onAfterDelete(AfterDeleteEvent)}.
227-
*/
228-
@Deprecated
229-
public void onAfterDelete(DBObject dbo) {
230155

231156
if (LOG.isDebugEnabled()) {
232-
LOG.debug("onAfterDelete({})", dbo);
157+
LOG.debug("onAfterConvert({}, {})", event.getDBObject(), event.getSource());
233158
}
234159
}
235160

@@ -240,20 +165,9 @@ public void onAfterDelete(DBObject dbo) {
240165
* @since 1.8
241166
*/
242167
public void onAfterDelete(AfterDeleteEvent<E> event) {
243-
onAfterDelete(event.getDBObject());
244-
}
245-
246-
/**
247-
* Capture {@link com.mongodb.DBObject} before delete.
248-
*
249-
* @param dbo can be {@literal null}.
250-
* @deprecated since 1.8. Please use {@link #onBeforeDelete(BeforeDeleteEvent)}.
251-
*/
252-
@Deprecated
253-
public void onBeforeDelete(DBObject dbo) {
254168

255169
if (LOG.isDebugEnabled()) {
256-
LOG.debug("onBeforeDelete({})", dbo);
170+
LOG.debug("onAfterDelete({})", event.getDBObject());
257171
}
258172
}
259173

@@ -264,6 +178,9 @@ public void onBeforeDelete(DBObject dbo) {
264178
* @since 1.8
265179
*/
266180
public void onBeforeDelete(BeforeDeleteEvent<E> event) {
267-
onBeforeDelete(event.getDBObject());
181+
182+
if (LOG.isDebugEnabled()) {
183+
LOG.debug("onBeforeDelete({})", event.getDBObject());
184+
}
268185
}
269186
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,78 +19,77 @@
1919
import org.slf4j.LoggerFactory;
2020
import org.springframework.context.ApplicationListener;
2121

22-
import com.mongodb.DBObject;
23-
2422
/**
2523
* {@link ApplicationListener} for Mongo mapping events logging the events.
2624
*
2725
* @author Jon Brisbin
2826
* @author Martin Baumgartner
27+
* @author Oliver Gierke
2928
*/
3029
public class LoggingEventListener extends AbstractMongoEventListener<Object> {
3130

3231
private static final Logger LOGGER = LoggerFactory.getLogger(LoggingEventListener.class);
3332

34-
/*
33+
/*
3534
* (non-Javadoc)
36-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeConvert(java.lang.Object)
35+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeConvert(org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent)
3736
*/
3837
@Override
39-
public void onBeforeConvert(Object source) {
40-
LOGGER.info("onBeforeConvert: {}", source);
38+
public void onBeforeConvert(BeforeConvertEvent<Object> event) {
39+
LOGGER.info("onBeforeConvert: {}", event.getSource());
4140
}
4241

43-
/*
42+
/*
4443
* (non-Javadoc)
45-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(java.lang.Object, com.mongodb.DBObject)
44+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent)
4645
*/
4746
@Override
48-
public void onBeforeSave(Object source, DBObject dbo) {
49-
LOGGER.info("onBeforeSave: {}, {}", source, dbo);
47+
public void onBeforeSave(BeforeSaveEvent<Object> event) {
48+
LOGGER.info("onBeforeSave: {}, {}", event.getSource(), event.getDBObject());
5049
}
5150

52-
/*
51+
/*
5352
* (non-Javadoc)
54-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterSave(java.lang.Object, com.mongodb.DBObject)
53+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterSave(org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent)
5554
*/
5655
@Override
57-
public void onAfterSave(Object source, DBObject dbo) {
58-
LOGGER.info("onAfterSave: {}, {}", source, dbo);
56+
public void onAfterSave(AfterSaveEvent<Object> event) {
57+
LOGGER.info("onAfterSave: {}, {}", event.getSource(), event.getDBObject());
5958
}
6059

61-
/*
60+
/*
6261
* (non-Javadoc)
63-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterLoad(com.mongodb.DBObject)
62+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterLoad(org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent)
6463
*/
6564
@Override
66-
public void onAfterLoad(DBObject dbo) {
67-
LOGGER.info("onAfterLoad: {}", dbo);
65+
public void onAfterLoad(AfterLoadEvent<Object> event) {
66+
LOGGER.info("onAfterLoad: {}", event.getDBObject());
6867
}
6968

70-
/*
69+
/*
7170
* (non-Javadoc)
72-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterConvert(com.mongodb.DBObject, java.lang.Object)
71+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterConvert(org.springframework.data.mongodb.core.mapping.event.AfterConvertEvent)
7372
*/
7473
@Override
75-
public void onAfterConvert(DBObject dbo, Object source) {
76-
LOGGER.info("onAfterConvert: {}, {}", dbo, source);
74+
public void onAfterConvert(AfterConvertEvent<Object> event) {
75+
LOGGER.info("onAfterConvert: {}, {}", event.getDBObject(), event.getSource());
7776
}
7877

79-
/*
78+
/*
8079
* (non-Javadoc)
81-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterDelete(com.mongodb.DBObject)
80+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onAfterDelete(org.springframework.data.mongodb.core.mapping.event.AfterDeleteEvent)
8281
*/
8382
@Override
84-
public void onAfterDelete(DBObject dbo) {
85-
LOGGER.info("onAfterDelete: {}", dbo);
83+
public void onAfterDelete(AfterDeleteEvent<Object> event) {
84+
LOGGER.info("onAfterDelete: {}", event.getDBObject());
8685
}
8786

88-
/*
87+
/*
8988
* (non-Javadoc)
90-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeDelete(com.mongodb.DBObject)
89+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeDelete(org.springframework.data.mongodb.core.mapping.event.BeforeDeleteEvent)
9190
*/
9291
@Override
93-
public void onBeforeDelete(DBObject dbo) {
94-
LOGGER.info("onBeforeDelete: {}", dbo);
92+
public void onBeforeDelete(BeforeDeleteEvent<Object> event) {
93+
LOGGER.info("onBeforeDelete: {}", event.getDBObject());
9594
}
9695
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/event/ValidatingMongoEventListener.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,13 +24,12 @@
2424
import org.slf4j.LoggerFactory;
2525
import org.springframework.util.Assert;
2626

27-
import com.mongodb.DBObject;
28-
2927
/**
3028
* javax.validation dependant entities validator. When it is registered as Spring component its automatically invoked
3129
* before entities are saved in database.
3230
*
3331
* @author Maciej Walkowiak
32+
* @author Oliver Gierke
3433
*/
3534
public class ValidatingMongoEventListener extends AbstractMongoEventListener<Object> {
3635

@@ -44,17 +43,20 @@ public class ValidatingMongoEventListener extends AbstractMongoEventListener<Obj
4443
* @param validator must not be {@literal null}.
4544
*/
4645
public ValidatingMongoEventListener(Validator validator) {
47-
Assert.notNull(validator);
46+
47+
Assert.notNull(validator, "Validator must not be null!");
4848
this.validator = validator;
4949
}
5050

51-
/*
51+
/*
5252
* (non-Javadoc)
53-
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(java.lang.Object, com.mongodb.DBObject)
53+
* @see org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener#onBeforeSave(org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent)
5454
*/
5555
@Override
5656
@SuppressWarnings({ "rawtypes", "unchecked" })
57-
public void onBeforeSave(Object source, DBObject dbo) {
57+
public void onBeforeSave(BeforeSaveEvent<Object> event) {
58+
59+
Object source = event.getSource();
5860

5961
LOG.debug("Validating object: {}", source);
6062
Set violations = validator.validate(source);

0 commit comments

Comments
 (0)