2024-09-18 13:37:11 +03:00
|
|
|
package Common.UI.VisualCache;
|
|
|
|
|
import Common.Database.DBObject;
|
|
|
|
|
import TestingSystem.Common.Configuration.Configuration;
|
2024-09-18 15:25:58 +03:00
|
|
|
import TestingSystem.Common.TestingPackage.TestingPackage;
|
2024-09-28 21:47:17 +03:00
|
|
|
import TestingSystem.DVM.DVMConfiguration.DVMConfiguration;
|
|
|
|
|
import TestingSystem.SAPFOR.SapforConfiguration.SapforConfiguration;
|
2024-09-18 13:37:11 +03:00
|
|
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
2024-09-18 14:57:11 +03:00
|
|
|
//нужен для серверных объектов, чтобы в сокет не класть лишнего.
|
2024-09-18 13:37:11 +03:00
|
|
|
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) {
|
2024-09-28 21:47:17 +03:00
|
|
|
if (object instanceof SapforConfiguration)
|
|
|
|
|
return new SapforConfigurationCache((Configuration) object);
|
|
|
|
|
if (object instanceof DVMConfiguration)
|
2024-10-01 17:33:08 +03:00
|
|
|
return new DVMConfigurationCache((Configuration) object);
|
2024-09-18 15:25:58 +03:00
|
|
|
if (object instanceof TestingPackage)
|
|
|
|
|
return new PackageCache((TestingPackage) object);
|
2024-09-18 13:37:11 +03:00
|
|
|
return new VisualCache();
|
|
|
|
|
}
|
|
|
|
|
public static VisualCache GetCache(DBObject object) {
|
|
|
|
|
VisualCache res = null;
|
|
|
|
|
LinkedHashMap<Object, VisualCache> data = getDataForClass(object.getClass());
|
|
|
|
|
if (!data.containsKey(object.getPK())) {
|
2024-09-19 00:24:36 +03:00
|
|
|
// System.out.println("get visual cache for " + object.getPK()+" "+object.getClass());
|
|
|
|
|
// System.out.println("cache not found, creating...");
|
2024-09-18 13:37:11 +03:00
|
|
|
data.put(object.getPK(), res = createCache(object));
|
|
|
|
|
} else {
|
2024-09-18 22:58:38 +03:00
|
|
|
// System.out.println("cache found");
|
2024-09-18 13:37:11 +03:00
|
|
|
res = data.get(object.getPK());
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2024-09-19 00:24:36 +03:00
|
|
|
//Принудительно удалить старый и записать новый.
|
|
|
|
|
public static void RefreshCache(DBObject object){
|
|
|
|
|
// System.out.println("refresh cache for " + object.getPK()+" "+object.getClass().getSimpleName());
|
|
|
|
|
LinkedHashMap<Object, VisualCache> data = getDataForClass(object.getClass());
|
|
|
|
|
//--
|
|
|
|
|
if (data.containsKey(object.getPK())) {
|
|
|
|
|
data.remove(object.getPK());
|
|
|
|
|
}
|
|
|
|
|
data.put(object.getPK(), createCache(object));
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 22:58:38 +03:00
|
|
|
public static void DeleteCache(DBObject object){
|
|
|
|
|
DeleteCache(object.getClass(), object.getPK());
|
2024-09-18 13:37:11 +03:00
|
|
|
}
|
2024-09-18 22:58:38 +03:00
|
|
|
public static void DeleteCache(Class class_, Object pk){
|
2024-09-19 00:24:36 +03:00
|
|
|
// System.out.println("Delete cache for " + pk+" "+class_);
|
2024-09-18 13:37:11 +03:00
|
|
|
LinkedHashMap<Object, VisualCache> data = getDataForClass(class_);
|
|
|
|
|
if (data.containsKey(pk))
|
|
|
|
|
data.remove(pk);
|
2024-09-18 16:18:50 +03:00
|
|
|
}
|
|
|
|
|
public static void Print(){
|
|
|
|
|
System.out.println("alldata size="+allData.size());
|
|
|
|
|
for (Class class_: allData.keySet()){
|
|
|
|
|
System.out.println("class="+class_.getSimpleName()+" size="+allData.get(class_).size());
|
|
|
|
|
}
|
2024-09-18 13:37:11 +03:00
|
|
|
}
|
|
|
|
|
}
|