Java Code Examples for org.pentaho.di.job.JobMeta#getDatabase()

The following examples show how to use org.pentaho.di.job.JobMeta#getDatabase() . 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: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void synchronizeConnections() throws Exception {
  final String databaseName = "SharedDB";
  DatabaseMeta sharedDB0 = createDatabaseMeta( databaseName, true );
  saveSharedObjects( SHARED_OBJECTS_FILE, sharedDB0 );


  JobMeta job1 = createJobMeta();

  spoonDelegates.jobs.addJob( job1 );
  JobMeta job2 = createJobMeta();
  spoonDelegates.jobs.addJob( job2 );

  DatabaseMeta sharedDB2 = job2.getDatabase( 0 );
  assertEquals( databaseName, sharedDB2.getName() );
  DatabaseMeta sharedDB1 = job1.getDatabase( 0 );
  assertEquals( databaseName, sharedDB1.getName() );
  assertTrue( sharedDB1 != sharedDB2 );

  assertThat( sharedDB1.getHostname(), equalTo( BEFORE_SYNC_VALUE ) );
  sharedDB2.setHostname( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeConnections( sharedDB2, sharedDB2.getName() );

  assertThat( sharedDB1.getHostname(), equalTo( AFTER_SYNC_VALUE ) );
}
 
Example 2
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void synchronizeConnectionsRename() throws Exception {
  final String databaseName = BEFORE_SYNC_VALUE;
  DatabaseMeta sharedDB0 = createDatabaseMeta( databaseName, true );
  saveSharedObjects( SHARED_OBJECTS_FILE, sharedDB0 );


  JobMeta job1 = createJobMeta();
  spoonDelegates.jobs.addJob( job1 );

  JobMeta job2 = createJobMeta();
  spoonDelegates.jobs.addJob( job2 );

  DatabaseMeta sharedDB2 = job2.getDatabase( 0 );
  assertEquals( databaseName, sharedDB2.getName() );
  DatabaseMeta sharedDB1 = job1.getDatabase( 0 );
  assertEquals( databaseName, sharedDB1.getName() );
  assertTrue( sharedDB1 != sharedDB2 );

  assertThat( sharedDB1.getName(), equalTo( BEFORE_SYNC_VALUE ) );
  sharedDB2.setName( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeConnections( sharedDB2, BEFORE_SYNC_VALUE );

  assertThat( sharedDB1.getName(), equalTo( AFTER_SYNC_VALUE ) );
}
 
Example 3
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void synchronizeConnections_sync_shared_only() throws Exception {
  final String databaseName = "DB";
  DatabaseMeta sharedDB0 = createDatabaseMeta( databaseName, true );

  saveSharedObjects( SHARED_OBJECTS_FILE, sharedDB0 );

  JobMeta job1 = createJobMeta();
  DatabaseMeta sharedDB1 = job1.getDatabase( 0 );

  spoonDelegates.jobs.addJob( job1 );

  DatabaseMeta unsharedDB2 = createDatabaseMeta( databaseName, false );
  JobMeta job2 = createJobMeta();
  spoonDelegates.jobs.addJob( job2 );
  job2.removeDatabase( 0 );
  job2.addDatabase( unsharedDB2 );

  JobMeta job3 = createJobMeta();
  DatabaseMeta sharedDB3 = job3.getDatabase( 0 );
  spoonDelegates.jobs.addJob( job3 );
  job3.addDatabase( sharedDB3 );

  sharedDB3.setHostname( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeConnections( sharedDB3, sharedDB3.getName() );
  assertThat( sharedDB1.getHostname(), equalTo( AFTER_SYNC_VALUE ) );
  assertThat( unsharedDB2.getHostname(), equalTo( BEFORE_SYNC_VALUE ) );
}
 
Example 4
Source File: SharedObjectSyncUtilTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void synchronizeConnectionsOpenNew() throws Exception {
  final String databaseName = "SharedDB";
  DatabaseMeta sharedDB0 = createDatabaseMeta( databaseName, true );
  saveSharedObjects( SHARED_OBJECTS_FILE, sharedDB0 );


  JobMeta job1 = createJobMeta();
  spoonDelegates.jobs.addJob( job1 );
  DatabaseMeta sharedDB1 = job1.getDatabase( 0 );

  JobMeta job2 = createJobMeta();
  spoonDelegates.jobs.addJob( job2 );
  DatabaseMeta sharedDB2 = job2.getDatabase( 0 );


  assertThat( sharedDB1.getHostname(), equalTo( BEFORE_SYNC_VALUE ) );
  sharedDB2.setHostname( AFTER_SYNC_VALUE );
  sharedUtil.synchronizeConnections( sharedDB2, sharedDB2.getName() );

  assertThat( sharedDB1.getHostname(), equalTo( AFTER_SYNC_VALUE ) );

  JobMeta job3 = createJobMeta();
  spoonDelegates.jobs.addJob( job3 );
  DatabaseMeta sharedDB3 = job3.getDatabase( 0 );
  assertThat( sharedDB3.getHostname(), equalTo( AFTER_SYNC_VALUE ) );
}
 
Example 5
Source File: StreamToJobNodeConverter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void saveSharedObjects( final Repository repo, final RepositoryElementInterface element )
  throws KettleException {
  JobMeta jobMeta = (JobMeta) element;
  // First store the databases and other depending objects in the transformation.
  List<String> databaseNames = Arrays.asList( repo.getDatabaseNames( true ) );

  int dbIndex = 0;
  int indexToReplace = 0;
  boolean updateMeta = Boolean.FALSE;

  for ( DatabaseMeta databaseMeta : jobMeta.getDatabases() ) {
    if ( !databaseNames.contains( databaseMeta.getName() ) ) {
      if ( databaseMeta.getObjectId() == null || !StringUtils.isEmpty( databaseMeta.getHostname() ) ) {
        repo.save( databaseMeta, null, null );
      }
    } else if ( databaseMeta.getObjectId() == null ) {
      indexToReplace = dbIndex;
      updateMeta = Boolean.TRUE;
    }

    dbIndex++;
  }

  // if db already exists in repo, get that object id and put it
  // in the transMeta db collection
  if ( updateMeta ) {
    DatabaseMeta dbMetaToReplace = jobMeta.getDatabase( indexToReplace );
    dbMetaToReplace.setObjectId( repo.getDatabaseID( dbMetaToReplace.getName() ) );
    jobMeta.removeDatabase( indexToReplace );
    jobMeta.addDatabase( dbMetaToReplace );
  }
  // Store the slave servers...
  //
  for ( SlaveServer slaveServer : jobMeta.getSlaveServers() ) {
    if ( slaveServer.getObjectId() == null ) {
      repo.save( slaveServer, null, null );
    }
  }

}