Search in sources :

Example 71 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException 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)

Example 72 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithMaxAllowedPacketException.

/**
 * PDI-5153
 * Test that in case of MaxAllowedPacketException exception there will be no stack trace in log (MariaDB)
 */
@Test
public void testExceptionStrategyWithMaxAllowedPacketException() {
    DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
    DatabaseInterface databaseInterface = new MariaDBDatabaseMeta();
    MaxAllowedPacketException e = new MaxAllowedPacketException();
    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) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) MaxAllowedPacketException(org.mariadb.jdbc.internal.stream.MaxAllowedPacketException) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) MariaDBDatabaseMeta(org.pentaho.di.core.database.MariaDBDatabaseMeta) Test(org.junit.Test)

Example 73 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class DatabaseTest method testCheckTableExistsByDbMetaThrowsKettleDatabaseException_WhenUnableToGetTableNames.

@Test
public void testCheckTableExistsByDbMetaThrowsKettleDatabaseException_WhenUnableToGetTableNames() {
    KettleDatabaseException kettleDatabaseException = new KettleDatabaseException("Unable to get table-names from the database meta-data.", SQL_EXCEPTION);
    try {
        when(rs.next()).thenReturn(true, false);
        when(dbMetaDataMock.getTables(any(), anyString(), anyString(), aryEq(TABLE_TYPES_TO_GET))).thenThrow(SQL_EXCEPTION);
        Database db = new Database(log, dbMetaMock);
        db.setConnection(mockConnection(dbMetaDataMock));
        db.checkTableExistsByDbMeta(SCHEMA_TO_CHECK, EXISTING_TABLE_NAME);
        fail("There should be thrown KettleDatabaseException but was not.");
    } catch (KettleDatabaseException e) {
        assertTrue(e instanceof KettleDatabaseException);
        assertEquals(kettleDatabaseException.getLocalizedMessage(), e.getLocalizedMessage());
    } catch (Exception ex) {
        fail("There should be thrown KettleDatabaseException but was :" + ex.getMessage());
    }
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) NamingException(javax.naming.NamingException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleDatabaseBatchException(org.pentaho.di.core.exception.KettleDatabaseBatchException) Test(org.junit.Test)

Example 74 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class DatabaseTest method testCheckTableExistsByDbMetaThrowsKettleDatabaseException.

@Test
public void testCheckTableExistsByDbMetaThrowsKettleDatabaseException() {
    KettleDatabaseException kettleDatabaseException = new KettleDatabaseException("Unable to check if table [" + EXISTING_TABLE_NAME + "] exists on connection [" + TEST_NAME_OF_DB_CONNECTION + "].", SQL_EXCEPTION);
    try {
        when(dbMetaMock.getName()).thenReturn(TEST_NAME_OF_DB_CONNECTION);
        when(rs.next()).thenReturn(true, false);
        when(rs.getString("TABLE_NAME")).thenThrow(SQL_EXCEPTION);
        when(dbMetaDataMock.getTables(any(), anyString(), anyString(), aryEq(TABLE_TYPES_TO_GET))).thenReturn(rs);
        Database db = new Database(log, dbMetaMock);
        db.setConnection(mockConnection(dbMetaDataMock));
        db.checkTableExistsByDbMeta(SCHEMA_TO_CHECK, EXISTING_TABLE_NAME);
        fail("There should be thrown KettleDatabaseException but was not.");
    } catch (KettleDatabaseException e) {
        assertTrue(e instanceof KettleDatabaseException);
        assertEquals(kettleDatabaseException.getLocalizedMessage(), e.getLocalizedMessage());
    } catch (Exception ex) {
        fail("There should be thrown KettleDatabaseException but was :" + ex.getMessage());
    }
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) NamingException(javax.naming.NamingException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleDatabaseBatchException(org.pentaho.di.core.exception.KettleDatabaseBatchException) Test(org.junit.Test)

Example 75 with KettleDatabaseException

use of org.pentaho.di.core.exception.KettleDatabaseException in project pentaho-kettle by pentaho.

the class JobEntryXMLWellFormed method saveRep.

public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_job) throws KettleException {
    try {
        rep.saveJobEntryAttribute(id_job, getObjectId(), "arg_from_previous", arg_from_previous);
        rep.saveJobEntryAttribute(id_job, getObjectId(), "include_subfolders", include_subfolders);
        rep.saveJobEntryAttribute(id_job, getObjectId(), "nr_errors_less_than", nr_errors_less_than);
        rep.saveJobEntryAttribute(id_job, getObjectId(), "success_condition", success_condition);
        rep.saveJobEntryAttribute(id_job, getObjectId(), "resultfilenames", resultfilenames);
        // save the arguments...
        if (source_filefolder != null) {
            for (int i = 0; i < source_filefolder.length; i++) {
                rep.saveJobEntryAttribute(id_job, getObjectId(), i, "source_filefolder", source_filefolder[i]);
                rep.saveJobEntryAttribute(id_job, getObjectId(), i, "wildcard", wildcard[i]);
            }
        }
    } catch (KettleDatabaseException dbe) {
        throw new KettleException(BaseMessages.getString(PKG, "JobXMLWellFormed.Error.Exception.UnableSaveRep") + id_job, dbe);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Aggregations

KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)279 KettleException (org.pentaho.di.core.exception.KettleException)176 SQLException (java.sql.SQLException)69 Database (org.pentaho.di.core.database.Database)46 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)41 KettleValueException (org.pentaho.di.core.exception.KettleValueException)39 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)37 KettleDatabaseBatchException (org.pentaho.di.core.exception.KettleDatabaseBatchException)33 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)31 BatchUpdateException (java.sql.BatchUpdateException)27 ResultSet (java.sql.ResultSet)27 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)26 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)25 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)24 RowMeta (org.pentaho.di.core.row.RowMeta)22 FileObject (org.apache.commons.vfs2.FileObject)18 LongObjectId (org.pentaho.di.repository.LongObjectId)17 Savepoint (java.sql.Savepoint)16 ArrayList (java.util.ArrayList)16 Test (org.junit.Test)14