Skip to content

Commit

Permalink
FMWK-520 Remove unnecessary checked ReflectiveOperationException decl…
Browse files Browse the repository at this point in the history
…aration (#166)
  • Loading branch information
reugn authored Jul 31, 2024
1 parent 1562be5 commit eb4dec4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
7 changes: 1 addition & 6 deletions src/main/java/com/aerospike/mapper/tools/AeroMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ private <T> T read(Policy readPolicy, @NotNull Class<T> clazz, @NotNull Key key,
try {
ThreadLocalKeySaver.save(key);
return mappingConverter.convertToObject(clazz, key, record, entry, resolveDependencies);
} catch (ReflectiveOperationException e) {
throw new AerospikeException(e);
} finally {
ThreadLocalKeySaver.clear();
}
Expand Down Expand Up @@ -263,8 +261,6 @@ private <T> T[] readBatch(BatchPolicy batchPolicy, @NotNull Class<T> clazz, @Not
ThreadLocalKeySaver.save(keys[i]);
T result = mappingConverter.convertToObject(clazz, keys[i], records[i], entry, false);
results[i] = result;
} catch (ReflectiveOperationException e) {
throw new AerospikeException(e);
} finally {
ThreadLocalKeySaver.clear();
}
Expand Down Expand Up @@ -328,8 +324,7 @@ public <T> void find(@NotNull Class<T> clazz, Function<T, Boolean> function) thr

RecordSet recordSet = null;
try {
// TODO: set the policy (If this statement is thought to be useful, which is
// dubious)
// TODO: set the policy (If this statement is thought to be useful, which is dubious)
recordSet = mClient.query(null, statement);
T result;
while (recordSet.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public <T> Mono<T> readFromDigest(@NotNull Class<T> clazz, @NotNull byte[] diges
}

@Override
public <T> Mono<T> readFromDigest(@NotNull Class<T> clazz, @NotNull byte[] digest, boolean resolveDependencies) throws AerospikeException {
public <T> Mono<T> readFromDigest(@NotNull Class<T> clazz, @NotNull byte[] digest, boolean resolveDependencies) {
ClassCacheEntry<T> entry = MapperUtils.getEntryAndValidateNamespace(clazz, this);
Key key = new Key(entry.getNamespace(), digest, entry.getSetName(), null);
return this.read(null, clazz, key, entry, resolveDependencies);
Expand Down Expand Up @@ -211,8 +211,6 @@ private <T> Mono<T> read(Policy readPolicy, @NotNull Class<T> clazz, @NotNull Ke
try {
ThreadLocalKeySaver.save(key);
return mappingConverter.convertToObject(clazz, key, keyRecord.record, entry, resolveDependencies);
} catch (ReflectiveOperationException e) {
throw new AerospikeException(e);
} finally {
ThreadLocalKeySaver.clear();
}
Expand Down Expand Up @@ -240,8 +238,6 @@ private <T> Flux<T> readBatch(BatchPolicy batchPolicy, @NotNull Class<T> clazz,
try {
ThreadLocalKeySaver.save(keyRecord.key);
return mappingConverter.convertToObject(clazz, keyRecord.key, keyRecord.record, entry, true);
} catch (ReflectiveOperationException e) {
throw new AerospikeException(e);
} finally {
ThreadLocalKeySaver.clear();
}
Expand Down Expand Up @@ -296,7 +292,8 @@ public Mono<Boolean> delete(WritePolicy writePolicy, @NotNull Object object) {
}

@Override
public <T> Mono<Void> find(@NotNull Class<T> clazz, Function<T, Boolean> function) throws AerospikeException {
@SuppressWarnings("deprecation")
public <T> Mono<Void> find(@NotNull Class<T> clazz, Function<T, Boolean> function) {
return Mono.fromCallable(() -> {
asMapper().find(clazz, function);
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.aerospike.mapper.tools.converters;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.validation.constraints.NotNull;

import com.aerospike.client.AerospikeException;
import com.aerospike.client.IAerospikeClient;
import com.aerospike.client.Key;
Expand All @@ -24,6 +17,12 @@
import com.aerospike.mapper.tools.utils.MapperUtils;
import com.aerospike.mapper.tools.utils.TypeUtils;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class MappingConverter {

private final IBaseAeroMapper mapper;
Expand Down Expand Up @@ -76,14 +75,9 @@ public <T> T translateFromAerospike(@NotNull Object obj, @NotNull Class<T> expec
* @param clazz The class type to convert the Aerospike record to.
* @param record The Aerospike record to convert.
* @return A virtual list.
* @throws AerospikeException an AerospikeException will be thrown in case of an encountering a ReflectiveOperationException.
*/
public <T> T convertToObject(Class<T> clazz, Key key, Record record) {
try {
return convertToObject(clazz, key, record, null);
} catch (ReflectiveOperationException e) {
throw new AerospikeException(e);
}
return convertToObject(clazz, key, record, null);
}

/**
Expand All @@ -94,16 +88,15 @@ public <T> T convertToObject(Class<T> clazz, Key key, Record record) {
* @param record The Aerospike record to convert.
* @param entry The entry that holds information on how to store the provided class.
* @return A virtual list.
* @throws AerospikeException an AerospikeException will be thrown in case of an encountering a ReflectiveOperationException.
*/
public <T> T convertToObject(Class<T> clazz, Key key, Record record, ClassCacheEntry<T> entry) throws ReflectiveOperationException {
public <T> T convertToObject(Class<T> clazz, Key key, Record record, ClassCacheEntry<T> entry) {
return this.convertToObject(clazz, key, record, entry, true);
}

/**
* This method should not be used, it is public only to allow mappers to see it.
*/
public <T> T convertToObject(Class<T> clazz, Key key, Record record, ClassCacheEntry<T> entry, boolean resolveDependencies) throws ReflectiveOperationException {
public <T> T convertToObject(Class<T> clazz, Key key, Record record, ClassCacheEntry<T> entry, boolean resolveDependencies) {
if (entry == null) {
entry = ClassCache.getInstance().loadClass(clazz, mapper);
}
Expand Down Expand Up @@ -252,10 +245,14 @@ public void resolveDependencies(ClassCacheEntry<?> parentEntity) {
DeferredObjectLoader.DeferredObjectSetter thisObjectSetter = deferredObjects.get(i);
try {
ThreadLocalKeySaver.save(keys[i]);
Object result = records[i] == null ? null : convertToObject((Class) thisObjectSetter.getObject().getType(), keys[i], records[i], classCacheEntryList.get(i), false);
Object obj = convertToObject(
(Class<Object>) thisObjectSetter.getObject().getType(),
keys[i],
records[i],
(ClassCacheEntry<Object>) classCacheEntryList.get(i),
false);
Object result = records[i] == null ? null : obj;
thisObjectSetter.getSetter().setValue(result);
} catch (ReflectiveOperationException e) {
throw new AerospikeException(e);
} finally {
ThreadLocalKeySaver.clear();
}
Expand Down

0 comments on commit eb4dec4

Please sign in to comment.