Skip to content

DATAKV-187 - Remove restriction of ID type to be Serializable. #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-keyvalue</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAKV-187-SNAPSHOT</version>

<name>Spring Data KeyValue</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.springframework.data.keyvalue.core;

import java.io.Serializable;
import java.util.Collection;

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

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.lang.Object, java.lang.String, java.lang.Class)
*/
@Override
public <T> T get(Serializable id, Serializable keyspace, Class<T> type) {
public <T> T get(Object id, String keyspace, Class<T> type) {
return (T) get(id, keyspace);
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#delete(java.lang.Object, java.lang.String, java.lang.Class)
*/
@Override
public <T> T delete(Serializable id, Serializable keyspace, Class<T> type) {
public <T> T delete(Object id, String keyspace, Class<T> type) {
return (T) delete(id, keyspace);
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#get(java.io.Serializable, java.io.Serializable, java.lang.Class)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String, java.lang.Class)
*/
@Override
public <T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type) {
public <T> Iterable<T> find(KeyValueQuery<?> query, String keyspace, Class<T> type) {
return engine.execute(query, keyspace, type);
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.io.Serializable)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#find(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String)
*/
@Override
public Collection<?> find(KeyValueQuery<?> query, Serializable keyspace) {
public Collection<?> find(KeyValueQuery<?> query, String keyspace) {
return engine.execute(query, keyspace);
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.io.Serializable)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(org.springframework.data.keyvalue.core.query.KeyValueQuery, java.lang.String)
*/
@Override
public long count(KeyValueQuery<?> query, Serializable keyspace) {
public long count(KeyValueQuery<?> query, String keyspace) {
return engine.count(query, keyspace);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 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.
Expand All @@ -15,7 +15,6 @@
*/
package org.springframework.data.keyvalue.core;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

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

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

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

/**
* @param id
Expand All @@ -65,7 +64,7 @@ public interface KeyValueAdapter extends DisposableBean {
* @return
* @since 1.1
*/
<T> T get(Serializable id, Serializable keyspace, Class<T> type);
<T> T get(Object id, String keyspace, Class<T> type);

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

/**
* @param id
Expand All @@ -83,30 +82,30 @@ public interface KeyValueAdapter extends DisposableBean {
* @return
* @since 1.1
*/
<T> T delete(Serializable id, Serializable keyspace, Class<T> type);
<T> T delete(Object id, String keyspace, Class<T> type);

/**
* Get all elements for given keyspace.
*
* @param keyspace must not be {@literal null}.
* @return empty {@link Collection} if nothing found.
*/
Iterable<?> getAllOf(Serializable keyspace);
Iterable<?> getAllOf(String keyspace);

/**
* Returns a {@link CloseableIterator} that iterates over all entries.
*
* @param keyspace
* @return
*/
CloseableIterator<Map.Entry<Serializable, Object>> entries(Serializable keyspace);
CloseableIterator<Map.Entry<Object, Object>> entries(String keyspace);

/**
* Remove all objects of given type.
*
* @param keyspace must not be {@literal null}.
*/
void deleteAllOf(Serializable keyspace);
void deleteAllOf(String keyspace);

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

/**
* @param query
Expand All @@ -129,14 +128,14 @@ public interface KeyValueAdapter extends DisposableBean {
* @return
* @since 1.1
*/
<T> Iterable<T> find(KeyValueQuery<?> query, Serializable keyspace, Class<T> type);
<T> Iterable<T> find(KeyValueQuery<?> query, String keyspace, Class<T> type);

/**
* Count number of objects within {@literal keyspace}.
*
* @param keyspace must not be {@literal null}.
*/
long count(Serializable keyspace);
long count(String keyspace);

/**
* Count all matching objects within {@literal keyspace}.
Expand All @@ -145,5 +144,5 @@ public interface KeyValueAdapter extends DisposableBean {
* @param keyspace must not be {@literal null}.
* @return
*/
long count(KeyValueQuery<?> query, Serializable keyspace);
long count(KeyValueQuery<?> query, String keyspace);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2017 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.
Expand All @@ -15,7 +15,6 @@
*/
package org.springframework.data.keyvalue.core;

import java.io.Serializable;
import java.util.Optional;

import org.springframework.beans.factory.DisposableBean;
Expand Down Expand Up @@ -45,7 +44,7 @@ public interface KeyValueOperations extends DisposableBean {
* @param id must not be {@literal null}.
* @param objectToInsert must not be {@literal null}.
*/
void insert(Serializable id, Object objectToInsert);
void insert(Object id, Object objectToInsert);

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

/**
* Execute operation against underlying store.
Expand Down Expand Up @@ -126,7 +125,7 @@ public interface KeyValueOperations extends DisposableBean {
* @param id must not be {@literal null}.
* @param objectToUpdate must not be {@literal null}.
*/
void update(Serializable id, Object objectToUpdate);
void update(Object id, Object objectToUpdate);

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

/**
* Total number of elements with given type available. Respects {@link KeySpace} if present and therefore counts all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.springframework.data.keyvalue.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -38,7 +37,6 @@
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

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

GeneratingIdAccessor generatingIdAccessor = new GeneratingIdAccessor(entity.getPropertyAccessor(objectToInsert),
entity.getIdProperty(),
identifierGenerator);
entity.getIdProperty(), identifierGenerator);
Object id = generatingIdAccessor.getOrGenerateIdentifier();

insert((Serializable) id, objectToInsert);
insert(id, objectToInsert);
return objectToInsert;
}

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

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.io.Serializable, java.lang.Object)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#insert(java.lang.Object, java.lang.Object)
*/
@Override
public void insert(final Serializable id, final Object objectToInsert) {
public void insert(final Object id, final Object objectToInsert) {

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

update((Serializable) entity.getIdentifierAccessor(objectToUpdate).getRequiredIdentifier(), objectToUpdate);
update(entity.getIdentifierAccessor(objectToUpdate).getRequiredIdentifier(), objectToUpdate);
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.io.Serializable, java.lang.Object)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#update(java.lang.Object, java.lang.Object)
*/
@Override
public void update(final Serializable id, final Object objectToUpdate) {
public void update(final Object id, final Object objectToUpdate) {

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

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findById(java.io.Serializable, java.lang.Class)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#findById(java.lang.Object, java.lang.Class)
*/
@Override
public <T> Optional<T> findById(final Serializable id, final Class<T> type) {
public <T> Optional<T> findById(final Object id, final Class<T> type) {

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

return delete((Serializable) entity.getIdentifierAccessor(objectToDelete).getIdentifier(), type);
return delete(entity.getIdentifierAccessor(objectToDelete).getIdentifier(), type);
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.io.Serializable, java.lang.Class)
* @see org.springframework.data.keyvalue.core.KeyValueOperations#delete(java.lang.Object, java.lang.Class)
*/
@Override
public <T> T delete(final Serializable id, final Class<T> type) {
public <T> T delete(final Object id, final Class<T> type) {

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