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-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) {
|
|
|
|
|
if (object instanceof Configuration)
|
|
|
|
|
return new ConfigurationCache((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) {
|
2024-09-18 15:25:58 +03:00
|
|
|
// System.out.println("get visual cache for " + object.getPK()+" "+object.getClass());
|
2024-09-18 13:37:11 +03:00
|
|
|
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);
|
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
|
|
|
}
|
|
|
|
|
}
|