diff --git a/storage/src/main/java/com/zfoo/storage/StorageContext.java b/storage/src/main/java/com/zfoo/storage/StorageContext.java index 91b8e7993..f837b71c0 100644 --- a/storage/src/main/java/com/zfoo/storage/StorageContext.java +++ b/storage/src/main/java/com/zfoo/storage/StorageContext.java @@ -56,10 +56,6 @@ public static V get(Class clazz, K id) { return instance.storageManager.getStorage(clazz).get(id); } - public static List getList(Class clazz) { - return instance.storageManager.getStorage(clazz).getList(); - } - public static List getIndexes(Class clazz, Func1 func, INDEX index) { return instance.storageManager.getStorage(clazz).getIndexes(func, index); } diff --git a/storage/src/main/java/com/zfoo/storage/manager/StorageInt.java b/storage/src/main/java/com/zfoo/storage/manager/StorageInt.java index 0b767648d..3822ae0e4 100644 --- a/storage/src/main/java/com/zfoo/storage/manager/StorageInt.java +++ b/storage/src/main/java/com/zfoo/storage/manager/StorageInt.java @@ -72,17 +72,6 @@ public V get(long id) { return get((int) id); } - @Override - public int size() { - return dataMap.size(); - } - - @Override - public void recycleStorage() { - super.recycleStorage(); - dataMap = null; - } - @Override public Collection getAll() { return dataMap.values().stream().toList(); @@ -95,4 +84,15 @@ public Map getData() { return map; } + @Override + public int size() { + return dataMap.size(); + } + + @Override + public void recycleStorage() { + super.recycleStorage(); + dataMap = null; + } + } diff --git a/storage/src/main/java/com/zfoo/storage/manager/StorageLong.java b/storage/src/main/java/com/zfoo/storage/manager/StorageLong.java index d5ba2b371..2c1abd8b6 100644 --- a/storage/src/main/java/com/zfoo/storage/manager/StorageLong.java +++ b/storage/src/main/java/com/zfoo/storage/manager/StorageLong.java @@ -72,17 +72,6 @@ public V get(long id) { return result; } - @Override - public int size() { - return dataMap.size(); - } - - @Override - public void recycleStorage() { - super.recycleStorage(); - dataMap = null; - } - @Override public Collection getAll() { return dataMap.values().stream().toList(); @@ -95,4 +84,15 @@ public Map getData() { return map; } + @Override + public int size() { + return dataMap.size(); + } + + @Override + public void recycleStorage() { + super.recycleStorage(); + dataMap = null; + } + } diff --git a/storage/src/main/java/com/zfoo/storage/manager/StorageObject.java b/storage/src/main/java/com/zfoo/storage/manager/StorageObject.java index ae6a6b87f..b58805e49 100644 --- a/storage/src/main/java/com/zfoo/storage/manager/StorageObject.java +++ b/storage/src/main/java/com/zfoo/storage/manager/StorageObject.java @@ -73,11 +73,11 @@ protected StorageObject() { } public StorageObject(Class clazz, IdDef idDef, Map indexDefMap, List values) { - this.dataMap = new HashMap<>(CollectionUtils.capacity(values.size())); + this.dataMap = new HashMap<>(CollectionUtils.capacity(values.size())); this.clazz = clazz; this.idDef = idDef; this.indexDefMap = indexDefMap; - for (var value: values) { + for (var value : values) { @SuppressWarnings("unchecked") var id = (K) ReflectionUtils.getField(idDef.getField(), value); @@ -150,47 +150,16 @@ public V get(long id) { return get(key); } - @Override - public void recycleStorage() { - recycle = true; - dataMap = null; - indexMap = null; - uniqueIndexMap = null; - idDef = null; - indexDefMap = null; - } - - @Override - public boolean isRecycle() { - return recycle; - } - - @Override - public void setRecycle(boolean recycle) { - this.recycle = recycle; - } - @Override public Collection getAll() { return dataMap.values(); } - @Override - public List getList() { - Collection all = getAll(); - return all.stream().toList(); - } - @Override public Map getData() { return Collections.unmodifiableMap(dataMap); } - @Override - public IdDef getIdDef() { - return idDef; - } - @Override public List getIndexes(Func1 func, INDEX index) { String indexName = LambdaUtils.getFieldName(func); @@ -213,6 +182,31 @@ public V getUniqueIndex(Func1 func, INDEX index) { return value; } + @Override + public void recycleStorage() { + recycle = true; + dataMap = null; + indexMap = null; + uniqueIndexMap = null; + idDef = null; + indexDefMap = null; + } + + @Override + public boolean isRecycle() { + return recycle; + } + + @Override + public void setRecycle(boolean recycle) { + this.recycle = recycle; + } + + @Override + public IdDef getIdDef() { + return idDef; + } + @Override public int size() { return dataMap.size(); diff --git a/storage/src/main/java/com/zfoo/storage/model/IStorage.java b/storage/src/main/java/com/zfoo/storage/model/IStorage.java index de300e142..809e8a396 100644 --- a/storage/src/main/java/com/zfoo/storage/model/IStorage.java +++ b/storage/src/main/java/com/zfoo/storage/model/IStorage.java @@ -36,24 +36,23 @@ public interface IStorage { V get(long id); - void recycleStorage(); - - boolean isRecycle(); - - void setRecycle(boolean recycle); - Collection getAll(); - List getList(); - Map getData(); - IdDef getIdDef(); - List getIndexes(Func1 func, INDEX index); @Nullable V getUniqueIndex(Func1 func, INDEX uindex); int size(); + + void recycleStorage(); + + boolean isRecycle(); + + void setRecycle(boolean recycle); + + IdDef getIdDef(); + } diff --git a/storage/src/test/java/com/zfoo/storage/ApplicationTest.java b/storage/src/test/java/com/zfoo/storage/ApplicationTest.java index f8e9f7953..dfe76a1b2 100644 --- a/storage/src/test/java/com/zfoo/storage/ApplicationTest.java +++ b/storage/src/test/java/com/zfoo/storage/ApplicationTest.java @@ -51,8 +51,6 @@ public void startStorageTest() { IStorage storage1 = StorageContext.getStorageManager().getStorage(StudentResource.class); - //获取所有数据 - List list = StorageContext.getList(StudentResource.class); //根据主键获取数据 StudentResource studentResource = StorageContext.get(StudentResource.class, 1001); TeacherResource teacherResource = StorageContext.get(TeacherResource.class, 1001);