use of com.mysql.jdbc.MysqlDataTruncation in project leopard by tanhaichao.
the class ErrorUtil method parseMessage.
/**
* 获取异常信息.
*
* @param e
* @return
*/
public static String parseMessage(Throwable e) {
if (e == null) {
throw new IllegalArgumentException("exception不能为空?");
}
String className = e.getClass().getName();
String message = MESSAGE_MAP.get(className);
if (message != null) {
return message;
}
if (e instanceof GenericSignatureFormatError) {
printStartupTime();
return "更新程序后,还没有重启服务.";
}
if (e instanceof NoSuchMethodError) {
printStartupTime();
return "NoSuchMethodError:方法找不到.";
}
if (e instanceof SQLException) {
return "操作数据库出错,请稍后重试.";
}
if (e instanceof DataIntegrityViolationException) {
Exception exception = (Exception) e.getCause();
if (exception instanceof MysqlDataTruncation) {
return MessageParserImpl.parse((MysqlDataTruncation) exception);
} else {
return "操作数据库出错,请稍后重试.";
}
// try {
// return parseDataIntegrityViolationException((DataIntegrityViolationException) e);
// }
// catch (Exception e1) {
// e1.printStackTrace();
// return "字段太长,请稍后重试.";
// }
}
message = e.getMessage();
if (message == null) {
return null;
}
return fillterDebugInfo(message);
}
use of com.mysql.jdbc.MysqlDataTruncation in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMysqlDataTruncationException.
/**
* PDI-5153
* Test that in case of MysqlDataTruncation exception there will be no stack trace in log
*/
@Test
public void testExceptionStrategyWithMysqlDataTruncationException() {
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
MysqlDataTruncation e = new MysqlDataTruncation();
when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
String strategyName = exceptionStrategy.getClass().getName();
assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
Aggregations