Skip to content

Using getRequiredAdapter in RedisQueryEngine to avoid NPE. #2801

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 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Junghoon Ban
* @since 1.7
*/
class RedisQueryEngine extends QueryEngine<RedisKeyValueAdapter, RedisOperationChain, Comparator<?>> {
Expand Down Expand Up @@ -89,7 +90,7 @@ private <T> List<T> doFind(RedisOperationChain criteria, long offset, int rows,
if (criteria == null
|| (CollectionUtils.isEmpty(criteria.getOrSismember()) && CollectionUtils.isEmpty(criteria.getSismember()))
&& criteria.getNear() == null) {
return getAdapter().getAllOf(keyspace, type, offset, rows);
return getRequiredAdapter().getAllOf(keyspace, type, offset, rows);
}

RedisCallback<Map<byte[], Map<byte[], byte[]>>> callback = connection -> {
Expand Down Expand Up @@ -118,7 +119,8 @@ private <T> List<T> doFind(RedisOperationChain criteria, long offset, int rows,
}
}

byte[] keyspaceBin = getAdapter().getConverter().getConversionService().convert(keyspace + ":", byte[].class);
byte[] keyspaceBin = getRequiredAdapter().getConverter().getConversionService().convert(keyspace + ":",
byte[].class);

Map<byte[], Map<byte[], byte[]>> rawData = new LinkedHashMap<>();

Expand All @@ -139,7 +141,7 @@ private <T> List<T> doFind(RedisOperationChain criteria, long offset, int rows,
return rawData;
};

Map<byte[], Map<byte[], byte[]>> raw = this.getAdapter().execute(callback);
Map<byte[], Map<byte[], byte[]>> raw = this.getRequiredAdapter().execute(callback);

List<T> result = new ArrayList<>(raw.size());
for (Map.Entry<byte[], Map<byte[], byte[]>> entry : raw.entrySet()) {
Expand All @@ -149,10 +151,10 @@ private <T> List<T> doFind(RedisOperationChain criteria, long offset, int rows,
}

RedisData data = new RedisData(entry.getValue());
data.setId(getAdapter().getConverter().getConversionService().convert(entry.getKey(), String.class));
data.setId(getRequiredAdapter().getConverter().getConversionService().convert(entry.getKey(), String.class));
data.setKeyspace(keyspace);

T converted = this.getAdapter().getConverter().read(type, data);
T converted = this.getRequiredAdapter().getConverter().read(type, data);

result.add(converted);
}
Expand All @@ -169,10 +171,10 @@ public Collection<?> execute(RedisOperationChain criteria, Comparator<?> sort, l
public long count(RedisOperationChain criteria, String keyspace) {

if (criteria == null || criteria.isEmpty()) {
return this.getAdapter().count(keyspace);
return this.getRequiredAdapter().count(keyspace);
}

return this.getAdapter().execute(connection -> {
return this.getRequiredAdapter().execute(connection -> {

long result = 0;

Expand All @@ -194,9 +196,9 @@ private byte[][] keys(String prefix, Collection<PathAndValue> source) {
int i = 0;
for (PathAndValue pathAndValue : source) {

byte[] convertedValue = getAdapter().getConverter().getConversionService().convert(pathAndValue.getFirstValue(),
byte[].class);
byte[] fullPath = getAdapter().getConverter().getConversionService()
byte[] convertedValue = getRequiredAdapter().getConverter().getConversionService()
.convert(pathAndValue.getFirstValue(), byte[].class);
byte[] fullPath = getRequiredAdapter().getConverter().getConversionService()
.convert(prefix + pathAndValue.getPath() + ":", byte[].class);

keys[i] = ByteUtils.concat(fullPath, convertedValue);
Expand All @@ -208,7 +210,7 @@ private byte[][] keys(String prefix, Collection<PathAndValue> source) {
private byte[] geoKey(String prefix, NearPath source) {

String path = GeoIndexedPropertyValue.geoIndexName(source.getPath());
return getAdapter().getConverter().getConversionService().convert(prefix + path, byte[].class);
return getRequiredAdapter().getConverter().getConversionService().convert(prefix + path, byte[].class);

}

Expand Down