Skip to content

Commit b954fbb

Browse files
author
Thomas Darimont
committed
DATAKV-91 - Polishing.
General polishing and improved javadoc. Removed type parameter for source from KeyValueEvent. Original pull request: #5.
1 parent 5e969de commit b954fbb

File tree

4 files changed

+47
-53
lines changed

4 files changed

+47
-53
lines changed

src/main/java/org/springframework/data/keyvalue/core/KeyValueAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2015 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.
@@ -103,6 +103,8 @@ public interface KeyValueAdapter extends DisposableBean {
103103
long count(KeyValueQuery<?> query, Serializable keyspace);
104104

105105
/**
106+
* Check if values from the given keyspace are contained in the underlying key-value store.
107+
*
106108
* @param keyspace
107109
* @return true if {@literal keyspace} already present in adapter.
108110
*/

src/main/java/org/springframework/data/keyvalue/core/KeyValueTemplate.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
*
5252
* @author Christoph Strobl
5353
* @author Oliver Gierke
54+
* @author Thomas Darimont
5455
*/
5556
public class KeyValueTemplate implements KeyValueOperations, ApplicationContextAware {
5657

@@ -61,7 +62,7 @@ public class KeyValueTemplate implements KeyValueOperations, ApplicationContextA
6162
private final MappingContext<? extends PersistentEntity<?, ? extends PersistentProperty<?>>, ? extends PersistentProperty<?>> mappingContext;
6263
private final IdentifierGenerator identifierGenerator;
6364
private ApplicationEventPublisher eventPublisher;
64-
private Set<KeyValueEvent.Type> eventTypesToPublish = new HashSet<KeyValueEvent.Type>(4);
65+
private final Set<KeyValueEvent.Type> eventTypesToPublish = new HashSet<KeyValueEvent.Type>(4);
6566
private PersistenceExceptionTranslator exceptionTranslator = DEFAULT_PERSISTENCE_EXCEPTION_TRANSLATOR;
6667

6768
/**
@@ -515,10 +516,13 @@ private RuntimeException resolveExceptionIfPossible(RuntimeException e) {
515516
return translatedException != null ? translatedException : e;
516517
}
517518

518-
private void potentiallyPublishEvent(KeyValueEvent<?> event) {
519+
private void potentiallyPublishEvent(KeyValueEvent event) {
520+
521+
if (eventPublisher == null) {
522+
return;
523+
}
519524

520-
if (eventPublisher != null
521-
&& (eventTypesToPublish.contains(event.getType()) || eventTypesToPublish.contains(KeyValueEvent.Type.ANY))) {
525+
if (eventTypesToPublish.contains(event.getType()) || eventTypesToPublish.contains(KeyValueEvent.Type.ANY)) {
522526
eventPublisher.publishEvent(event);
523527
}
524528
}

src/main/java/org/springframework/data/keyvalue/core/event/KeyValueEvent.java

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
* has been emitted.
2626
*
2727
* @author Christoph Strobl
28+
* @author Thomas Darimont
2829
* @param <T>
2930
*/
30-
public class KeyValueEvent<T> extends ApplicationEvent {
31+
public class KeyValueEvent extends ApplicationEvent {
3132

3233
private static final long serialVersionUID = -7128527253428193044L;
3334

@@ -40,7 +41,8 @@ public enum Type {
4041
private final Serializable id;
4142
private final Object value;
4243

43-
protected KeyValueEvent(T source, Type type, String keyspace, Serializable id, Object value) {
44+
protected KeyValueEvent(Object source, Type type, String keyspace, Serializable id, Object value) {
45+
4446
super(source);
4547
this.type = type;
4648
this.keyspace = keyspace;
@@ -76,102 +78,96 @@ public Object getValue() {
7678
return value;
7779
}
7880

79-
@Override
80-
@SuppressWarnings("unchecked")
81-
public T getSource() {
82-
return (T) super.getSource();
83-
}
84-
8581
@Override
8682
public String toString() {
8783
return "KeyValueEvent [type=" + type + ", keyspace=" + keyspace + ", id=" + id + "]";
8884
}
8985

90-
public static <T> GetEvent<T> beforeGet(T source, String keyspace, Serializable id) {
91-
return new GetEvent<T>(source, Type.BEFORE_GET, keyspace, id, null);
86+
public static GetEvent beforeGet(Object source, String keyspace, Serializable id) {
87+
return new GetEvent(source, Type.BEFORE_GET, keyspace, id, null);
9288
}
9389

94-
public static <T> GetEvent<T> afterGet(T source, String keyspace, Serializable id, Object value) {
95-
return new GetEvent<T>(source, Type.AFTER_GET, keyspace, id, value);
90+
public static GetEvent afterGet(Object source, String keyspace, Serializable id, Object value) {
91+
return new GetEvent(source, Type.AFTER_GET, keyspace, id, value);
9692
}
9793

98-
public static <T> InsertEvent<T> beforeInsert(T source, String keyspace, Serializable id, Object value) {
99-
return new InsertEvent<T>(source, Type.BEFORE_INSERT, keyspace, id, value);
94+
public static InsertEvent beforeInsert(Object source, String keyspace, Serializable id, Object value) {
95+
return new InsertEvent(source, Type.BEFORE_INSERT, keyspace, id, value);
10096
}
10197

102-
public static <T> InsertEvent<T> afterInsert(T source, String keyspace, Serializable id, Object value) {
103-
return new InsertEvent<T>(source, Type.AFTER_INSERT, keyspace, id, value);
98+
public static InsertEvent afterInsert(Object source, String keyspace, Serializable id, Object value) {
99+
return new InsertEvent(source, Type.AFTER_INSERT, keyspace, id, value);
104100
}
105101

106-
public static <T> UpdateEvent<T> beforeUpdate(T source, String keyspace, Serializable id, Object value) {
107-
return new UpdateEvent<T>(source, Type.BEFORE_UPDATE, keyspace, id, value);
102+
public static UpdateEvent beforeUpdate(Object source, String keyspace, Serializable id, Object value) {
103+
return new UpdateEvent(source, Type.BEFORE_UPDATE, keyspace, id, value);
108104
}
109105

110-
public static <T> UpdateEvent<T> afterUpdate(T source, String keyspace, Serializable id, Object value) {
111-
return new UpdateEvent<T>(source, Type.AFTER_UPDATE, keyspace, id, value);
106+
public static UpdateEvent afterUpdate(Object source, String keyspace, Serializable id, Object value) {
107+
return new UpdateEvent(source, Type.AFTER_UPDATE, keyspace, id, value);
112108
}
113109

114-
public static <T> DropKeyspaceEvent<T> beforeDelete(T source, String keyspace) {
115-
return new DropKeyspaceEvent<T>(source, Type.BEFORE_DELETE, keyspace);
110+
public static DropKeyspaceEvent beforeDelete(Object source, String keyspace) {
111+
return new DropKeyspaceEvent(source, Type.BEFORE_DELETE, keyspace);
116112
}
117113

118-
public static <T> DeleteEvent<T> beforeDelete(T source, String keyspace, Serializable id) {
114+
public static DeleteEvent beforeDelete(Object source, String keyspace, Serializable id) {
119115
return beforeDelete(source, keyspace, id, null);
120116
}
121117

122-
public static <T> DeleteEvent<T> beforeDelete(T source, String keyspace, Serializable id, Object value) {
123-
return new DeleteEvent<T>(source, Type.BEFORE_DELETE, keyspace, id, value);
118+
public static DeleteEvent beforeDelete(Object source, String keyspace, Serializable id, Object value) {
119+
return new DeleteEvent(source, Type.BEFORE_DELETE, keyspace, id, value);
124120
}
125121

126-
public static <T> DropKeyspaceEvent<T> afterDelete(T source, String keyspace) {
127-
return new DropKeyspaceEvent<T>(source, Type.AFTER_DELETE, keyspace);
122+
public static DropKeyspaceEvent afterDelete(Object source, String keyspace) {
123+
return new DropKeyspaceEvent(source, Type.AFTER_DELETE, keyspace);
128124
}
129125

130-
public static <T> DeleteEvent<T> afterDelete(T source, String keyspace, Serializable id, Object value) {
131-
return new DeleteEvent<T>(source, Type.AFTER_DELETE, keyspace, id, value);
126+
public static DeleteEvent afterDelete(Object source, String keyspace, Serializable id, Object value) {
127+
return new DeleteEvent(source, Type.AFTER_DELETE, keyspace, id, value);
132128
}
133129

134-
public static class InsertEvent<T> extends KeyValueEvent<T> {
130+
public static class InsertEvent extends KeyValueEvent {
135131

136132
private static final long serialVersionUID = -1;
137133

138-
InsertEvent(T source, Type type, String keyspace, Serializable id, Object value) {
134+
InsertEvent(Object source, Type type, String keyspace, Serializable id, Object value) {
139135
super(source, type, keyspace, id, value);
140136
}
141137
}
142138

143-
public static class UpdateEvent<T> extends KeyValueEvent<T> {
139+
public static class UpdateEvent extends KeyValueEvent {
144140

145141
private static final long serialVersionUID = -1;
146142

147-
UpdateEvent(T source, Type type, String keyspace, Serializable id, Object value) {
143+
UpdateEvent(Object source, Type type, String keyspace, Serializable id, Object value) {
148144
super(source, type, keyspace, id, value);
149145
}
150146
}
151147

152-
public static class DeleteEvent<T> extends KeyValueEvent<T> {
148+
public static class DeleteEvent extends KeyValueEvent {
153149

154150
private static final long serialVersionUID = -1;
155151

156-
DeleteEvent(T source, Type type, String keyspace, Serializable id, Object value) {
152+
DeleteEvent(Object source, Type type, String keyspace, Serializable id, Object value) {
157153
super(source, type, keyspace, id, value);
158154
}
159155
}
160156

161-
public static class DropKeyspaceEvent<T> extends DeleteEvent<T> {
157+
public static class DropKeyspaceEvent extends DeleteEvent {
162158

163159
private static final long serialVersionUID = -1;
164160

165-
DropKeyspaceEvent(T source, Type type, String keyspace) {
161+
DropKeyspaceEvent(Object source, Type type, String keyspace) {
166162
super(source, type, keyspace, null, null);
167163
}
168164
}
169165

170-
public static class GetEvent<T> extends KeyValueEvent<T> {
166+
public static class GetEvent extends KeyValueEvent {
171167

172168
private static final long serialVersionUID = -1;
173169

174-
protected GetEvent(T source, org.springframework.data.keyvalue.core.event.KeyValueEvent.Type type, String keyspace,
170+
protected GetEvent(Object source, Type type, String keyspace,
175171
Serializable id, Object value) {
176172
super(source, type, keyspace, id, value);
177173
}

src/test/java/org/springframework/data/keyvalue/core/KeyValueTemplateUnitTests.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
/**
5959
* @author Christoph Strobl
60+
* @author Thomas Darimont
6061
*/
6162
@RunWith(MockitoJUnitRunner.class)
6263
public class KeyValueTemplateUnitTests {
@@ -464,7 +465,6 @@ public void shouldNotPublishEventWhenNotExplicitlySetForPublication() {
464465
* @see DATAKV-91
465466
*/
466467
@Test
467-
@SuppressWarnings("rawtypes")
468468
public void shouldPublishBeforeInsertEventCorrectly() {
469469

470470
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.BEFORE_INSERT)));
@@ -486,7 +486,6 @@ public void shouldPublishBeforeInsertEventCorrectly() {
486486
* @see DATAKV-91
487487
*/
488488
@Test
489-
@SuppressWarnings("rawtypes")
490489
public void shouldPublishAfterInsertEventCorrectly() {
491490

492491
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.AFTER_INSERT)));
@@ -508,7 +507,6 @@ public void shouldPublishAfterInsertEventCorrectly() {
508507
* @see DATAKV-91
509508
*/
510509
@Test
511-
@SuppressWarnings("rawtypes")
512510
public void shouldPublishBeforeUpdateEventCorrectly() {
513511

514512
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.BEFORE_UPDATE)));
@@ -530,7 +528,6 @@ public void shouldPublishBeforeUpdateEventCorrectly() {
530528
* @see DATAKV-91
531529
*/
532530
@Test
533-
@SuppressWarnings("rawtypes")
534531
public void shouldPublishAfterUpdateEventCorrectly() {
535532

536533
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.AFTER_UPDATE)));
@@ -552,7 +549,6 @@ public void shouldPublishAfterUpdateEventCorrectly() {
552549
* @see DATAKV-91
553550
*/
554551
@Test
555-
@SuppressWarnings("rawtypes")
556552
public void shouldPublishBeforeDeleteEventCorrectly() {
557553

558554
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.BEFORE_DELETE)));
@@ -574,7 +570,6 @@ public void shouldPublishBeforeDeleteEventCorrectly() {
574570
* @see DATAKV-91
575571
*/
576572
@Test
577-
@SuppressWarnings("rawtypes")
578573
public void shouldPublishAfterDeleteEventCorrectly() {
579574

580575
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.AFTER_DELETE)));
@@ -597,7 +592,6 @@ public void shouldPublishAfterDeleteEventCorrectly() {
597592
* @see DATAKV-91
598593
*/
599594
@Test
600-
@SuppressWarnings("rawtypes")
601595
public void shouldPublishBeforeGetEventCorrectly() {
602596

603597
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.BEFORE_GET)));
@@ -620,7 +614,6 @@ public void shouldPublishBeforeGetEventCorrectly() {
620614
* @see DATAKV-91
621615
*/
622616
@Test
623-
@SuppressWarnings("rawtypes")
624617
public void shouldPublishAfterGetEventCorrectly() {
625618

626619
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.AFTER_GET)));
@@ -643,7 +636,6 @@ public void shouldPublishAfterGetEventCorrectly() {
643636
* @see DATAKV-91
644637
*/
645638
@Test
646-
@SuppressWarnings("rawtypes")
647639
public void shouldPublishDropKeyspaceEventCorrectly() {
648640

649641
template.setEventTypesToPublish(new HashSet<KeyValueEvent.Type>(Arrays.asList(KeyValueEvent.Type.AFTER_DELETE)));

0 commit comments

Comments
 (0)