Skip to content

Commit

Permalink
updated repository to use <From, To> format for generics
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar committed Jul 8, 2024
1 parent 793e01b commit 6c47f97
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class NDBConnectionRepositoryImpl<C extends Connection<T, F>, ID extends String, T extends DataEntry, F extends DataEntry> implements NDBConnRepository<C, ID, T, F>{
public class NDBConnectionRepositoryImpl<C extends Connection<F, T>, ID extends String, T extends DataEntry, F extends DataEntry> implements NDBConnRepository<C, ID, F, T>{
private @Nullable ConnectionHandler connectionHandler = null;
private final NucleoDB nucleoDB;
private final Class<C> classType;
Expand Down Expand Up @@ -238,7 +238,7 @@ public void deleteById(ID id) {
@Override
public void delete(C entity) {
try {
connectionHandler.deleteSync(entity);
connectionHandler.deleteSync(entity.copy(classType, true));
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -272,7 +272,7 @@ public C getById(String uuid) {

@Override
public Set<C> getByTo(T entity, ConnectionProjection projection) {
return connectionHandler.getReverseByTo(entity, projection).stream().map(c->(C)c).collect(Collectors.toSet());
return connectionHandler.getReverseByTo(entity, projection);
}

@Override
Expand All @@ -282,7 +282,7 @@ public Set<F> getFromByTo(T entity, ConnectionProjection projection) {

@Override
public Set<C> getByFrom(F entity, ConnectionProjection projection) {
return connectionHandler.getByFrom(entity, projection).stream().map(c->(C)c).collect(Collectors.toSet());
return connectionHandler.getByFrom(entity, projection);
}

@Override
Expand All @@ -292,6 +292,6 @@ public Set<T> getToByFrom(F entity, ConnectionProjection projection) {

@Override
public Set<C> getByFromAndTo(F fromEntity, T toEntity, ConnectionProjection projection) {
return connectionHandler.getByFromAndTo(fromEntity, toEntity, projection).stream().map(c->(C)c).collect(Collectors.toSet());
return connectionHandler.getByFromAndTo(fromEntity, toEntity, projection);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.nucleodb.library.database.utils.Pagination;
import com.nucleodb.library.database.utils.Serializer;
import com.nucleodb.library.database.utils.exceptions.InvalidIndexTypeException;
import com.nucleodb.library.database.utils.exceptions.ObjectNotSavedException;
import com.nucleodb.spring.query.QueryParser;
import com.nucleodb.spring.query.common.ConditionOperation;
import com.nucleodb.spring.query.common.LookupOperation;
Expand Down Expand Up @@ -166,7 +167,13 @@ public Object execute(Object[] parameters) {
return entries.stream();
}else if(query.getMethod().equals("deleteBy")){
CountDownLatch countDownLatch = new CountDownLatch(entries.size());
entries.stream().map(de -> (DataEntry) de.copy(table.getConfig().getDataEntryClass(), true)).forEach(e->{
entries.stream().map(de -> {
try {
return de.copy(table.getConfig().getDataEntryClass(), true);
} catch (ObjectNotSavedException e) {
throw new RuntimeException(e);
}
}).forEach(e->{
table.deleteAsync(e, (dataEntry)->{
countDownLatch.countDown();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

public interface NDBConnRepository<C extends Connection<T, F>, ID extends String, T extends DataEntry, F extends DataEntry> extends CrudRepository<C, ID>{
public interface NDBConnRepository<C extends Connection<F, T>, ID extends String, F extends DataEntry, T extends DataEntry> extends CrudRepository<C, ID>{
@Override
<S extends C> S save(S entity);

Expand Down

0 comments on commit 6c47f97

Please sign in to comment.