use of com.diboot.core.cache.StaticMemoryCacheManager in project diboot by dibo-software.
the class IamCacheManager method initApiPermissionCache.
/**
* 初始化
*/
private static synchronized void initApiPermissionCache() {
StaticMemoryCacheManager cacheManager = getCacheManager();
if (cacheManager.isUninitializedCache(CACHE_NAME_CONTROLLER_API) == false) {
return;
}
List<ApiPermissionWrapper> permissions = ApiPermissionExtractor.extractAllApiPermissions();
if (V.notEmpty(permissions)) {
for (ApiPermissionWrapper wrapper : permissions) {
if (wrapper.getChildren() != null) {
for (ApiPermission apiPermission : wrapper.getChildren()) {
// 缓存url-permission
URL_PERMISSIONCODE_CACHE.put(apiPermission.getApiMethod().toUpperCase() + ":" + apiPermission.getApiUri(), apiPermission.getPermissionCode());
// 缓存class-api
cacheManager.putCacheObj(CACHE_NAME_CONTROLLER_API, wrapper.getClassName(), wrapper);
}
}
}
}
}
use of com.diboot.core.cache.StaticMemoryCacheManager in project diboot by dibo-software.
the class BindingCacheManager method initEntityInfoCache.
/**
* 初始化
*/
private static void initEntityInfoCache() {
StaticMemoryCacheManager cacheManager = getCacheManager();
if (cacheManager.isUninitializedCache(CACHE_NAME_CLASS_ENTITY) == false) {
return;
}
// 初始化有service的entity缓存
Map<String, IService> serviceMap = ContextHelper.getApplicationContext().getBeansOfType(IService.class);
Set<String> uniqueEntitySet = new HashSet<>();
if (V.notEmpty(serviceMap)) {
for (Map.Entry<String, IService> entry : serviceMap.entrySet()) {
Class entityClass = BeanUtils.getGenericityClass(entry.getValue(), 1);
if (entityClass != null) {
IService entityIService = entry.getValue();
if (uniqueEntitySet.contains(entityClass.getName())) {
if (entityIService.getClass().getAnnotation(Primary.class) != null) {
EntityInfoCache entityInfoCache = cacheManager.getCacheObj(CACHE_NAME_CLASS_ENTITY, entityClass.getName(), EntityInfoCache.class);
if (entityInfoCache != null) {
entityInfoCache.setService(entityIService);
}
} else {
log.warn("Entity: {} 存在多个service实现类,可能导致调用实例与预期不一致!", entityClass.getName());
}
} else {
EntityInfoCache entityInfoCache = new EntityInfoCache(entityClass, entityIService);
cacheManager.putCacheObj(CACHE_NAME_CLASS_ENTITY, entityClass.getName(), entityInfoCache);
cacheManager.putCacheObj(CACHE_NAME_TABLE_ENTITY, entityInfoCache.getTableName(), entityInfoCache);
cacheManager.putCacheObj(CACHE_NAME_ENTITYNAME_CLASS, entityClass.getSimpleName(), entityClass);
uniqueEntitySet.add(entityClass.getName());
}
}
}
} else {
log.debug("未获取到任何有效@Service.");
}
// 初始化没有service的table-mapper缓存
SqlSessionFactory sqlSessionFactory = ContextHelper.getBean(SqlSessionFactory.class);
Collection<Class<?>> mappers = sqlSessionFactory.getConfiguration().getMapperRegistry().getMappers();
if (V.notEmpty(mappers)) {
for (Class<?> mapperClass : mappers) {
Type[] types = mapperClass.getGenericInterfaces();
try {
if (types != null && types.length > 0 && types[0] != null) {
ParameterizedType genericType = (ParameterizedType) types[0];
Type[] superTypes = genericType.getActualTypeArguments();
if (superTypes != null && superTypes.length > 0 && superTypes[0] != null) {
String entityClassName = superTypes[0].getTypeName();
if (!uniqueEntitySet.contains(entityClassName) && entityClassName.length() > 1) {
Class<?> entityClass = Class.forName(entityClassName);
BaseMapper mapper = (BaseMapper) ContextHelper.getBean(mapperClass);
EntityInfoCache entityInfoCache = new EntityInfoCache(entityClass, null);
entityInfoCache.setBaseMapper(mapper);
cacheManager.putCacheObj(CACHE_NAME_CLASS_ENTITY, entityClass.getName(), entityInfoCache);
cacheManager.putCacheObj(CACHE_NAME_TABLE_ENTITY, entityInfoCache.getTableName(), entityInfoCache);
cacheManager.putCacheObj(CACHE_NAME_ENTITYNAME_CLASS, entityClass.getSimpleName(), entityClass);
uniqueEntitySet.add(entityClass.getName());
}
}
}
} catch (Exception e) {
log.warn("解析mapper异常", e);
}
}
}
uniqueEntitySet = null;
}
use of com.diboot.core.cache.StaticMemoryCacheManager in project diboot by dibo-software.
the class IamCacheManager method getCacheManager.
private static StaticMemoryCacheManager getCacheManager() {
if (iamMemoryCacheManager == null) {
iamMemoryCacheManager = new StaticMemoryCacheManager(CACHE_NAME_CONTROLLER_API);
URL_PERMISSIONCODE_CACHE.clear();
}
return iamMemoryCacheManager;
}
Aggregations