подправил кеширование отображаемых данных ( чтобы не распаковывать каждый раз список имен групп и прочее)
This commit is contained in:
@@ -17,8 +17,8 @@ import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
public class DataSet<K, D extends DBObject> extends DataSetAnchestor {
|
||||
//-
|
||||
public static LinkedHashMap<Class, Object> selections = new LinkedHashMap<>();
|
||||
//-
|
||||
public LinkedHashMap<Class, Object> selections = new LinkedHashMap<>();
|
||||
//---
|
||||
public String Name;
|
||||
public Class<K> k; //класс первичного ключа.
|
||||
public Class<D> d; //класс объектов.
|
||||
|
||||
57
src/Common/UI/VisualCache/ConfigurationCache.java
Normal file
57
src/Common/UI/VisualCache/ConfigurationCache.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package Common.UI.VisualCache;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import TestingSystem.Common.Configuration.Configuration;
|
||||
import TestingSystem.Common.Group.Group;
|
||||
import TestingSystem.Common.Group.Json.GroupJson;
|
||||
import TestingSystem.Common.Group.Json.GroupsJson;
|
||||
import TestingSystem.Common.Test.Json.TestJson;
|
||||
import TestingSystem.Common.Test.Json.TestsJson;
|
||||
import TestingSystem.Common.Test.Test;
|
||||
|
||||
import java.util.Vector;
|
||||
public class ConfigurationCache extends VisualCache{
|
||||
public GroupsJson groupsJson = null;
|
||||
public Vector<String> groupsDescriptions = null;
|
||||
public TestsJson testsJson = null;
|
||||
//--
|
||||
public ConfigurationCache(Configuration configuration) {
|
||||
if (configuration.packedGroupsJson.isEmpty())
|
||||
groupsJson = new GroupsJson(); //просто пустой
|
||||
else
|
||||
groupsJson = Utils.gson.fromJson(configuration.packedGroupsJson, GroupsJson.class);
|
||||
//--
|
||||
if (testsJson == null) {
|
||||
if (configuration.packedTestsJson.isEmpty())
|
||||
testsJson = new TestsJson(); //просто пустой
|
||||
else
|
||||
testsJson = Utils.gson.fromJson(configuration.packedTestsJson, TestsJson.class);
|
||||
}
|
||||
//-
|
||||
groupsDescriptions = new Vector<>();
|
||||
for (GroupJson groupJson : groupsJson.array)
|
||||
groupsDescriptions.add(groupJson.description);
|
||||
}
|
||||
public int getTestsCount() {
|
||||
return testsJson.array.size();
|
||||
}
|
||||
public Vector<String> getGroupsDescriptions() {
|
||||
return groupsDescriptions;
|
||||
}
|
||||
public Vector<Group> getGroups(){
|
||||
Vector<Group> groups = new Vector<>();
|
||||
for (GroupJson groupJson : groupsJson.array){
|
||||
if (Global.testingServer.db.groups.containsKey(groupJson.id))
|
||||
groups.add(Global.testingServer.db.groups.get(groupJson.id));
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
public Vector<Test> getTests(){
|
||||
Vector<Test> tests = new Vector<>();
|
||||
for (TestJson testJson : testsJson.array){
|
||||
if (Global.testingServer.db.tests.containsKey(testJson.id))
|
||||
tests.add(Global.testingServer.db.tests.get(testJson.id));
|
||||
}
|
||||
return tests;
|
||||
}
|
||||
}
|
||||
3
src/Common/UI/VisualCache/VisualCache.java
Normal file
3
src/Common/UI/VisualCache/VisualCache.java
Normal file
@@ -0,0 +1,3 @@
|
||||
package Common.UI.VisualCache;
|
||||
public class VisualCache {
|
||||
}
|
||||
46
src/Common/UI/VisualCache/VisualCaches.java
Normal file
46
src/Common/UI/VisualCache/VisualCaches.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package Common.UI.VisualCache;
|
||||
import Common.Database.DBObject;
|
||||
import TestingSystem.Common.Configuration.Configuration;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
public class VisualCaches {
|
||||
static LinkedHashMap<Class, LinkedHashMap<Object, VisualCache>> allData = new LinkedHashMap<>();
|
||||
static LinkedHashMap<Object, VisualCache> getDataForClass(Class class_) {
|
||||
LinkedHashMap<Object, VisualCache> data;
|
||||
if (allData.containsKey(class_)) {
|
||||
data = allData.get(class_);
|
||||
} else {
|
||||
data = new LinkedHashMap<>();
|
||||
allData.put(class_, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
//чтобы не трогать сами объекты и не сбить сериализацию
|
||||
static VisualCache createCache(Object object) {
|
||||
if (object instanceof Configuration)
|
||||
return new ConfigurationCache((Configuration) object);
|
||||
return new VisualCache();
|
||||
}
|
||||
public static VisualCache GetCache(DBObject object) {
|
||||
// System.out.println("get visual cache for " + object.getPK());
|
||||
VisualCache res = null;
|
||||
LinkedHashMap<Object, VisualCache> data = getDataForClass(object.getClass());
|
||||
if (!data.containsKey(object.getPK())) {
|
||||
// System.out.println("cache not found, creating...");
|
||||
data.put(object.getPK(), res = createCache(object));
|
||||
} else {
|
||||
// System.out.println("cache found");
|
||||
res = data.get(object.getPK());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
public static void DeleteCahce(DBObject object){
|
||||
DeleteCahce(object.getClass(), object.getPK());
|
||||
}
|
||||
public static void DeleteCahce(Class class_, Object pk){
|
||||
LinkedHashMap<Object, VisualCache> data = getDataForClass(class_);
|
||||
if (data.containsKey(pk))
|
||||
data.remove(pk);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user