Browse Source
1-简化操作,不区分 设计器/服务器 启动。只在设计器启动后进行检测 2-切换环境的检测。切换环境后上次的任务需要停止执行。 3-FineDB 检测从捕获检测,切换到全量检测feature/x
Harrison
2 years ago
3 changed files with 138 additions and 183 deletions
@ -1,22 +1,106 @@
|
||||
package com.fr.env.detect.impl; |
||||
|
||||
import com.fr.env.detect.base.CatchExceptionDetector; |
||||
import com.fr.config.ConfigContext; |
||||
import com.fr.config.Configuration; |
||||
import com.fr.design.dialog.FineJOptionPane; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.env.detect.base.AbstractExceptionDetector; |
||||
import com.fr.env.detect.base.DetectorConstants; |
||||
import com.fr.env.detect.bean.DetectorResult; |
||||
import com.fr.env.detect.bean.DetectorType; |
||||
import com.fr.env.detect.impl.converter.FineDbDirtyConverter; |
||||
import com.fr.env.detect.thowable.ThrowableStore; |
||||
import com.fr.env.detect.bean.ExceptionSolution; |
||||
import com.fr.env.detect.bean.Message; |
||||
import com.fr.env.detect.bean.SolutionAction; |
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.third.org.hibernate.exception.GenericJDBCException; |
||||
|
||||
import javax.swing.JOptionPane; |
||||
import java.util.Iterator; |
||||
import java.util.function.Function; |
||||
|
||||
/** |
||||
* created by Harrison on 2022/05/25 |
||||
**/ |
||||
public class FineDbDirtyDetector extends CatchExceptionDetector { |
||||
public class FineDbDirtyDetector extends AbstractExceptionDetector { |
||||
|
||||
public FineDbDirtyDetector() { |
||||
this(ThrowableStore.getInstance()); |
||||
|
||||
super(DetectorType.FINE_DB_DIRTY); |
||||
} |
||||
|
||||
public FineDbDirtyDetector(ThrowableStore throwableStore) { |
||||
@Override |
||||
public DetectorResult detect() { |
||||
|
||||
super(DetectorType.FINE_DB_DIRTY, throwableStore, new FineDbDirtyConverter()); |
||||
} |
||||
Iterator<String> tableNames = ConfigContext.getConfigNames(); |
||||
while (tableNames.hasNext()) { |
||||
String tableName = tableNames.next(); |
||||
Class<? extends Configuration> configClass = ConfigContext.getConfigClass(tableName); |
||||
Configuration configuration = ConfigContext.getConfigInstance(configClass); |
||||
try { |
||||
|
||||
// 尝试获取每一个值
|
||||
configuration.mirror(); |
||||
} catch (Throwable e) { |
||||
|
||||
Function<Throwable, Boolean> isDirtyExFunction = throwable -> { |
||||
while (throwable != null) { |
||||
if (throwable instanceof GenericJDBCException) { |
||||
return true; |
||||
} |
||||
throwable = throwable.getCause(); |
||||
} |
||||
return false; |
||||
}; |
||||
boolean isDirtyEx = isDirtyExFunction.apply(e); |
||||
|
||||
if (isDirtyEx) { |
||||
DetectorType detectorType = DetectorType.FINE_DB_DIRTY; |
||||
DetectorResult.DetectorResultBuilder builder = DetectorResult |
||||
.builder() |
||||
.withType(detectorType); |
||||
|
||||
String tipsLocale = Toolkit.i18nText(detectorType.getTipsLocale(), tableName); |
||||
|
||||
String solutionLocale = detectorType.getSolutionLocale(); |
||||
ExceptionSolution exceptionSolution = new ExceptionSolution(new Message.Link(Toolkit.i18nText(solutionLocale, DetectorConstants.FINE_DB_HELP_LINK), DetectorConstants.FINE_DB_HELP_LINK), new SolutionAction() { |
||||
@Override |
||||
public String name() { |
||||
return Toolkit.i18nText("Fine-Design_Basic_Reset_Immediately"); |
||||
} |
||||
|
||||
@Override |
||||
public void run() { |
||||
boolean success = false; |
||||
try { |
||||
ResourceIOUtils.copy(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME), |
||||
StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_BAK_NAME)); |
||||
success = ResourceIOUtils.delete(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME)); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
// todo 最好的逻辑是,这里应该和 UI 隔离开的
|
||||
if (!success) { |
||||
FineJOptionPane.showMessageDialog(null, |
||||
Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset_Result", |
||||
ResourceIOUtils.getRealPath(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME))), |
||||
Toolkit.i18nText("Fine-Design_Basic_Error"), |
||||
JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
}); |
||||
builder.withTips(tipsLocale) |
||||
.withSolution(exceptionSolution) |
||||
.withLog(Toolkit.i18nText(detectorType.getLogLocale(), tableName)); |
||||
|
||||
return builder.build(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
||||
return DetectorResult.normal(DetectorType.FINE_DB_DIRTY); |
||||
} |
||||
} |
||||
|
@ -1,110 +0,0 @@
|
||||
package com.fr.env.detect.impl.converter; |
||||
|
||||
import com.fr.config.ConfigContext; |
||||
import com.fr.config.Configuration; |
||||
import com.fr.design.dialog.FineJOptionPane; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import com.fr.env.detect.base.DetectorConstants; |
||||
import com.fr.env.detect.bean.DetectorResult; |
||||
import com.fr.env.detect.bean.DetectorType; |
||||
import com.fr.env.detect.bean.ExceptionSolution; |
||||
import com.fr.env.detect.bean.Message; |
||||
import com.fr.env.detect.bean.SolutionAction; |
||||
import com.fr.env.detect.thowable.ThrowableConverter; |
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.third.org.hibernate.exception.GenericJDBCException; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
import javax.swing.JOptionPane; |
||||
import java.util.Iterator; |
||||
|
||||
/** |
||||
* 脏数据检测 |
||||
* |
||||
* created by Harrison on 2022/05/25 |
||||
**/ |
||||
public class FineDbDirtyConverter implements ThrowableConverter { |
||||
|
||||
@Override |
||||
public boolean accept(Throwable throwable) { |
||||
|
||||
Throwable sign = throwable; |
||||
while (sign != null) { |
||||
if (sign.getClass() == GenericJDBCException.class) { |
||||
return true; |
||||
} |
||||
sign = sign.getCause(); |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 根据堆栈,确认是否是从配置中发出来的异常 |
||||
* 如果是,则找到对应的配置的表, |
||||
* 输出信息 |
||||
* |
||||
* @param throwable 异常 |
||||
* @return 检测结果 |
||||
*/ |
||||
@Override |
||||
public @Nullable DetectorResult convert(Throwable throwable) { |
||||
|
||||
Iterator<String> tableNames = ConfigContext.getConfigNames(); |
||||
while (tableNames.hasNext()) { |
||||
String tableName = tableNames.next(); |
||||
Class<? extends Configuration> configClass = ConfigContext.getConfigClass(tableName); |
||||
Configuration configuration = ConfigContext.getConfigInstance(configClass); |
||||
try { |
||||
|
||||
// 尝试获取每一个值
|
||||
configuration.mirror(); |
||||
} catch (Throwable e) { |
||||
|
||||
DetectorType detectorType = DetectorType.FINE_DB_DIRTY; |
||||
DetectorResult.DetectorResultBuilder builder = DetectorResult.builder() |
||||
.withType(detectorType); |
||||
|
||||
String tipsLocale = Toolkit.i18nText(detectorType.getTipsLocale(), tableName); |
||||
|
||||
String solutionLocale = detectorType.getSolutionLocale(); |
||||
ExceptionSolution exceptionSolution = new ExceptionSolution(new Message.Link(Toolkit.i18nText(solutionLocale, DetectorConstants.FINE_DB_HELP_LINK), DetectorConstants.FINE_DB_HELP_LINK), new SolutionAction() { |
||||
@Override |
||||
public String name() { |
||||
return Toolkit.i18nText("Fine-Design_Basic_Reset_Immediately"); |
||||
} |
||||
|
||||
@Override |
||||
public void run() { |
||||
boolean success = false; |
||||
try { |
||||
ResourceIOUtils.copy(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME), |
||||
StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_BAK_NAME)); |
||||
success = ResourceIOUtils.delete(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME)); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
// todo 最好的逻辑是,这里应该和 UI 隔离开的
|
||||
if (!success) { |
||||
FineJOptionPane.showMessageDialog(null, |
||||
Toolkit.i18nText("Fine-Design_Error_Finedb_Backup_Reset_Result", |
||||
ResourceIOUtils.getRealPath(StableUtils.pathJoin(ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.FINE_DB_NAME))), |
||||
Toolkit.i18nText("Fine-Design_Basic_Error"), |
||||
JOptionPane.ERROR_MESSAGE); |
||||
} |
||||
} |
||||
}); |
||||
builder.withTips(tipsLocale) |
||||
.withSolution(exceptionSolution) |
||||
.withLog(Toolkit.i18nText(detectorType.getLogLocale(), tableName)); |
||||
|
||||
return builder.build(); |
||||
} |
||||
} |
||||
|
||||
return DetectorResult.normal(DetectorType.FINE_DB_DIRTY); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue