use of com.mendmix.mybatis.metadata.MapperMetadata in project jeesuite-libs by vakinge.
the class CacheHandler method removeCacheByGroup.
/**
* 删除缓存组
* @param msId
* @param mapperClassName
* @param removePkCache 是否同时删除按主键的缓存
*/
private void removeCacheByGroup(String msId, String mapperClassName) {
MapperMetadata entityInfo = MybatisMapperParser.getMapperMetadata(mapperClassName);
if (entityInfo == null)
return;
final String groupName = entityInfo.getEntityClass().getSimpleName();
cleanCacheExecutor.execute(new Runnable() {
@Override
public void run() {
clearCacheGroup(groupName);
if (logger.isDebugEnabled())
logger.debug(">>auto_cache_process removeGroupCache -> mapperId:{},groupName:{}", msId, groupName);
}
});
}
use of com.mendmix.mybatis.metadata.MapperMetadata in project jeesuite-libs by vakinge.
the class CacheHandler method buildEvictOnMethods.
/**
* 构建自定义缓存更新关系
* @param mapperClassName
* @param method
* @param evictOnMethods
*/
private void buildEvictOnMethods(String mapperClassName, MapperMethod method, String[] evictOnMethods) {
if (evictOnMethods == null || evictOnMethods.length == 0) {
return;
}
String targetMethodFullNamePrefix = mapperClassName.substring(0, mapperClassName.lastIndexOf(".") + 1);
String targetMapperClassName = null;
for (String methodName : evictOnMethods) {
if ("*".equals(methodName)) {
methodName = mapperClassName + ".*";
} else if (!methodName.contains(InvocationVals.DOT)) {
methodName = mapperClassName + InvocationVals.DOT + methodName;
}
if (!methodName.startsWith(targetMethodFullNamePrefix)) {
methodName = targetMethodFullNamePrefix + methodName;
}
targetMapperClassName = methodName.substring(0, methodName.lastIndexOf("."));
if (!methodName.endsWith("*")) {
addCacheCheckRelations(methodName, method.getFullName());
} else {
MapperMetadata methodEntityInfo = MybatisMapperParser.getMapperMetadata(targetMapperClassName);
if (methodEntityInfo == null) {
continue;
}
for (MapperMethod mm : methodEntityInfo.getMapperMethods().values()) {
if (mm.getSqlType() == SqlCommandType.SELECT)
continue;
if (mm.getFullName().contains(methodName.replace("*", ""))) {
addCacheCheckRelations(mm.getFullName(), method.getFullName());
}
}
}
}
}
use of com.mendmix.mybatis.metadata.MapperMetadata in project jeesuite-libs by vakinge.
the class DataChangeLogHandler method set.
public static void set(Class<? extends BaseEntity>[] entityClass) {
List<String> names = new ArrayList<String>(entityClass.length);
for (Class<? extends BaseEntity> clazz : entityClass) {
MapperMetadata entityInfo = MybatisMapperParser.getMapperMetadata(clazz.getName());
names.add(entityInfo.getMapperClass().getName());
}
entityClassNameHolder.set(names);
}
use of com.mendmix.mybatis.metadata.MapperMetadata in project jeesuite-libs by vakinge.
the class DataChangeLogHandler method onFinished.
@Override
public void onFinished(InvocationVals invocation, Object result) {
if (entityClassNameHolder.get() == null || entityClassNameHolder.get().isEmpty())
return;
Object[] args = invocation.getArgs();
MappedStatement mt = (MappedStatement) args[0];
String mapperClassName = mt.getId().substring(0, mt.getId().lastIndexOf("."));
if (!entityClassNameHolder.get().contains(mapperClassName))
return;
MapperMetadata entityInfo = MybatisMapperParser.getMapperMetadata(mapperClassName);
if (entityInfo == null)
return;
try {
System.out.println(mt.getId());
if (mt.getId().endsWith(methodNames[0]) || mt.getId().endsWith(methodNames[1])) {
// BehaviorLogContextHoler.onAddEntity(entityInfo.getEntityClass(), ((BaseEntity)args[1]).getId());
} else if (mt.getId().endsWith(methodNames[2])) {
if (result != null && !((List) result).isEmpty()) {
// BehaviorLogContextHoler.onUpdateEntityBefore((BaseEntity)((List)result).get(0));
}
} else if (mt.getId().endsWith(methodNames[3])) {
// BehaviorLogContextHoler.onDeleteEntity(entityInfo.getEntityClass(), args[1]);
} else if (mt.getId().endsWith(methodNames[4]) || mt.getId().endsWith(methodNames[5])) {
// BehaviorLogContextHoler.onUpdateEntityAfter((BaseEntity)args[1]);
}
} catch (Exception e) {
logger.warn("datachange_interceptor_error for[" + mt.getId() + "]", e);
}
}
use of com.mendmix.mybatis.metadata.MapperMetadata in project jeesuite-libs by vakinge.
the class SqlRewriteHandler method start.
@Override
public void start(JeesuiteMybatisInterceptor context) {
isFieldSharddingTenant = MybatisConfigs.isFieldSharddingTenant(context.getGroupName());
softDeleteColumnName = MybatisConfigs.getSoftDeleteColumn(context.getGroupName());
softDeleteFalseValue = MybatisConfigs.getSoftDeletedFalseValue(context.getGroupName());
deptColumnName = MybatisConfigs.getDeptColumnName(context.getGroupName());
ownerColumnName = MybatisConfigs.getOwnerColumnName(context.getGroupName());
orgBasePermKey = MybatisConfigs.getCurrentOrgPermKey(context.getGroupName());
Properties properties = ResourceUtils.getAllProperties("mendmix.mybatis.permission.table-column-mappings");
properties.forEach((k, v) -> {
String tableName = k.toString().substring(k.toString().indexOf("[") + 1).replace("]", "").trim();
buildTableDataPermissionMapping(tableName, v.toString());
});
dynaDataPermEnabled = !dataPermMappings.isEmpty();
final List<MapperMetadata> mappers = MybatisMapperParser.getMapperMetadatas(context.getGroupName());
//
initColumnConfig(mappers, deptColumnName, deptMappedStatements);
// 软删除
initColumnConfig(mappers, softDeleteColumnName, softDeleteMappedStatements);
// 字段隔离租户模式
if (isFieldSharddingTenant) {
String tenantField = MybatisConfigs.getTenantSharddingField(context.getGroupName());
ColumnMetadata tenantColumn;
for (MapperMetadata mapper : mappers) {
tenantColumn = mapper.getEntityMetadata().getColumns().stream().filter(o -> {
return o.getColumn().equals(tenantField) || o.getProperty().equals(tenantField);
}).findFirst().orElse(null);
if (tenantColumn == null)
continue;
if (tenantColumnName == null)
tenantColumnName = tenantColumn.getColumn();
if (tenantPropName == null)
tenantPropName = tenantColumn.getProperty();
if (!dataPermMappings.containsKey(mapper.getTableName())) {
dataPermMappings.put(mapper.getTableName(), new LinkedHashMap<>());
}
dataPermMappings.get(mapper.getTableName()).put(tenantPropName, tenantColumnName);
}
}
logger.info("dataProfileMappings >> {}", dataPermMappings);
}
Aggregations