Java Code Examples for org.pentaho.di.core.database.Database#truncateTable()

The following examples show how to use org.pentaho.di.core.database.Database#truncateTable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobEntryTruncateTables.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private boolean truncateTables( String tablename, String schemaname, Database db ) {
  boolean retval = false;
  try {
    // check if table exists!
    if ( db.checkTableExists( schemaname, tablename ) ) {
      if ( !Utils.isEmpty( schemaname ) ) {
        db.truncateTable( schemaname, tablename );
      } else {
        db.truncateTable( tablename );
      }

      if ( log.isDetailed() ) {
        logDetailed( BaseMessages.getString( PKG, "JobEntryTruncateTables.Log.TableTruncated", tablename ) );
      }

      retval = true;
    } else {
      logError( BaseMessages.getString( PKG, "JobEntryTruncateTables.Error.CanNotFindTable", tablename ) );
    }
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "JobEntryTruncateTables.Error.CanNotTruncateTables", tablename, e
      .toString() ) );
  }
  return retval;
}
 
Example 2
Source File: TeraFast.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Execute fastload.
 *
 * @throws KettleException
 *           ...
 */
public void execute() throws KettleException {
  if ( this.meta.getTruncateTable().getValue() ) {
    Database db = new Database( this, this.meta.getDbMeta() );
    db.connect();
    db.truncateTable( this.meta.getTargetTable().getValue() );
    db.commit();
    db.disconnect();
  }
  startFastLoad();

  if ( this.meta.getUseControlFile().getValue() ) {
    this.invokeLoadingControlFile();
  } else {
    this.invokeLoadingCommand();
  }
}
 
Example 3
Source File: DataSetDatabaseGroup.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
public static final void writeDataSetData( LoggingObjectInterface loggingObject, DataSetGroup dataSetGroup, String tableName,
                                           RowMetaInterface rowMeta, List<Object[]> rows ) throws KettleException {

  Database database = new Database( loggingObject, dataSetGroup.getDatabaseMeta() );
  try {
    database.connect();

    String schemaTable = dataSetGroup.getDatabaseMeta().getQuotedSchemaTableCombination( dataSetGroup.getSchemaName(), tableName );

    String sql;
    if ( database.checkTableExists( schemaTable ) ) {
      // Clean out old junk, allow for rollback
      //
      database.truncateTable( schemaTable );
      sql = database.getAlterTableStatement( schemaTable, rowMeta, null, false, null, true );
    } else {
      sql = database.getCreateTableStatement( schemaTable, rowMeta, null, false, null, true );
    }
    if ( !StringUtil.isEmpty( sql ) ) {
      database.execStatements( sql );
    }
    database.prepareInsert( rowMeta, schemaTable );
    for ( Object[] row : rows ) {
      database.setValuesInsert( new RowMetaAndData( rowMeta, row ) );
      database.insertRow();
    }

    database.commit();
  } finally {
    database.disconnect();
  }

}
 
Example 4
Source File: JobHistoryDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * User requested to clear the log table.<br>
 * Better ask confirmation
 */
private void clearLogTable( int index ) {
  JobHistoryLogTab model = models[index];
  LogTableInterface logTable = model.logTable;

  if ( logTable.isDefined() ) {
    DatabaseMeta databaseMeta = logTable.getDatabaseMeta();

    MessageBox mb = new MessageBox( jobGraph.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION );
    mb.setMessage( BaseMessages.getString( PKG, "JobGraph.Dialog.AreYouSureYouWantToRemoveAllLogEntries.Message",
      logTable.getQuotedSchemaTableCombination() ) );
    mb.setText( BaseMessages.getString( PKG, "JobGraph.Dialog.AreYouSureYouWantToRemoveAllLogEntries.Title" ) );
    if ( mb.open() == SWT.YES ) {
      Database database = new Database( loggingObject, databaseMeta );
      try {
        database.connect();
        database.truncateTable( logTable.getSchemaName(), logTable.getTableName() );
      } catch ( Exception e ) {
        new ErrorDialog( jobGraph.getShell(),
          BaseMessages.getString( PKG, "JobGraph.Dialog.ErrorClearningLoggingTable.Title" ),
          BaseMessages.getString( PKG, "JobGraph.Dialog.AreYouSureYouWantToRemoveAllLogEntries.Message" ), e );
      } finally {
        database.disconnect();

        refreshHistory();
        if ( model.logDisplayText != null ) {
          model.logDisplayText.setText( "" );
        }
      }
    }
  }
}
 
Example 5
Source File: TransHistoryDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * User requested to clear the log table.<br>
 * Better ask confirmation
 */
private void clearLogTable( int index ) {
  TransHistoryLogTab model = models[index];
  LogTableInterface logTable = model.logTable;

  if ( logTable.isDefined() ) {
    DatabaseMeta databaseMeta = logTable.getDatabaseMeta();

    MessageBox mb = new MessageBox( transGraph.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION );
    mb.setMessage( BaseMessages.getString( PKG, "TransGraph.Dialog.AreYouSureYouWantToRemoveAllLogEntries.Message",
      logTable.getQuotedSchemaTableCombination() ) );
    mb.setText( BaseMessages.getString( PKG, "TransGraph.Dialog.AreYouSureYouWantToRemoveAllLogEntries.Title" ) );
    if ( mb.open() == SWT.YES ) {
      Database database = new Database( loggingObject, databaseMeta );
      try {
        database.connect();
        database.truncateTable( logTable.getSchemaName(), logTable.getTableName() );
      } catch ( Exception e ) {
        new ErrorDialog( transGraph.getShell(),
          BaseMessages.getString( PKG, "TransGraph.Dialog.ErrorClearningLoggingTable.Title" ),
          BaseMessages.getString( PKG, "TransGraph.Dialog.ErrorClearningLoggingTable.Message" ), e );
      } finally {
        database.disconnect();

        refreshHistory();
        if ( model.logDisplayText != null ) {
          model.logDisplayText.setText( "" );
        }
      }
    }
  }
}