Search in sources :

Example 1 with MysqlDataTruncation

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);
}
Also used : GenericSignatureFormatError(java.lang.reflect.GenericSignatureFormatError) MysqlDataTruncation(com.mysql.jdbc.MysqlDataTruncation) SQLException(java.sql.SQLException) SQLException(java.sql.SQLException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 2 with MysqlDataTruncation

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);
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) MysqlDataTruncation(com.mysql.jdbc.MysqlDataTruncation) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Test(org.junit.Test)

Aggregations

MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)2 GenericSignatureFormatError (java.lang.reflect.GenericSignatureFormatError)1 SQLException (java.sql.SQLException)1 Test (org.junit.Test)1 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)1 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1