47 lines
1.8 KiB
Java
47 lines
1.8 KiB
Java
|
|
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);
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|