Skip to content

Commit d6ee87a

Browse files
christophstroblmp911de
authored andcommitted
DATAKV-187 - Remove restriction of ID type to be Serializable.
Original pull request: #25.
1 parent 8f5fa59 commit d6ee87a

File tree

11 files changed

+107
-121
lines changed

11 files changed

+107
-121
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.keyvalue.core;
1717

18-
import java.io.Serializable;
1918
import java.util.Collection;
2019

2120
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
@@ -59,46 +58,46 @@ protected AbstractKeyValueAdapter(QueryEngine<? extends KeyValueAdapter, ?, ?> e
5958

6059
/*
6160
* (non-Javadoc)
62-
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
61+
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.lang.Object, java.lang.String, java.lang.Class)
6362
*/
6463
@Override
65-
public <T> T get(Serializable id, Serializable keyspace, Class<T> type) {
64+
public <T> T get(Object id, String keyspace, Class<T> type) {
6665
return (T) get(id, keyspace);
6766
}
6867

6968
/*
7069
* (non-Javadoc)
71-
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
70+
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#delete(java.lang.Object, java.lang.String, java.lang.Class)
7271
*/
7372
@Override
74-
public <T> T delete(Serializable id, Serializable keyspace, Class<T> type) {
73+
public <T> T delete(Object id, String keyspace, Class<T> type) {
7574
return (T) delete(id, keyspace);
7675
}
7776

7877
/*
7978
* (non-Javadoc)
80-
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
79+
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String, java.lang.Class)
8180
*/
8281
@Override
83-
public <T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type) {
82+
public <T> Iterable<T> find(KeyValueQuery<?> query, String keyspace, Class<T> type) {
8483
return engine.execute(query, keyspace, type);
8584
}
8685

8786
/*
8887
* (non-Javadoc)
89-
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.io.Serializable)
88+
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String)
9089
*/
9190
@Override
92-
public Collection<?> find(KeyValueQuery<?> query, Serializable keyspace) {
91+
public Collection<?> find(KeyValueQuery<?> query, String keyspace) {
9392
return engine.execute(query, keyspace);
9493
}
9594

9695
/*
9796
* (non-Javadoc)
98-
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.io.Serializable)
97+
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String)
9998
*/
10099
@Override
101-
public long count(KeyValueQuery<?> query, Serializable keyspace) {
100+
public long count(KeyValueQuery<?> query, String keyspace) {
102101
return engine.count(query, keyspace);
103102
}
104103
}

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2017 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.
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.keyvalue.core;
1717

18-
import java.io.Serializable;
1918
import java.util.Collection;
2019
import java.util.Map;
2120

@@ -38,7 +37,7 @@ public interface KeyValueAdapter extends DisposableBean {
3837
* @param keyspace must not be {@literal null}.
3938
* @return the item previously associated with the id.
4039
*/
41-
Object put(Serializable id, Object item, Serializable keyspace);
40+
Object put(Object id, Object item, String keyspace);
4241

4342
/**
4443
* Check if a object with given id exists in keyspace.
@@ -47,7 +46,7 @@ public interface KeyValueAdapter extends DisposableBean {
4746
* @param keyspace must not be {@literal null}.
4847
* @return true if item of type with id exists.
4948
*/
50-
boolean contains(Serializable id, Serializable keyspace);
49+
boolean contains(Object id, String keyspace);
5150

5251
/**
5352
* Get the object with given id from keyspace.
@@ -56,7 +55,7 @@ public interface KeyValueAdapter extends DisposableBean {
5655
* @param keyspace must not be {@literal null}.
5756
* @return {@literal null} in case no matching item exists.
5857
*/
59-
Object get(Serializable id, Serializable keyspace);
58+
Object get(Object id, String keyspace);
6059

6160
/**
6261
* @param id
@@ -65,7 +64,7 @@ public interface KeyValueAdapter extends DisposableBean {
6564
* @return
6665
* @since 1.1
6766
*/
68-
<T> T get(Serializable id, Serializable keyspace, Class<T> type);
67+
<T> T get(Object id, String keyspace, Class<T> type);
6968

7069
/**
7170
* Delete and return the obect with given type and id.
@@ -74,7 +73,7 @@ public interface KeyValueAdapter extends DisposableBean {
7473
* @param keyspace must not be {@literal null}.
7574
* @return {@literal null} if object could not be found
7675
*/
77-
Object delete(Serializable id, Serializable keyspace);
76+
Object delete(Object id, String keyspace);
7877

7978
/**
8079
* @param id
@@ -83,30 +82,30 @@ public interface KeyValueAdapter extends DisposableBean {
8382
* @return
8483
* @since 1.1
8584
*/
86-
<T> T delete(Serializable id, Serializable keyspace, Class<T> type);
85+
<T> T delete(Object id, String keyspace, Class<T> type);
8786

8887
/**
8988
* Get all elements for given keyspace.
9089
*
9190
* @param keyspace must not be {@literal null}.
9291
* @return empty {@link Collection} if nothing found.
9392
*/
94-
Iterable<?> getAllOf(Serializable keyspace);
93+
Iterable<?> getAllOf(String keyspace);
9594

9695
/**
9796
* Returns a {@link CloseableIterator} that iterates over all entries.
9897
*
9998
* @param keyspace
10099
* @return
101100
*/
102-
CloseableIterator<Map.Entry<Serializable, Object>> entries(Serializable keyspace);
101+
CloseableIterator<Map.Entry<Object, Object>> entries(String keyspace);
103102

104103
/**
105104
* Remove all objects of given type.
106105
*
107106
* @param keyspace must not be {@literal null}.
108107
*/
109-
void deleteAllOf(Serializable keyspace);
108+
void deleteAllOf(String keyspace);
110109

111110
/**
112111
* Removes all objects.
@@ -120,7 +119,7 @@ public interface KeyValueAdapter extends DisposableBean {
120119
* @param keyspace must not be {@literal null}.
121120
* @return empty {@link Collection} if no match found.
122121
*/
123-
Iterable<?> find(KeyValueQuery<?> query, Serializable keyspace);
122+
Iterable<?> find(KeyValueQuery<?> query, String keyspace);
124123

125124
/**
126125
* @param query
@@ -129,14 +128,14 @@ public interface KeyValueAdapter extends DisposableBean {
129128
* @return
130129
* @since 1.1
131130
*/
132-
<T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type);
131+
<T> Iterable<T> find(KeyValueQuery<?> query, String keyspace, Class<T> type);
133132

134133
/**
135134
* Count number of objects within {@literal keyspace}.
136135
*
137136
* @param keyspace must not be {@literal null}.
138137
*/
139-
long count(Serializable keyspace);
138+
long count(String keyspace);
140139

141140
/**
142141
* Count all matching objects within {@literal keyspace}.
@@ -145,5 +144,5 @@ public interface KeyValueAdapter extends DisposableBean {
145144
* @param keyspace must not be {@literal null}.
146145
* @return
147146
*/
148-
long count(KeyValueQuery<?> query, Serializable keyspace);
147+
long count(KeyValueQuery<?> query, String keyspace);
149148
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2017 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.
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.keyvalue.core;
1717

18-
import java.io.Serializable;
1918
import java.util.Optional;
2019

2120
import org.springframework.beans.factory.DisposableBean;
@@ -45,7 +44,7 @@ public interface KeyValueOperations extends DisposableBean {
4544
* @param id must not be {@literal null}.
4645
* @param objectToInsert must not be {@literal null}.
4746
*/
48-
void insert(Serializable id, Object objectToInsert);
47+
void insert(Object id, Object objectToInsert);
4948

5049
/**
5150
* Get all elements of given type. Respects {@link KeySpace} if present and therefore returns all elements that can be
@@ -74,7 +73,7 @@ public interface KeyValueOperations extends DisposableBean {
7473
* @param type must not be {@literal null}.
7574
* @return null if not found.
7675
*/
77-
<T> Optional<T> findById(Serializable id, Class<T> type);
76+
<T> Optional<T> findById(Object id, Class<T> type);
7877

7978
/**
8079
* Execute operation against underlying store.
@@ -126,7 +125,7 @@ public interface KeyValueOperations extends DisposableBean {
126125
* @param id must not be {@literal null}.
127126
* @param objectToUpdate must not be {@literal null}.
128127
*/
129-
void update(Serializable id, Object objectToUpdate);
128+
void update(Object id, Object objectToUpdate);
130129

131130
/**
132131
* Remove all elements of type. Respects {@link KeySpace} if present and therefore removes all elements that can be
@@ -149,7 +148,7 @@ public interface KeyValueOperations extends DisposableBean {
149148
* @param type must not be {@literal null}.
150149
* @return the deleted item or {@literal null} if no match found.
151150
*/
152-
<T> T delete(Serializable id, Class<T> type);
151+
<T> T delete(Object id, Class<T> type);
153152

154153
/**
155154
* Total number of elements with given type available. Respects {@link KeySpace} if present and therefore counts all

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.keyvalue.core;
1717

18-
import java.io.Serializable;
1918
import java.util.ArrayList;
2019
import java.util.Collections;
2120
import java.util.List;
@@ -38,7 +37,6 @@
3837
import org.springframework.util.Assert;
3938
import org.springframework.util.ClassUtils;
4039
import org.springframework.util.CollectionUtils;
41-
import org.springframework.util.ObjectUtils;
4240

4341
/**
4442
* Basic implementation of {@link KeyValueOperations}.
@@ -135,11 +133,10 @@ public <T> T insert(T objectToInsert) {
135133
KeyValuePersistentEntity<?, ?> entity = getKeyValuePersistentEntity(objectToInsert);
136134

137135
GeneratingIdAccessor generatingIdAccessor = new GeneratingIdAccessor(entity.getPropertyAccessor(objectToInsert),
138-
entity.getIdProperty(),
139-
identifierGenerator);
136+
entity.getIdProperty(), identifierGenerator);
140137
Object id = generatingIdAccessor.getOrGenerateIdentifier();
141138

142-
insert((Serializable) id, objectToInsert);
139+
insert(id, objectToInsert);
143140
return objectToInsert;
144141
}
145142

@@ -149,10 +146,10 @@ public <T> T insert(T objectToInsert) {
149146

150147
/*
151148
* (non-Javadoc)
152-
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.io.Serializable, java.lang.Object)
149+
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.lang.Object, java.lang.Object)
153150
*/
154151
@Override
155-
public void insert(final Serializable id, final Object objectToInsert) {
152+
public void insert(final Object id, final Object objectToInsert) {
156153

157154
Assert.notNull(id, "Id for object to be inserted must not be null!");
158155
Assert.notNull(objectToInsert, "Object to be inserted must not be null!");
@@ -194,15 +191,15 @@ public void update(Object objectToUpdate) {
194191
String.format("Cannot determine id for type %s", ClassUtils.getUserClass(objectToUpdate)));
195192
}
196193

197-
update((Serializable) entity.getIdentifierAccessor(objectToUpdate).getRequiredIdentifier(), objectToUpdate);
194+
update(entity.getIdentifierAccessor(objectToUpdate).getRequiredIdentifier(), objectToUpdate);
198195
}
199196

200197
/*
201198
* (non-Javadoc)
202-
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.io.Serializable, java.lang.Object)
199+
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.lang.Object, java.lang.Object)
203200
*/
204201
@Override
205-
public void update(final Serializable id, final Object objectToUpdate) {
202+
public void update(final Object id, final Object objectToUpdate) {
206203

207204
Assert.notNull(id, "Id for object to be inserted must not be null!");
208205
Assert.notNull(objectToUpdate, "Object to be updated must not be null!");
@@ -258,10 +255,10 @@ public Iterable<T> doInKeyValue(KeyValueAdapter adapter) {
258255

259256
/*
260257
* (non-Javadoc)
261-
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findById(java.io.Serializable, java.lang.Class)
258+
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findById(java.lang.Object, java.lang.Class)
262259
*/
263260
@Override
264-
public <T> Optional<T> findById(final Serializable id, final Class<T> type) {
261+
public <T> Optional<T> findById(final Object id, final Class<T> type) {
265262

266263
Assert.notNull(id, "Id for object to be inserted must not be null!");
267264
Assert.notNull(type, "Type to fetch must not be null!");
@@ -328,15 +325,15 @@ public <T> T delete(T objectToDelete) {
328325
Class<T> type = (Class<T>) ClassUtils.getUserClass(objectToDelete);
329326
KeyValuePersistentEntity<?, ?> entity = getKeyValuePersistentEntity(objectToDelete);
330327

331-
return delete((Serializable) entity.getIdentifierAccessor(objectToDelete).getIdentifier(), type);
328+
return delete(entity.getIdentifierAccessor(objectToDelete).getIdentifier(), type);
332329
}
333330

334331
/*
335332
* (non-Javadoc)
336-
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.io.Serializable, java.lang.Class)
333+
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.lang.Object, java.lang.Class)
337334
*/
338335
@Override
339-
public <T> T delete(final Serializable id, final Class<T> type) {
336+
public <T> T delete(final Object id, final Class<T> type) {
340337

341338
Assert.notNull(id, "Id for object to be deleted must not be null!");
342339
Assert.notNull(type, "Type to delete must not be null!");

0 commit comments

Comments
 (0)