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

The following examples show how to use org.pentaho.di.core.database.Database#commit() . 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: JobTrackerExecution.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Before
public void setUpBeforeClass() throws Exception {
  KettleEnvironment.init();
  LoggingObjectInterface log = new SimpleLoggingObject( "junit", LoggingObjectType.GENERAL, null );

  File file = File.createTempFile( JobTrackerExecution.class.getSimpleName(), "" );
  file.deleteOnExit();
  DatabaseMeta databaseMeta =
      new DatabaseMeta( NAME, "Hypersonic", "JDBC", null, "mem:HSQLDB-JUNIT-LOGJOB", null, null, null );
  Database logDataBase = new Database( log, databaseMeta );
  logDataBase.connect();

  // run sql create for database
  InputStream input = JobTrackerExecution.class.getClassLoader().getResourceAsStream( PKG + CREATE );
  String sql = getStringFromInput( input );
  logDataBase.execStatements( sql );
  logDataBase.commit( true );

  logDataBase.disconnect();
}
 
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: JobTrackerExecution.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@After
public void after() throws KettleDatabaseException {
  // DatabaseMeta databaseMeta = new DatabaseMeta( NAME, "H2", "JDBC", null, TMP, null, USER, USER );
  DatabaseMeta databaseMeta =
      new DatabaseMeta( NAME, "Hypersonic", "JDBC", null, "mem:HSQLDB-JUNIT-LOGJOB", null, null, null );
  LoggingObjectInterface log = new SimpleLoggingObject( "junit", LoggingObjectType.GENERAL, null );
  Database db = new Database( log, databaseMeta );
  db.connect();

  db.execStatements( "DROP SCHEMA PUBLIC CASCADE" );
  db.commit( true );
  db.disconnect();
}
 
Example 5
Source File: TableCompareIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  InputStream input = TableCompareIT.class.getClassLoader().getResourceAsStream( PKG + "PDI-7255.sql" );
  String sql = TestUtilities.getStringFromInput( input );
  Database db = new Database( log, databaseMeta );
  db.connect();
  db.execStatements( sql );
  db.commit( true );
  db.disconnect();
}
 
Example 6
Source File: TableCompareIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void executeSqlPrecondition( String sqlFile ) throws IOException, KettleDatabaseException {
  String path = PKG + sqlFile;
  InputStream input = TableCompareIT.class.getClassLoader().getResourceAsStream( PKG + sqlFile );
  if ( input == null ) {
    throw new IOException( "Resource not found in classpath: " + path );
  }
  String sql = TestUtilities.getStringFromInput( input );
  Database db = new Database( log, databaseMeta );
  db.connect();
  db.execStatements( sql );
  db.commit( true );
  db.disconnect();
}
 
Example 7
Source File: Trans.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void disconnectDb( Database db ) throws KettleDatabaseException {
  if ( db == null ) {
    return;
  }
  if ( !db.isAutoCommit() ) {
    db.commit( true );
  }
  db.disconnect();
}