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

View File

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