EntityCache

This commit is contained in:
redkale
2024-09-08 01:13:28 +08:00
parent 8c448da19a
commit 3ca986e5a5
2 changed files with 11 additions and 31 deletions

View File

@@ -3105,11 +3105,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
return info.getArrayer().apply(0);
}
final EntityCache<T> cache = info.getCache();
if (cache != null) {
T[] rs = selects == null ? cache.finds(pks) : cache.finds(selects, pks);
if (cache.isFullLoaded() || rs != null) {
return rs;
}
if (cache != null && cache.isFullLoaded()) {
return selects == null ? cache.finds(pks) : cache.finds(selects, pks);
}
return findsDBAsync(info, selects, pks).join();
}
@@ -3121,11 +3118,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
return CompletableFuture.completedFuture(info.getArrayer().apply(0));
}
final EntityCache<T> cache = info.getCache();
if (cache != null) {
T[] rs = selects == null ? cache.finds(pks) : cache.finds(selects, pks);
if (cache.isFullLoaded() || rs != null) {
return CompletableFuture.completedFuture(rs);
}
if (cache != null && cache.isFullLoaded()) {
return CompletableFuture.completedFuture(selects == null ? cache.finds(pks) : cache.finds(selects, pks));
}
return findsDBAsync(info, selects, pks);
}
@@ -3511,11 +3505,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
public <T> boolean exists(final Class<T> clazz, final FilterNode node) {
final EntityInfo<T> info = loadEntityInfo(clazz);
final EntityCache<T> cache = info.getCache();
if (cache != null) {
boolean rs = cache.exists(node);
if (rs || cache.isFullLoaded()) {
return rs;
}
if (cache != null && cache.isFullLoaded()) {
return cache.exists(node);
}
final String[] tables = info.getTables(node);
String sql = existsSql(info, tables, node);
@@ -3533,11 +3524,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource
public <T> CompletableFuture<Boolean> existsAsync(final Class<T> clazz, final FilterNode node) {
final EntityInfo<T> info = loadEntityInfo(clazz);
final EntityCache<T> cache = info.getCache();
if (cache != null) {
boolean rs = cache.exists(node);
if (rs || cache.isFullLoaded()) {
return CompletableFuture.completedFuture(rs);
}
if (cache != null && cache.isFullLoaded()) {
return CompletableFuture.completedFuture(cache.exists(node));
}
final String[] tables = info.getTables(node);

View File

@@ -5,8 +5,6 @@
*/
package org.redkale.source;
import static org.redkale.source.FilterFunc.*;
import java.io.Serializable;
import java.util.*;
import java.util.concurrent.*;
@@ -16,6 +14,7 @@ import java.util.function.*;
import java.util.logging.*;
import java.util.stream.*;
import org.redkale.persistence.*;
import static org.redkale.source.FilterFunc.*;
import org.redkale.util.*;
/**
@@ -128,13 +127,6 @@ public final class EntityCache<T> {
});
}
public void fullLoad() {
CompletableFuture<List<T>> future = fullLoadAsync();
if (future != null) {
future.join();
}
}
public CompletableFuture<List<T>> fullLoadAsync() {
if (this.fullloaded) {
return this.loadFuture;
@@ -1174,7 +1166,7 @@ public final class EntityCache<T> {
numb = numb.floatValue() + val.floatValue();
} else if (numb instanceof Double || val instanceof Double) {
numb = numb.doubleValue() + val.doubleValue();
} else {
} else if (val != null) {
numb = numb.longValue() + val.longValue();
}
}
@@ -1187,7 +1179,7 @@ public final class EntityCache<T> {
numb = numb.floatValue() - val.floatValue();
} else if (numb instanceof Double || val instanceof Double) {
numb = numb.doubleValue() - val.doubleValue();
} else {
} else if (val != null) {
numb = numb.longValue() - val.longValue();
}
}